Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
Expose all netstate options (for all-in-one nets) #3863
Conversation
This was referenced Mar 21, 2016
|
While I agree that the new interface is more Pythonic, I personally think that the old interface can be maintained with a little bit of massaging. All that needs to be edited is the Modify the end of # Original Boost.Python Net.__init__ function
_Net_init_boost = Net.__init__
def _Net_init(self, *args, **kwargs):
""" Construct a caffe.Net """
# Transform the arguments to handle the legacy API
if len(args) == 2 and not kwargs:
# Handle case: Net(param_file, phase)
_Net_init_boost(self, args[0], weights_file=None, phase=args[1])
elif len(args) == 3 and not kwargs:
# Handle case: Net(param_file, weights_file, phase)
_Net_init_boost(self, args[0], weights_file=args[1], phase=args[2])
else:
# Handle new API:
# Net('net.prototxt', weights_file='weights.caffemodel', phase=caffe.TEST, level=1, stages=['deploy'])
_Net_init_boost(self, *args, **kwargs)
# Attach methods to Net.
Net.__init__ = _Net_init
...The above code makes One other note: It seems that if you wanted to use a kwarg for every argument, then in some place it's named |
ajtulloch
commented on the diff
Apr 17, 2016
| @@ -25,6 +25,7 @@ class Net { | ||
| public: | ||
| explicit Net(const NetParameter& param, const Net* root_net = NULL); | ||
| explicit Net(const string& param_file, Phase phase, | ||
| + const int level = 0, const vector<string>* stages = NULL, |
ajtulloch
Contributor
|
EDIT - Oh, I see what you were pointing out. I was being internally inconsistent with my own code. Whoops! |
@seanbell I think I've found a nice compromise between our solutions. I've left the old Now all of these constructors work as expected: ### Legacy style
net = caffe.Net('network.prototxt', caffe.TRAIN)
net = caffe.Net('network.prototxt', 'weights.caffemodel', caffe.TEST)
# pattern matches to Net(network_file, weights_file, phase)
# prints deprecation warning
### New style
net = caffe.Net('network.prototxt', phase=caffe.TRAIN)
net = caffe.Net('network.prototxt', weights_file='weights.caffemodel', phase=caffe.TEST)
net = caffe.Net('network.prototxt', phase=caffe.TEST, weights_file='weights.caffemodel')
net = caffe.Net('network.prototxt', caffe.TRAIN, 0)
# pattern matches to Net(network_file, phase, level)
net = caffe.Net('network.prototxt', caffe.TEST, 0, [], 'weights.caffemodel')Made changes and rebased to address merge conflict from https://github.com/BVLC/caffe/pull/3982. |
|
Is there anything in particular holding back this PR? Does the re-arranging of the Is my Python constructor compromise not satisfactory? |
shelhamer
added the
focus
label
Apr 26, 2016
|
|
LGTM. Cool stuff @lukeyeager! |
|
Will review after NIPS deadline 05/20. Thanks for this @lukeyeager and thanks for review @ajtulloch! |
lukeyeager
referenced
this pull request
May 19, 2016
Closed
Update summarize.py to select different netstate options #4174
shelhamer
commented on an outdated diff
May 25, 2016
| @@ -237,7 +260,12 @@ BOOST_PYTHON_MODULE(_caffe) { | ||
| bp::class_<Net<Dtype>, shared_ptr<Net<Dtype> >, boost::noncopyable >("Net", | ||
| bp::no_init) | ||
| - .def("__init__", bp::make_constructor(&Net_Init)) | ||
| + // Constructor | ||
| + .def("__init__", bp::make_constructor(&Net_Init, | ||
| + bp::default_call_policies(), (bp::arg("network_file"), "phase", | ||
| + bp::arg("level")=0, bp::arg("stages")=bp::object(), | ||
| + bp::arg("weights_file")=bp::object()))) | ||
| + // XXX Legacy constructor |
|
|
shelhamer
commented on an outdated diff
May 25, 2016
| @@ -237,7 +260,12 @@ BOOST_PYTHON_MODULE(_caffe) { | ||
| bp::class_<Net<Dtype>, shared_ptr<Net<Dtype> >, boost::noncopyable >("Net", | ||
| bp::no_init) | ||
| - .def("__init__", bp::make_constructor(&Net_Init)) | ||
| + // Constructor | ||
| + .def("__init__", bp::make_constructor(&Net_Init, | ||
| + bp::default_call_policies(), (bp::arg("network_file"), "phase", | ||
| + bp::arg("level")=0, bp::arg("stages")=bp::object(), | ||
| + bp::arg("weights_file")=bp::object()))) |
shelhamer
Owner
|
shelhamer
commented on the diff
May 25, 2016
| @@ -34,6 +34,13 @@ DEFINE_string(solver, "", | ||
| "The solver definition protocol buffer text file."); | ||
| DEFINE_string(model, "", | ||
| "The model definition protocol buffer text file."); | ||
| +DEFINE_string(phase, "", | ||
| + "Optional; network phase (TRAIN or TEST). Only used for 'time'."); | ||
| +DEFINE_int32(level, 0, |
shelhamer
Owner
|
shelhamer
commented on the diff
May 25, 2016
| os.remove(net_file) | ||
| os.remove(f.name) | ||
| for name in self.net.params: | ||
| for i in range(len(self.net.params[name])): | ||
| self.assertEqual(abs(self.net.params[name][i].data | ||
| - net2.params[name][i].data).sum(), 0) | ||
| + | ||
| +class TestLevels(unittest.TestCase): |
shelhamer
Owner
|
|
Re: |
|
Although I originally voted for net states and these varied ways of expressing them, I'm now of two minds. On one hand phase, level, and stage states make all-in-one definitions possible and potentially make variations easier to express, but on the other these are just more special cases in the definition of nets. That said, they do seem to address a need in practice and since they are in the library they should at least be properly exposed to its interfaces. Thoughts @jeffdonahue @longjon? While I now use and suggest net spec, net states have their purposes so thanks for extending them throughout the interfaces @lukeyeager. For merge:
Let me know if there are other concerns. |
|
I've addressed (1) and (2). (3) Gulp. Time to dive into gtest ... (4) Don't care |
|
Added a basic C++ test |
|
Ready for review. Do you want more extensive tests? Would you like me to switch the location of the |
|
@lukeyeager I'd rather switch the order of It would be best to have a C++ test that checks that the layers for do in fact exist, for instance by checking the layer name in the instantiated net (or differentiate the Thanks. |
|
At some point all of the root solver/root net code needs to be simplified, but it's here for now and not a problem to be solved by this PR |
None of those invocations need updating - they use a different constructor which expects a |
Done
Done |
|
https://github.com/BVLC/caffe/pull/3863#issuecomment-223065222 Right, sorry about that. With https://github.com/BVLC/caffe/pull/3863#issuecomment-223070737 this looks good to me. @longjon will double-check for merge. |
lukeyeager
added some commits
Jun 1, 2016
|
Rebased after conflict from #4227 |
shelhamer
added ready for review and removed ES JD JL
labels
Jun 9, 2016
This was referenced Jun 27, 2016
|
Merging after offline discussion. Thanks @lukeyeager! p.s. @jeffdonahue noted that this not strictly necessary since the |
shelhamer
merged commit 3e94c0e
into
BVLC:master
Jul 11, 2016
1 check passed
Sure, but it's nice to be able to change it without editing
Thanks! |
lukeyeager
deleted the
lukeyeager:bvlc/expose-all-netstate-options branch
Jul 11, 2016
This was referenced Jul 12, 2016
fxbit
added a commit
to Yodigram/caffe
that referenced
this pull request
Sep 1, 2016
|
|
shelhamer + fxbit |
b82abb9
|
lukeyeager commentedMar 21, 2016
•
edited
Was #3736
There are 3 configurable dimensions to a network's NetState: phase (TRAIN or TEST), level and stage. Currently, only phase is exposed through common interfaces. This PR exposes level and stage to the user, further enabling all-in-one nets (#1245)
New CLI:
New pycaffe interface:
EDIT: PR has been updated not to break old code
This is a breaking change (see #1790 (comment) for an explanation). Users will need to transform pycaffe code like:to:With some effort, this could probably be done without breaking the interface (but I'd need some help with the Boost.Python code). However, I am actually in favor of breaking the interface in order to make it simpler and more "Pythonic".