MCPcopy Index your code
hub / github.com/tensorpack/tensorpack / TrainTowerContext

Class TrainTowerContext

tensorpack/tfutils/tower.py:163–199  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

161
162
163class TrainTowerContext(BaseTowerContext):
164
165 def __init__(self, ns_name, vs_name='', index=0, total=1):
166 """
167 Args:
168 index (int): index of this tower, only used in training.
169 total (int): total number of towers to be built.
170 """
171 super(TrainTowerContext, self).__init__(ns_name, vs_name)
172 self._is_training = True
173
174 self.index = int(index)
175 self.total = int(total)
176 if self.index > 0:
177 assert self.total > self.index, "(index, total) = ({}, {})".format(self.index, self.total)
178
179 vs = tf.get_variable_scope()
180 assert vs.name == '', "Cannot nest TrainTowerContext with an existing variable scope!"
181 if vs_name:
182 assert not vs.reuse, \
183 "Cannot create tower {} with vs_name={} under reuse=True!".format(ns_name, vs_name)
184 self._original_vs_reuse = vs.reuse
185
186 @property
187 def is_main_training_tower(self):
188 return self.index == 0
189
190 @property
191 def has_own_variables(self):
192 if self._original_vs_reuse:
193 return False
194 return self.index == 0 or len(self._vs_name) > 0
195
196 def _keys_to_freeze(self):
197 if self.index == 0:
198 return []
199 return [tf.GraphKeys.SUMMARIES, MOVING_SUMMARY_OPS_KEY]
200
201
202class PredictTowerContext(BaseTowerContext):

Callers 4

call_for_each_towerMethod · 0.85
TowerContextFunction · 0.85
_setup_graphMethod · 0.85
_setup_graphMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected