Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
Allow the python layer have attribute "phase" #3995
Conversation
shelhamer
added the
Python
label
Apr 15, 2016
|
Looks fine to me. Would you be able to add a test that demonstrates reading out the phase with TRAIN/TEST values as well? |
shaibagon
referenced
this pull request
Apr 17, 2016
Closed
Extend pycaffe to expose LayerParameters in Python layer #3506
|
related to issue #3506 -- thanks for implementing this PR! |
|
Looks great to me. Can you squash the commits? @longjon , @shelhamer does this look good to you? |
longjon
commented on an outdated diff
May 4, 2016
| @@ -44,6 +44,23 @@ def forward(self, bottom, top): | ||
| def backward(self, top, propagate_down, bottom): | ||
| self.blobs[0].diff[0] = 1 | ||
| +class PhaseLayer(caffe.Layer): | ||
| + """A layer for checking attribute `phase`""" | ||
| + | ||
| + def setup(self, bottom, top): | ||
| + pass | ||
| + | ||
| + def reshape(self, bootom, top): | ||
| + top[0].reshape(1) |
|
|
longjon
commented on an outdated diff
May 4, 2016
| @@ -44,6 +44,23 @@ def forward(self, bottom, top): | ||
| def backward(self, top, propagate_down, bottom): | ||
| self.blobs[0].diff[0] = 1 | ||
| +class PhaseLayer(caffe.Layer): | ||
| + """A layer for checking attribute `phase`""" | ||
| + | ||
| + def setup(self, bottom, top): | ||
| + pass | ||
| + | ||
| + def reshape(self, bootom, top): | ||
| + top[0].reshape(1) | ||
| + | ||
| + def forward(self, bottom, top): | ||
| + if (self.phase == caffe.TRAIN): | ||
| + top[0].data[...] = 0 # caffe.TRAIN |
longjon
Contributor
|
longjon
commented on an outdated diff
May 4, 2016
| @@ -140,3 +165,14 @@ def test_parameter(self): | ||
| self.assertEqual(layer.blobs[0].data[0], 1) | ||
| os.remove(net_file) | ||
| + | ||
| + def test_phase(self): | ||
| + net_file = phase_net_file() | ||
| + # Test on phase TRAIN |
longjon
Contributor
|
|
I never really got much into phase myself, but this is a clear improvement for the completeness of Python layers, so it seems worthwhile. However, there are a few style issues, as noted. I'd be happy to merge once these are fixed (and squashed into the existing two commits). |
|
@longjon Thanks for review and I've fixed it. I'm glad this pr is helpful. |
|
Looks very clean now, thanks! |
longjon
merged commit de8ac32
into
BVLC:master
May 4, 2016
1 check passed
fxbit
added a commit
to Yodigram/caffe
that referenced
this pull request
Sep 1, 2016
|
|
longjon + fxbit |
a16a05c
|
ZhouYzzz commentedApr 15, 2016
I noticed that the python layer cannot tell whether the phase is TRAIN or TEST. This change may bring convenience in some cases. e.g. to me.