Augment layers with their induced coordinate maps #1637
Closed
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.
After #1615, not because that PR is necessary for this one, but so thatDeconvolutionLayer
is already supported.All layers map values from some array to another, often of a different size. For most basic convnet layers, this forward mapping naturally induces a mapping on the coordinates that index the values of the input and output arrays. Computing this map is often useful for constructing and analyzing nets. Doing so by hand is laborious and error-prone; this PR provides an automated mechanism.
There are a few basic ways this could be done:
Options 1 and 2 avoid touching the layer class definition, but require separated pieces of code to be kept in sync. Option 1 makes it impossible to use these coordinate maps within Caffe proper, e.g., by a future layer. Option 3 is the one implemented here.
This PR augments layers with a member function,
coord_map
, that keeps track of the coordinate mapping. A new type,DiagonalAffineMap
, is introduced to store these mappings. (Note that they all that they all take the formAx + b
, whereA
is diagonal. This could be generalized to a class hierarchy in the future.) Note that the coordinate maps depend only on the layer (specification) parameters, not on bottom data (though the latter is not strictly prohibited).For all existing layers, the induced coordinate map is one of the following:
FilterMap
FilterMap(...).inv()
.Certain conventions need to be chosen to define the induced coordinate map. The conventions used here:
num
dimension induces the identity map, thechannel
dimension does not induce a meaningful coordinate transformation. The mapping returned bycoord_map
therefore applies only to the coordinates for which such a mapping makes sense and is useful (i.e., the spatial dimensions). Thus all implemented maps are 2-dimensional (but the code should be easily extendable to Blobs are N-D arrays (for N not necessarily equals 4) #1486).Forward
. (Often one wants the reverse, easily accessible withDiagonalAffineMap::inv
.)Questions
DiagonalAffineMap::identity
as a static method, butFilterMap
as a separate function. Should they both be separate functions?