Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PythonLayer takes parameters by string #2871

Merged
merged 1 commit into from
Aug 7, 2015

Conversation

shelhamer
Copy link
Member

Cherry-picking of the PythonLayer string parameter from #2001 by @tnarihi to give PythonLayer a param_str member for passing parameters through the python_param proto message.

This is a simple change in itself that leaves the choice of what and how to parameterize open.
There is no automatic eval

@shelhamer
Copy link
Member Author

@philkr have you adapted this test to Python 3 already?

@shelhamer shelhamer force-pushed the python-layer-arg branch 2 times, most recently from 4130028 to bd788bd Compare August 6, 2015 07:40


def python_net_file():
f = tempfile.NamedTemporaryFile(delete=False)
Copy link
Contributor

Choose a reason for hiding this comment

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

NamedTemporaryFile is created with mode='w+b' by default, which in python3 is a buffer, not a string. To fix this just call NamedTemporaryFile(mode='w+', delete=False).

@philkr
Copy link
Contributor

philkr commented Aug 6, 2015

The python3 error is easy to fix (see above). I have no idea why python2 fails on those warnings...

@tnarihi
Copy link
Contributor

tnarihi commented Aug 6, 2015

@shelhamer @philkr Thank you so much for taking care of my previous PR! Other than this, I still have a bunch of PRs for python that are not finished. If I need to update and polish them, please let me know.

@tnarihi
Copy link
Contributor

tnarihi commented Aug 6, 2015

According to this post in Stack Overflow, maybe we have to include Python.h first, which means we have to put include of boost/python.hpp first in tools/caffe.cpp. But I am not sure why this warning suddenly came out in this PR.

@philkr
Copy link
Contributor

philkr commented Aug 6, 2015

I think ac6d4b6 broke it. It seems to be broken for any PR based on the current master. ac6d4b6 introduced an additional include in caffe.cpp.

@shelhamer
Copy link
Member Author

Hmm, the branch CI had passed but this is an issue. I'll try to fix it shortly.

@shelhamer
Copy link
Member Author

@jeffdonahue @longjon does anybody have a favorite name or is param_str_ fine?

@jeffdonahue
Copy link
Contributor

I think param_str is fine. It could also just be called param or arg since the str is a little redundant with the protobuf type, but I could also see how it might be a useful hint to have the str annotation when parsing in Python.

@shelhamer shelhamer force-pushed the python-layer-arg branch 4 times, most recently from 245f920 to 39794ed Compare August 6, 2015 22:23
@shelhamer shelhamer added the JL label Aug 6, 2015
@shelhamer
Copy link
Member Author

I changed the name of the property to param_str on the Python side and simplified the test to just check multiplication by the param_str value. @longjon take a look and merge if you like it.

input: 'data' input_shape { dim: 10 dim: 9 dim: 8 }
layer { type: 'Python' name: 'mul10' bottom: 'data' top: 'mul10'
python_param { module: 'test_python_layer_with_param_str'
layer: 'SimpleParamLayer' param_str: "10" } }
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we be consistent with single-quotes here?

@longjon
Copy link
Contributor

longjon commented Aug 7, 2015

Looks good except as noted.

@shelhamer
Copy link
Member Author

Thanks for the glance @longjon. Fixed and merging.

shelhamer added a commit that referenced this pull request Aug 7, 2015
[pycaffe] PythonLayer takes parameters by string
@shelhamer shelhamer merged commit 5986a37 into BVLC:master Aug 7, 2015
@shelhamer shelhamer deleted the python-layer-arg branch August 7, 2015 01:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants