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

Python net spec cleanups and top-less layers #2813

Merged
merged 6 commits into from
Aug 8, 2015

Conversation

longjon
Copy link
Contributor

@longjon 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 6 commits July 23, 2015 20:23
This makes it possible to serialize Functions or Tops with a uniform
interface.
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.)
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.
@jeffdonahue
Copy link
Contributor

Cool! LGTM.

@shelhamer
Copy link
Member

Sweet. Thanks Jon!

shelhamer added a commit that referenced this pull request Aug 8, 2015
Python net spec cleanups and top-less layers
@shelhamer shelhamer merged commit eb3e114 into BVLC:master Aug 8, 2015
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