MCPcopy
hub / github.com/pytorch/vision / train

Method train

torchvision/models/feature_extraction.py:320–332  ·  view source on GitHub ↗

Swap out the graph depending on the selected training mode. NOTE this should be safe when calling model.eval() because that just calls this with mode == False.

(self, mode=True)

Source from the content-addressed store, hash-verified

318 self._tracer_cls = self.graph._tracer_cls
319
320 def train(self, mode=True):
321 """
322 Swap out the graph depending on the selected training mode.
323 NOTE this should be safe when calling model.eval() because that just
324 calls this with mode == False.
325 """
326 # NOTE: Only set self.graph if the current graph is not the desired
327 # one. This saves us from recompiling the graph where not necessary.
328 if mode and not self.training:
329 self.graph = self.train_graph
330 elif not mode and self.training:
331 self.graph = self.eval_graph
332 return super().train(mode=mode)
333
334 def _deepcopy_init(self):
335 # See __deepcopy__ below

Callers 15

__init__Method · 0.95
create_feature_extractorFunction · 0.95
test_forward_backwardMethod · 0.80
test_train_evalMethod · 0.80
test_deepcopyMethod · 0.80
get_graph_node_namesFunction · 0.80
retrieve_out_channelsFunction · 0.80
train_epochFunction · 0.80
train_one_epochFunction · 0.80

Calls

no outgoing calls

Tested by 6

test_forward_backwardMethod · 0.64
test_train_evalMethod · 0.64
test_deepcopyMethod · 0.64