Python net spec cleanups and top-less layers #2813
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
(forfn
aFunction
); in particular, it need no longer be true thatfn.ntop == len(fn.tops)
, and iterating throughfn.tops
is no longer the same as iterating throughfn
'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 ofFunction
s andTop
s.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-lessFunction
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
Function
s (layers) separately fromTop
s (the fourth commit here), and have top-less layers return theirFunction
s rather than any (fictitious)Top
s (the fifth). It might be argued that this solution ungraciously overloads the semantics of net spec layer creation, since layers sometimes returnTop
s and sometimesFunction
s, 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 theirFunction
and all theirTop
s (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.