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

Class CallbackFactory

tensorpack/callbacks/base.py:298–339  ·  view source on GitHub ↗

Create a callback with some lambdas.

Source from the content-addressed store, hash-verified

296
297
298class CallbackFactory(Callback):
299 """
300 Create a callback with some lambdas.
301 """
302 def __init__(self, setup_graph=None, before_train=None, trigger=None,
303 after_train=None):
304 """
305 Each lambda takes ``self`` as the only argument.
306 """
307
308 self._cb_setup_graph = setup_graph
309 self._cb_before_train = before_train
310 self._cb_trigger = trigger
311 self._cb_after_train = after_train
312
313 def _setup_graph(self):
314 if self._cb_setup_graph:
315 self._cb_setup_graph(self)
316
317 def _before_train(self):
318 if self._cb_before_train:
319 self._cb_before_train(self)
320
321 def _trigger(self):
322 if self._cb_trigger:
323 self._cb_trigger(self)
324
325 def _after_train(self):
326 if self._cb_after_train:
327 self._cb_after_train(self)
328
329 def __str__(self):
330 strs = []
331 if self._cb_setup_graph is not None:
332 strs.append("setup_graph=" + str(self._cb_setup_graph))
333 if self._cb_before_train is not None:
334 strs.append("before_train=" + str(self._cb_before_train))
335 if self._cb_trigger is not None:
336 strs.append("trigger=" + str(self._cb_trigger))
337 if self._cb_after_train is not None:
338 strs.append("after_train=" + str(self._cb_after_train))
339 return "CallbackFactory({})".format(', '.join(strs))

Callers 4

_get_reset_callbackFunction · 0.85
get_callbacksMethod · 0.85
_setup_graphMethod · 0.85
get_configFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…