| 34 | |
| 35 | template <typename Dtype> |
| 36 | void CropLayer<Dtype>::Reshape(const vector<Blob<Dtype>*>& bottom, |
| 37 | const vector<Blob<Dtype>*>& top) { |
| 38 | const CropParameter& param = this->layer_param_.crop_param(); |
| 39 | int input_dim = bottom[0]->num_axes(); |
| 40 | const int start_axis = bottom[0]->CanonicalAxisIndex(param.axis()); |
| 41 | |
| 42 | // Initialize offsets to 0 and the new shape to the current shape of the data. |
| 43 | offsets = vector<int>(input_dim, 0); |
| 44 | vector<int> new_shape(bottom[0]->shape()); |
| 45 | |
| 46 | // Determine crop offsets and the new shape post-crop. |
| 47 | for (int i = 0; i < input_dim; ++i) { |
| 48 | int crop_offset = 0; |
| 49 | int new_size = bottom[0]->shape(i); |
| 50 | if (i >= start_axis) { |
| 51 | new_size = bottom[1]->shape(i); |
| 52 | if (param.offset_size() == 1) { |
| 53 | // If only one offset is given, all crops have the same offset. |
| 54 | crop_offset = param.offset(0); |
| 55 | } else if (param.offset_size() > 1) { |
| 56 | // For several offsets, the number of offsets must be equal to the |
| 57 | // number of dimensions to crop, that is dimensions after the axis. |
| 58 | crop_offset = param.offset(i - start_axis); |
| 59 | } |
| 60 | // Check that the crop and offset are within the dimension's bounds. |
| 61 | CHECK_GE(bottom[0]->shape(i) - crop_offset, bottom[1]->shape(i)) |
| 62 | << "the crop for dimension " << i << " is out-of-bounds with " |
| 63 | << "size " << bottom[1]->shape(i) << " and offset " << crop_offset; |
| 64 | } |
| 65 | new_shape[i] = new_size; |
| 66 | offsets[i] = crop_offset; |
| 67 | } |
| 68 | top[0]->Reshape(new_shape); |
| 69 | } |
| 70 | |
| 71 | template <typename Dtype> |
| 72 | void CropLayer<Dtype>::crop_copy(const vector<Blob<Dtype>*>& bottom, |
nothing calls this directly
no test coverage detected