Skip to content
This repository has been archived by the owner on Jul 2, 2021. It is now read-only.

Add sequential_feature_extractor #342

Merged
merged 37 commits into from
Jul 17, 2017
Merged
Changes from 1 commit
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
75ad8e7
add sequential_feature_extractor
yuyu2172 Jul 14, 2017
817d4e4
improve doc
yuyu2172 Jul 14, 2017
4601ed1
fix doc
yuyu2172 Jul 14, 2017
3c031d4
fix doc
yuyu2172 Jul 14, 2017
b6d618a
fix doc
yuyu2172 Jul 14, 2017
d1790a5
remove unnecessary []
yuyu2172 Jul 14, 2017
ec70c8f
drop support for list layers
yuyu2172 Jul 14, 2017
1cad17b
add to doc
yuyu2172 Jul 14, 2017
321ee42
use init_scope
Hakuyume Jul 15, 2017
644ce71
update test
Hakuyume Jul 15, 2017
958913e
update docs
Hakuyume Jul 15, 2017
4af9fc8
remove unused import
Hakuyume Jul 15, 2017
d02e8ce
support None
Hakuyume Jul 15, 2017
064c7bc
check if a layer is used in layer_names
Hakuyume Jul 15, 2017
08f1ba7
improve test
Hakuyume Jul 15, 2017
8e80d7b
use tuple
Hakuyume Jul 15, 2017
210f3d2
remove list
Hakuyume Jul 15, 2017
5e31464
add deletion test
Hakuyume Jul 15, 2017
a0f4fcf
force tuple
Hakuyume Jul 15, 2017
97778d1
fix test
Hakuyume Jul 15, 2017
6036240
fix docs
Hakuyume Jul 15, 2017
29faace
update docs
Hakuyume Jul 15, 2017
4870aaa
fix docs
Hakuyume Jul 15, 2017
49c490e
Merge pull request #2 from Hakuyume/use-init-scope-in-sequential-feat…
yuyu2172 Jul 15, 2017
73e7189
delete imoprt collections
yuyu2172 Jul 15, 2017
869dcaf
layer_names --> feature_names
yuyu2172 Jul 15, 2017
4168f06
fix doc
yuyu2172 Jul 16, 2017
faa7f22
flake8
yuyu2172 Jul 16, 2017
4fdc7d6
fix getter
Hakuyume Jul 16, 2017
9a3fdee
add test
Hakuyume Jul 16, 2017
aaf403c
add comment
Hakuyume Jul 16, 2017
cae3e59
member variable -> attribute
Hakuyume Jul 16, 2017
ffd8152
the
Hakuyume Jul 16, 2017
e9f5af2
move comment
Hakuyume Jul 16, 2017
c57dd3b
Merge pull request #3 from Hakuyume/fix-feature-names-getter-in-seque…
yuyu2172 Jul 16, 2017
b2e012d
add a test when there are two same keys in feature_names
yuyu2172 Jul 17, 2017
b053036
Merge branch 'sequential-feature-extractor' of https://github.com/yuy…
yuyu2172 Jul 17, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
update docs
  • Loading branch information
Hakuyume committed Jul 15, 2017
commit 958913e523744d2c57c97db0f5d24709341e686b
29 changes: 14 additions & 15 deletions chainercv/links/model/sequential_feature_extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ class SequentialFeatureExtractor(chainer.Chain):

This class is a base class that can be used for an implementation of
a feature extractor model.
The link takes an argument :obj:`layers` that specifies the computation
conducted in :meth:`__call__`.
:obj:`layers` is a :class:`collections.OrderedDict` of
callable objects called layers, which are going to be called sequentially
starting from the top to the bottom.
Callabel objects, such as :class:`chainer.Link` and
:class:`chainer.Function`, can be registered to this link with
:meth:`init_scope`.
This link keeps the order of registerations and conducts the computation
in the same order when :meth:`__call__` is called.
A :class:`chainer.Link` object in the sequence will be added as
a child link of this object.

Expand All @@ -33,23 +33,22 @@ class SequentialFeatureExtractor(chainer.Chain):
>>> import collections
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I forgot to remove this line. Could you remove this?

>>> import chainer.functions as F
>>> import chainer.links as L
>>> layers = collections.OrderedDict([
>>> ('l1', L.Linear(None, 1000)),
>>> ('l1_relu', F.relu),
>>> ('l2', L.Linear(None, 1000)),
>>> ('l2_relu', F.relu),
>>> ('l3', L.Linear(None, 10))])
>>> model = SequentialFeatureExtractor(layers, ['l2_relu', 'l1_relu'])
>>> model = SequentialFeatureExtractor()
>>> 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)
>>> model.layer_names = ['l2_relu', 'l1_relu']
>>> # These are outputs of layer l2_relu and l1_relu.
>>> feat1, feat2 = model(x)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

feat1, feat2 -> feat2, feat1? (feat1 sounds a feature from l1_relu)

>>> # The layer_names can be dynamically changed.
>>> model.layer_names = 'l3'
>>> # This is an output of layer l1.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

l1 -> l3

>>> feat3 = model(x)

Args:
layers (collections.OrderedDict of callables):
Callable objects called in the forward pass.
Params:
layer_names (string or iterable of strings):
Names of layers whose outputs will be collected in
the forward pass.
Expand Down