[fix] CropLayer: check dimension bounds only for cropped dimensions
authorEvan Shelhamer <shelhamer@imaginarynumber.net>
Fri, 15 Apr 2016 05:16:07 +0000 (22:16 -0700)
committerEvan Shelhamer <shelhamer@imaginarynumber.net>
Fri, 15 Apr 2016 06:12:45 +0000 (23:12 -0700)
check only the dimensions to be cropped for compatible sizes and offsets

src/caffe/layers/crop_layer.cpp

index e81bdd7..849208f 100644 (file)
@@ -61,12 +61,11 @@ void CropLayer<Dtype>::Reshape(const vector<Blob<Dtype>*>& bottom,
         // following axis
         crop_offset = param.offset(i - start_axis);
       }
+      // check that the crop and offset are within the dimension bounds
+      CHECK_GE(bottom[0]->shape(i) - crop_offset, bottom[1]->shape(i))
+          << "the crop for dimension " << i << " is out-of-bounds with "
+          << "size " << bottom[1]->shape(i) << " and offset " << crop_offset;
     }
-    // Check that the image we are cropping minus the margin is bigger
-    // than the destination image.
-    CHECK_GE(bottom[0]->shape(i) - crop_offset,
-             bottom[1]->shape(i))
-        << "invalid crop parameters in dimension: " << i;
     // Now set new size and offsets
     new_shape[i] = new_size;
     offsets[i] = crop_offset;