@@ -47,6 +47,9 @@ void* WindowDataLayerPrefetch(void* layer_pointer) {
4747 const int mean_width = layer->data_mean_ .width ();
4848 const int mean_height = layer->data_mean_ .height ();
4949 cv::Size cv_crop_size (cropsize, cropsize);
50+ const string& crop_mode = layer->layer_param_ .crop_mode ();
51+
52+ bool use_square = (crop_mode == " square" ) ? true : false ;
5053
5154 // zero out batch
5255 memset (top_data, 0 , sizeof (Dtype)*layer->prefetch_data_ ->count ());
@@ -93,7 +96,7 @@ void* WindowDataLayerPrefetch(void* layer_pointer) {
9396
9497 int pad_w = 0 ;
9598 int pad_h = 0 ;
96- if (context_pad > 0 ) {
99+ if (context_pad > 0 || use_square ) {
97100 // scale factor by which to expand the original region
98101 // such that after warping the expanded region to cropsize x cropsize
99102 // there's exactly context_pad amount of padding on each side
@@ -105,6 +108,13 @@ void* WindowDataLayerPrefetch(void* layer_pointer) {
105108 Dtype half_width = static_cast <Dtype>(x2-x1+1 )/2.0 ;
106109 Dtype center_x = static_cast <Dtype>(x1) + half_width;
107110 Dtype center_y = static_cast <Dtype>(y1) + half_height;
111+ if (use_square) {
112+ if (half_height > half_width) {
113+ half_width = half_height;
114+ } else {
115+ half_height = half_width;
116+ }
117+ }
108118 x1 = static_cast <int >(round (center_x - half_width*context_scale));
109119 x2 = static_cast <int >(round (center_x + half_width*context_scale));
110120 y1 = static_cast <int >(round (center_y - half_height*context_scale));
@@ -339,6 +349,8 @@ void WindowDataLayer<Dtype>::SetUp(const vector<Blob<Dtype>*>& bottom,
339349 LOG (INFO ) << " Amount of context padding: "
340350 << this ->layer_param_ .context_pad ();
341351
352+ LOG (INFO ) << " Crop mode: " << this ->layer_param_ .crop_mode ();
353+
342354 // image
343355 int cropsize = this ->layer_param_ .cropsize ();
344356 CHECK_GT (cropsize, 0 );
0 commit comments