You're right. The cropping layer takes a crop bottom and a reference bottom.
1 - How does caffe understand where to crop? Apparently it does not by default. You have to tell it by specifying the offset
2 - What does the offset parameter used for? It is used to tell the cropping layer where exactly to crop.
Let's take an example:
Blobs are 4D : (Batch size , Number of channels/filter , Height, Width) = (N,C,H,W)
1-crop bottom A is (20, 50, 512, 512)
2-reference bottom B is (20, 10, 256, 256)
3-the top blob C (result blob) will be (20, 10, 256, 256)
In this example we want to crop dimensions 1,2 & 3. But keep dimension 0 fixed.
So we set axis=1 (that will crop 1 and all the following axes)
The other parameter 'offset' specifies where exactly should the crop take place in A. Apparently this parameter has no defaults and have to be specified.
There are 2 modes :
1- Specify 3 offsets, one for each dimension : say offset = (25, 128, 128)
- So axis=1, offset=(25,128,128)
- The crop operation in numpy syntax will be : C = A[: , 25: 25+B.shape[1] , 128: 128+B.shape[2] , 128: 128+B.shape[3] ]
- In words : this will only take filters of A 25 to 35 and ignore the rest. And do a center crop for the spatial dimensions
2- Specify 1 offset that applies for all dimensions : offset = 25
- This will be exactly like in (1) with offset = (25, 25, 25)
The prototxt for mode (1) is the following :
layer {
name: "crop_layer"
type: "Crop"
bottom: "A"
bottom: "B"
top: "C"
crop_param {
axis: 1
offset: 25
offset: 128
offset: 128
}
}