Responsible for building the main training graph for single-cost training. Args: input_signature ([TensorSpec]): list of TensorSpec that describe the inputs input (InputSource): an InputSource which has to match the input signature get_cost_fn ([
(self, input_signature, input, get_cost_fn, get_opt_fn)
| 195 | |
| 196 | @call_only_once |
| 197 | def setup_graph(self, input_signature, input, get_cost_fn, get_opt_fn): |
| 198 | """ |
| 199 | Responsible for building the main training graph for single-cost training. |
| 200 | |
| 201 | Args: |
| 202 | input_signature ([TensorSpec]): list of TensorSpec that describe the inputs |
| 203 | input (InputSource): an InputSource which has to match the input signature |
| 204 | get_cost_fn ([tf.Tensor] -> tf.Tensor): callable, takes some input tensors and return a cost tensor. |
| 205 | get_opt_fn (-> tf.train.Optimizer): callable which returns an |
| 206 | optimizer. Will only be called once. |
| 207 | |
| 208 | Note: |
| 209 | `get_cost_fn` will be part of the tower function. |
| 210 | It must follows the `rules of tower function. |
| 211 | <http://tensorpack.readthedocs.io/tutorial/trainer.html#tower-trainer>`_. |
| 212 | """ |
| 213 | get_cost_fn = TowerFunc(get_cost_fn, input_signature) |
| 214 | get_opt_fn = memoized(get_opt_fn) |
| 215 | self.tower_func = get_cost_fn |
| 216 | |
| 217 | # TODO setup may want to register monitor as well?? |
| 218 | input_callbacks = self._setup_input(input_signature, input) |
| 219 | train_callbacks = self._setup_graph(input, get_cost_fn, get_opt_fn) |
| 220 | self.register_callback(input_callbacks + train_callbacks) |
| 221 | |
| 222 | @abstractmethod |
| 223 | def _setup_graph(self, input, get_cost_fn, get_opt_fn): |
no test coverage detected