Python net spec cleanups and top-less layers #2813

Merged
merged 6 commits into from Aug 8, 2015

Conversation

Projects
None yet
3 participants
Contributor

longjon commented Jul 24, 2015

This PR makes small stylistic improvements to the net spec code and includes an alternative implementation of the functionality provided by #2741.

While #2741 generates top-less layers, it breaks the meaningfulness of fn.tops (for fn a Function); in particular, it need no longer be true that fn.ntop == len(fn.tops), and iterating through fn.tops is no longer the same as iterating through fn's tops, which now requires a special case (https://github.com/BVLC/caffe/pull/2741/files#diff-57d5ca5bbea564c189da52386291f6d8R145), which, while mild in the current code, would need to propagate to future code that operates on the (Python-level) graph of Functions and Tops.

The fake top doesn't really need to be added to fn.tops, and could just be generated around https://github.com/BVLC/caffe/pull/2741/files#diff-57d5ca5bbea564c189da52386291f6d8R198, except that this would prohibit the top-less Function from discovering a name assigned to this fake top.

We could simply forgo naming of top-less layers, but a more complete solution is to allow naming of Functions (layers) separately from Tops (the fourth commit here), and have top-less layers return their Functions rather than any (fictitious) Tops (the fifth). It might be argued that this solution ungraciously overloads the semantics of net spec layer creation, since layers sometimes return Tops and sometimes Functions, but this is surely no worse than any solution in which top-less layers return something, since something cannot be a top that isn't. It's probably best to view this as an abbreviation of a syntax in which all layers return both their Function and all their Tops (an option which could actually be added in the future if it becomes desirable to create layers with distinct layer and first-top names).

A simple test for top-less layers is included.

Thanks @philkr for getting the ball rolling on toplessness, and let me know how you feel about this solution.

longjon added some commits Jul 24, 2015

@longjon longjon [pycaffe] remove dead code 129d222
@longjon longjon [pycaffe] use a Counter instead of a dict for counting net spec names 7488163
@longjon longjon [pycaffe] add Top._to_proto convenience function
This makes it possible to serialize Functions or Tops with a uniform
interface.
f16195a
@longjon longjon [pycaffe] allow layers to have names different from their first tops
Previously, net spec only allowed names to be assigned to Tops, giving
layers the names of their first tops. Now, names can be assigned to
Functions, which become layer names in serialization. Unnamed Functions
still get named after their first top, if present, or autogenerated, if
not. (This will allow top-less layers in a natural way.)
96c2fe1
@longjon longjon [pycaffe] net spec layers can have ntop=0
In this case, the Function is returned instead of a Top, which can be
assigned a name if desired.

Thanks @philkr for an earlier implementation of this.
b464a6e
@longjon longjon [pytest] simple test of top-less layers c80f6f5

longjon added the Python label Jul 24, 2015

Contributor

jeffdonahue commented Aug 7, 2015

Cool! LGTM.

Owner

shelhamer commented Aug 8, 2015

Sweet. Thanks Jon!

@shelhamer shelhamer added a commit that referenced this pull request Aug 8, 2015

@shelhamer shelhamer Merge pull request #2813 from longjon/net-spec-imp
Python net spec cleanups and top-less layers
eb3e114

@shelhamer shelhamer merged commit eb3e114 into BVLC:master Aug 8, 2015

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment