@@ -34,7 +34,7 @@ namespace {
3434void interpolate_nearest (float * out_buf_ptr, const float * images_buf,
3535 std::vector<int > images_strides, int crop_width,
3636 int image_width, int image_width_m1, int num_channels,
37- float extrapolation_value, int box_ind , float y_ind,
37+ float extrapolation_value, int box_offset , float y_ind,
3838 float width_scale, float x1, float x2) {
3939 for (int x = 0 ; x < crop_width; ++x) {
4040 const float x_ind = (crop_width > 1 ) ? x1 * image_width_m1 + x * width_scale
@@ -52,7 +52,7 @@ void interpolate_nearest(float* out_buf_ptr, const float* images_buf,
5252 float closest_y = round (y_ind);
5353 for (int c = 0 ; c < num_channels; ++c) {
5454 const int in_ind = c + closest_x * images_strides[2 ] +
55- closest_y * images_strides[1 ] + box_ind ;
55+ closest_y * images_strides[1 ] + box_offset ;
5656 *out_buf_ptr = images_buf[in_ind];
5757 out_buf_ptr++;
5858 }
@@ -123,7 +123,7 @@ void CropAndResize(int images_id, int boxes_id, int box_ind_id, int num_boxes,
123123 continue ;
124124 }
125125
126- const int box_ind = *box_ind_buf * images_strides[0 ];
126+ const int box_offset = *box_ind_buf * images_strides[0 ];
127127
128128 const float height_scale =
129129 (crop_height > 1 ) ? (y2 - y1) * image_height_m1 / (crop_height - 1 ) : 0 ;
@@ -175,22 +175,22 @@ void CropAndResize(int images_id, int boxes_id, int box_ind_id, int num_boxes,
175175
176176 if (should_memcpy) {
177177 int y_ind_int = y_ind;
178- images_buf += ( y_ind_int * images_strides[1 ] + box_ind) ;
179-
180- memcpy (out_buf_ptr, images_buf, sizeof (float ) * crop_width);
178+ int offset = box_offset + y_ind_int * images_strides[1 ];
179+ memcpy (out_buf_ptr, images_buf + offset,
180+ sizeof (float ) * crop_width * num_channels );
181181 continue ;
182182 }
183183
184184 if (method == InterpolationMethod::BILINEAR) {
185185 tfjs::wasm::interpolate_bilinear (
186186 out_buf_ptr, images_buf, images_strides, crop_width, image_width,
187187 image_width_m1, image_height_m1, num_channels, should_extrapolate,
188- extrapolation_value, box_ind , y_ind, width_scale, x1, x2);
188+ extrapolation_value, box_offset , y_ind, width_scale, x1, x2);
189189
190190 } else {
191191 interpolate_nearest (out_buf_ptr, images_buf, images_strides, crop_width,
192192 image_width, image_width_m1, num_channels,
193- extrapolation_value, box_ind , y_ind, width_scale,
193+ extrapolation_value, box_offset , y_ind, width_scale,
194194 x1, x2);
195195 }
196196 }
0 commit comments