| 161 | |
| 162 | |
| 163 | class 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 | |
| 202 | class PredictTowerContext(BaseTowerContext): |
no outgoing calls
no test coverage detected