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

Update Python interface, using OrderedDict for blobs and layers #199

Merged
merged 13 commits into from
Mar 18, 2014

Conversation

longjon
Copy link
Contributor

@longjon longjon commented Mar 11, 2014

This commit modifies the pycaffe interface to use OrderedDict in place of lists for blobs and layers, per the discussion in #112. Some notes:

  • There are four ways this could have been accomplished:

    1. return an OrderedDict using boost::python
    2. in separate Python code, write a wrapper class with the boost interface as member
    3. in separate Python code, write a wrapper extending the boost interface through inheritance
    4. in separate Python code, directly update the class exposed through boost

    This PR uses the third method. The first is a headache, and it may be useful to add more pure-Python functionality anyway. The second requires explicit wrappers for every method exposed via boost. The fourth makes the code a little less obvious and more mind-bending.

  • caffe.CaffeNet was renamed caffe.Net

  • Net.blobs was made an OrderedDict

  • Layers are now exposed as an OrderedDict (which really just provides groups of parameter blobs). Note that layer parameter blobs don't have names in caffe proper, only layers have names, so Net.params was kept as a list, as it is in C++.

  • This code should probably be updated to use Feature extraction, feature binarization and image retrieval examples #161 if/when that is merged.

  • You'll need to make clean before building this.

This commit should not break any code which does not refer explicitly to
caffe.pycaffe.
This commit restores caffe.pycaffe as Python code that wraps
caffe._caffe. It also renames caffe.CaffeNet as the less-redundant
caffe.Net.
For now, only layer names and blobs are accessible, but more
functionality (layer Forward and Backward) could be added later.
Even though these are redundant, this keeps the meaning of
CaffeBlob.name consistent for now, and will allow CaffeBlob construction
to be simplified.
This prevents accidental construction of partially-specified blobs,
which could break the Python layer.
@longjon
Copy link
Contributor Author

longjon commented Mar 15, 2014

Per offline discussion with @shelhamer, the naming has been cleaned up (and is ready for review and merge). The interface exposes:

  • Net.blobs, an OrderedDict of feature data, each blob having data and diff arrays (as before)
  • Net.params, an OrderedDict of lists of blobs, one list for each layer that has parameters

shelhamer added a commit that referenced this pull request Mar 18, 2014
Update Python interface, using OrderedDict for blobs and layers to expose activations, params, and diffs.
@shelhamer shelhamer merged commit f890a18 into BVLC:dev Mar 18, 2014
@shelhamer
Copy link
Member

Thanks @longjon! This is a marked improvement to the interface.

@shelhamer shelhamer mentioned this pull request Mar 18, 2014
mitmul pushed a commit to mitmul/caffe that referenced this pull request Sep 30, 2014
Update Python interface, using OrderedDict for blobs and layers to expose activations, params, and diffs.
@longjon longjon deleted the pycaffe-ordereddict branch December 30, 2014 05:00
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.

3 participants