-
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
ND Crop layer #3570
ND Crop layer #3570
Conversation
@longjon So, my attempt at a ND crop layer, if this is approximately what you are looking for I can try to fix the GPU part. Edit: For the GPU part just implementing the 4D case would seem like a reasonable compromise. |
Actually I'm confused about the parameter interface here... what I had in mind is something mirroring the conv layer interface, with a scalar (i.e., The way it would work would be the same way conv layer works: if only one crop value is specified, all the dimensions after the specified The reason for doing it this way is because the crop values need to be determined from the net specification, and the net specification doesn't know how many dimensions the data will have! If the layers we are "cropping through" include conv/pool layers with non-singleton kernel sizes, then we know exactly how many dimensions to crop; but if not, all we can do is propagate the It would be nice to have an ND GPU kernel, but it's fine to punt that to get the basic functionality in. Thanks! |
@longjon The parameters should do what you want now. I substituted the copy kernel with repeated calls to caffe_copy, which if I understood correctly will call cudaMemcpy, and thus perform the copy operation on the GPU. My intuition is that calling this thousands of times is probably less efficient than writing a custom kernel. |
The parameters look right now.
|
bcbd2f7
to
c092887
Compare
@longjon The |
It seems to a few problems with the backward pass of
|
8495199
to
164472e
Compare
@bjosv79 Thanks. All those things seemed correct, I changed them ( but haven't tested yet ). |
@@ -306,7 +306,7 @@ message ParamSpec { | |||
// NOTE | |||
// Update the next available ID when you add a new LayerParameter field. | |||
// | |||
// LayerParameter next available layer-specific ID: 143 (last added: scale_param) | |||
// LayerParameter next available layer-specific ID: 144 (last added: crop_param) |
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.
Needs ID++ after #3211 -- sorry for the rebase.
@BlGene I pushed a rebase on the latest master to my fork https://github.com/shelhamer/caffe/tree/crop-nd with a few other additions -- feel free to integrate my changes if the commits save you time. |
// values specified must be equal to the number of dimensions following axis, and | ||
// the trailing dimensions would be cropped accordingly. | ||
// Protip: standard dimensions are ( N,C,H,W ) | ||
optional uint32 axis = 1 [default = 2]; |
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.
Let's make axis
mirror the axis
arg of other layers to allow for negative indexing through an int32
field and the CanonicalAxisIndex()
helper method? See for instance https://github.com/BVLC/caffe/blob/master/src/caffe/layers/flatten_layer.cpp#L12-L13
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
- crop -> offset - adjust crop axis by 1
66216cf
to
e03a287
Compare
@shelhamer OK, I fixed the commit messages. I'm happy to have FCN functionality merged too. Thanks for the attention to detail. 👍 |
configure offset(s) through proto definition.
Changes are: reduce test blob dims for speed use standard Gaussian filler, polish formatting and rename tests, test HW crop and 5D crop, standard gradient checks
- crop -> offset - adjust crop axis by 1
Just a quick question from my side, can the ND crop be used to implement a rectangular crop as in #1980? |
This layer crops blob B to have the same shape as Blob A. So its a bit hacky, but you could create a dummy blob (A) that has the desired shape and crop the (B) blob to this size. BR, Max |
- crop -> offset - adjust crop axis by 1
- crop -> offset - adjust crop axis by 1
- crop -> offset - adjust crop axis by 1
- crop -> offset - adjust crop axis by 1
- crop -> offset - adjust crop axis by 1
- crop -> offset - adjust crop axis by 1
- crop -> offset - adjust crop axis by 1
- crop -> offset - adjust crop axis by 1
- crop -> offset - adjust crop axis by 1
- crop -> offset - adjust crop axis by 1
- crop -> offset - adjust crop axis by 1
Something along the lines of what a ND crop layer would look like.
Based on: PR #1976 -> PR #3565 -> this
Todo
Please see PR #3613 for how to set the crop parameters.