A sequential chain that can pick intermediate layers.
Callable objects, such as
chainer.Function, can be registered to this chain with
This chain keeps the order of registrations and
executes callables in that order.
chainer.Link object in the sequence will be added as
a child link of this link.
forward() returns single or multiple layers that are picked up
through a stream of computation.
These layers can be specified by
pick, which contains
the names of the layers that are collected.
pick is a string, single layer is returned.
pick is an iterable of strings, a tuple of layers
is returned. The order of the layers is the same as the order of
the strings in
None, the last layer is returned.
>>> import chainer.functions as F
>>> import chainer.links as L
>>> model = PickableSequentialChain()
>>> with model.init_scope():
>>> model.l1 = L.Linear(None, 1000)
>>> model.l1_relu = F.relu
>>> model.l2 = L.Linear(None, 1000)
>>> model.l2_relu = F.relu
>>> model.l3 = L.Linear(None, 10)
>>> # This is layer l3
>>> layer3 = model(x)
>>> # The layers to be collected can be changed.
>>> model.pick = ('l2_relu', 'l1_relu')
>>> # These are layers l2_relu and l1_relu.
>>> layer2, layer1 = model(x)
pick (string or iterable of strings) – Names of layers that are collected during
the forward pass.
layer_names (iterable of strings) – Names of layers that can be collected from
this chain. The names are ordered in the order
Copies the link hierarchy to new one.
The whole hierarchy rooted by this link is copied. There are three
modes to perform copy. Please see the documentation for the argument
The name of the link is reset on the copy, since the copied instance
does not belong to the original parent chain (even if exists).
mode (str) – It should be either
init means parameter variables under the returned link
object is re-initialized by calling their
initialize() method, so that all the
parameters may have different initial values from the original
copy means that the link object is deeply copied, so that
its parameters are not re-initialized but are also deeply
copied. Thus, all parameters have same initial values but can
be changed independently.
share means that the link is shallowly copied, so that its
parameters’ arrays are shared with the original one. Thus,
their values are changed synchronously. The default
Copied link object.
- Return type
Forward this model.
x (chainer.Variable or array) – Input to the model.
The returned layers are determined by
- Return type
chainer.Variable or tuple of chainer.Variable
Delete all layers that are not needed for the forward pass.