const int mean_width = layer->data_mean_.width();
const int mean_height = layer->data_mean_.height();
cv::Size cv_crop_size(cropsize, cropsize);
+ const string& crop_mode = layer->layer_param_.crop_mode();
+
+ bool use_square = (crop_mode == "square") ? true : false;
// zero out batch
memset(top_data, 0, sizeof(Dtype)*layer->prefetch_data_->count());
int pad_w = 0;
int pad_h = 0;
- if (context_pad > 0) {
+ if (context_pad > 0 || use_square) {
// scale factor by which to expand the original region
// such that after warping the expanded region to cropsize x cropsize
// there's exactly context_pad amount of padding on each side
Dtype half_width = static_cast<Dtype>(x2-x1+1)/2.0;
Dtype center_x = static_cast<Dtype>(x1) + half_width;
Dtype center_y = static_cast<Dtype>(y1) + half_height;
+ if (use_square) {
+ if (half_height > half_width) {
+ half_width = half_height;
+ } else {
+ half_height = half_width;
+ }
+ }
x1 = static_cast<int>(round(center_x - half_width*context_scale));
x2 = static_cast<int>(round(center_x + half_width*context_scale));
y1 = static_cast<int>(round(center_y - half_height*context_scale));
LOG(INFO) << "Amount of context padding: "
<< this->layer_param_.context_pad();
+ LOG(INFO) << "Crop mode: " << this->layer_param_.crop_mode();
+
// image
int cropsize = this->layer_param_.cropsize();
CHECK_GT(cropsize, 0);
// (used only by the window_data_layer)
optional uint32 context_pad = 58 [default = 0];
+ // Mode for cropping out a detection window
+ // warp: cropped window is warped to a fixed size and aspect ratio
+ // square: the tightest square around the window is cropped
+ optional string crop_mode = 59 [default = "warp"];
+
// For ReshapeLayer, one needs to specify the new dimensions.
optional int32 new_num = 60 [default = 0];
optional int32 new_channels = 61 [default = 0];