chainer.LinkHook¶
-
class
chainer.LinkHook[source]¶ Base class of hooks for links.
LinkHookis a callback object that is registered to aLink. Registered link hooks are invoked before and after callingLink.forward()method of each link.Link hooks that derive from
LinkHookmay override the following method:By default, these methods do nothing.
Specifically, when the
__call__()method of some link is invoked,forward_preprocess()(resp.forward_postprocess()) of all link hooks registered to this link are called before (resp. after)Link.forward()method of the link.There are two ways to register
LinkHookobjects toLinkobjects.The first one is to use
withstatement. Link hooks hooked in this way are registered to all links withinwithstatement and are unregistered at the end ofwithstatement.Note
Chainer stores the dictionary of registered link hooks as a thread local object. So, link hooks registered are different depending on threads.
The other one is to register directly to a
Linkobject by calling itsadd_hook()method. Link hooks registered in this way can be removed bydelete_hook()method. Contrary to former registration method, link hooks are registered only to the link whichadd_hook()is called.Parameters: name (str) – Name of this link hook. Methods
-
added(link)[source]¶ Callback function invoked when the link hook is registered
Parameters: link (Link) – Link object to which the link hook is registered. Noneif the link hook is registered globally.
-
deleted(link)[source]¶ Callback function invoked when the link hook is unregistered
Parameters: link (Link) – Link object to which the link hook is unregistered. Noneif the link hook had been registered globally.
-
forward_postprocess(args)[source]¶ Callback function invoked after a forward call of a link.
Parameters: args – Callback data. It has the following attributes:
-
forward_preprocess(args)[source]¶ Callback function invoked before a forward call of a link.
Parameters: args – Callback data. It has the following attributes:
Attributes
-
name= 'LinkHook'¶
-