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.
__call__() 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
Delete all layers that are not needed for the forward pass.