-
Notifications
You must be signed in to change notification settings - Fork 18.7k
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 coordinate map and crop computation #3613
Conversation
By the way (this should become evident when tests are added): basic usage is like this: from caffe.coord_map import crop
from caffe import layers as L
data = L.Data(...)
...
output = L.Convolution(...)
cropped_output = crop(output, data) |
'TanH', 'Threshold'] | ||
|
||
def conv_params(fn): | ||
params = fn.params.get('convolution_param', fn.params) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If fn.type_name == 'Pooling'
, then this should check pooling_param
I think, since this can get called in coord_map
for pooling layers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not at work here, but a reminder to one day settle #1318.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not quite; perhaps this warrants a comment. What's going on here is that the parameters are normally read from fn.params
, which contains the conv params for a conv layer and the pooling params for a pooling layer. However, for layers which share the ConvolutionParameter
message type (i.e., currently only deconv layer), we need to explicitly ask for convolution_param
, since Convolution
is not the name of the layer.
Does this replace the "crop" layer types used in some fully convolutional networks? How do you perform training of fully convolutional networks if there is no crop layer to bring the per-pixel labels and the network output into the same coordinate space? Will you have to do the cropping manually as a pre-processing step on the training data? This looks rather inefficient to me. |
@longjon will #3570 and #3613 together provide the functionality in https://github.com/longjon/caffe/? I created longjon#11 to keep things going until the requisite parts are done. Also, is this close to merging? Things seem to have stalled in both for a month or so. Apologies if this is the wrong place to post this. |
import numpy as np | ||
from caffe import layers as L | ||
|
||
PASS_THROUGH_LAYERS = ['AbsVal', 'ReLU', 'PReLU', 'Dropout', 'LRN', 'Eltwise', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add ELU, Scale, Bias
846a8ea
to
2ad9995
Compare
@shelhamer thanks! Also are these two patches applied to master compatible with the exiting trained .caffemodel and .prototext of the version in https://github.com/longjon/caffe? |
The answer to my prior question is that no From the model zoo:
printed output in python:
key lines of stack trace:
@shelhamer is this perhaps a bug in this pull request? |
@ahundt, no (unless @shelhamer has made updates I'm not aware of), existing prototxts are not compatible with these two PRs. They will probably run with |
5860e05
to
775a5c7
Compare
8a46e4c
to
a3359a4
Compare
This provides a framework for automatically aligning different layers of a net despite up/downsampling, padding, and output size rounding.
Python/net spec coordinate map and crop computation * longjon/py-coord-map: [pycaffe] test coord_map [pycaffe] align coord_map and BVLC#3570 Crop layer [pycaffe] document, style, and complete coord_map [pycaffe] add coord_map.py for computing induced coordinate transform
- document by docstring and comment - pep8 - add latest layers and alphabetize - respect default crop params - handle graphs with compositions of crops by walking only the first, cropped bottom of Crop layers - make python3 happy by replacing arg tuple unpacking
- crop -> offset - adjust crop axis by 1
- test known mappings: conv-pool-deconv stack, ReLU and 1x1 conv - test effects of padding - test rectangular/anisotropic coordinate mapping, test N-D - catch error cases: negative crop, scale mismatch, tops that are not spatially connected
Python/net spec coordinate map and crop offset computation
@shelhamer Is it possible to post new or updated pre-trained fcn-xx models using this code in the model zoo? |
Does pycaffe support 'Crop' layer? I run caffe.Net to load model net = caffe.Net(model_file, model_weights, caffe.TEST) and got error: F0419 10:14:49.936854 10131 layer_factory.hpp:77] Check failed: registry.count(type) == 1 (0 vs. 1) Unknown layer type: Crop (known types: AbsVal, Accuracy, ArgMax, BNLL, Concat, ContrastiveLoss, Convolution, Data, Deconvolution, Dropout, DummyData, Eltwise, EuclideanLoss, Exp, Flatten, HDF5Data, HDF5Output, HingeLoss, Im2col, ImageData, InfogainLoss, InnerProduct, LRN, MVN, MemoryData, MultinomialLogisticLoss, Pooling, Power, ReLU, Sigmoid, SigmoidCrossEntropyLoss, Silence, Slice, Softmax, SoftmaxWithLoss, Split, TanH, Threshold, WindowData) (I used latest caffe master branch) |
Python/net spec coordinate map and crop offset computation
This PR provides an updated version of #1975 (see also #1976; this is the new version described there). This is meant for use along with #3570 (new ND crop layer).
This version has several advantages over #1975, which make it a better candidate for merge.
Net
andLayer
, whereas the strategy employed by Augment layers with their induced coordinate maps #1975 allowed for layers to interact in arbitrary ways that are difficult to reason about and make certain kinds of functionality difficult to implement. (This was the primary objection blocking the merge of Augment layers with their induced coordinate maps #1975.) The alternate strategy used here is to perform the net-level analysis at net definition time (through pycaffe's net spec), and bake the results into the parameters of the net, through a much more straightforward (e.g.) crop layer (now ND Crop layer #3570).Layer
interface remains unchanged; layers don't gain an extra method which may be obscure to some users.In addition, the functionality of this code is significantly expanded from that of #1975. In particular,
Eltwise
orConvolution
with multiple inputs/outputs) should now be supported.Like #1975, the coordinate maps computed with this code can be used for other purposes in addition to cropping.
The main disadvantage of this approach compared to #1975 is that the coordinate mapping formulae are kept apart from the definitions of their corresponding layers, which have to be manually kept in sync. Given that these formulae only come in a few basic forms, this seems like a reasonable approach for now.
This PR is not complete. The latest version of this code has just been written and has not been well-tested. Work still to be done:
coord_map_from_to
is more awkward than it needs to be)coord_map_from_to
)