39
39
40
40
#define INTERP_MIN (a , b ) ((a) < (b) ? (a) : (b))
41
41
42
- void linear_coeffs (int w , int outw , int * xofs , float * alpha )
42
+ static void linear_coeffs (int w , int outw , int * xofs , float * alpha , int align_corner )
43
43
{
44
44
double scale = (double )w / outw ;
45
-
45
+ if (align_corner )
46
+ {
47
+ scale = (double )(w - 1 ) / (outw - 1 );
48
+ }
46
49
for (int dx = 0 ; dx < outw ; dx ++ )
47
50
{
48
- float fx = (float )((dx )* scale );
51
+ float fx = (float )((dx + 0.5 ) * scale - 0.5 );
52
+ if (align_corner )
53
+ {
54
+ fx = (float )(dx * scale );
55
+ }
56
+
49
57
int sx = floor (fx );
50
58
fx -= sx ;
51
59
@@ -193,7 +201,7 @@ int ref_interp_fp32(struct tensor* input_tensor, struct tensor* output_tensor, s
193
201
}
194
202
}
195
203
}
196
- else if (param -> resize_type == 2 )
204
+ else if (param -> resize_type == 2 || param -> resize_type == 4 )
197
205
{
198
206
float * input = (float * )input_tensor -> data ;
199
207
float * output = (float * )output_tensor -> data ;
@@ -222,8 +230,9 @@ int ref_interp_fp32(struct tensor* input_tensor, struct tensor* output_tensor, s
222
230
float * alpha = (float * )(buf + param -> output_width + param -> output_height ); //new float[ow * 2];
223
231
float * beta = (float * )(buf + param -> output_width + param -> output_height + param -> output_width * 2 ); //new float[oh * 2];
224
232
225
- linear_coeffs (in_w , out_w , xofs , alpha );
226
- linear_coeffs (in_h , out_h , yofs , beta );
233
+ int align_corner = param -> resize_type == 2 ? 0 : 1 ;
234
+ linear_coeffs (in_w , out_w , xofs , alpha , align_corner );
235
+ linear_coeffs (in_h , out_h , yofs , beta , align_corner );
227
236
228
237
for (int q = 0 ; q < channel ; ++ q )
229
238
{
@@ -290,7 +299,7 @@ int ref_interp_int8(struct tensor* input_tensor, struct tensor* output_tensor, s
290
299
}
291
300
}
292
301
}
293
- else if (param -> resize_type == 2 )
302
+ else if (param -> resize_type == 2 || param -> resize_type == 4 )
294
303
{
295
304
int batch = input_tensor -> dims [0 ];
296
305
int channel = input_tensor -> dims [1 ];
@@ -316,8 +325,9 @@ int ref_interp_int8(struct tensor* input_tensor, struct tensor* output_tensor, s
316
325
float * alpha = (float * )(buf + param -> output_width + param -> output_height ); //new float[ow * 2];
317
326
float * beta = (float * )(buf + param -> output_width + param -> output_height + param -> output_width * 2 ); //new float[oh * 2];
318
327
319
- linear_coeffs (in_w , out_w , xofs , alpha );
320
- linear_coeffs (in_h , out_h , yofs , beta );
328
+ int align_corner = param -> resize_type == 2 ? 0 : 1 ;
329
+ linear_coeffs (in_w , out_w , xofs , alpha , align_corner );
330
+ linear_coeffs (in_h , out_h , yofs , beta , align_corner );
321
331
322
332
for (int q = 0 ; q < channel ; ++ q )
323
333
{
@@ -398,7 +408,7 @@ int ref_interp_uint8(struct tensor* input_tensor, struct tensor* output_tensor,
398
408
}
399
409
}
400
410
}
401
- else if (param -> resize_type == 2 )
411
+ else if (param -> resize_type == 2 || param -> resize_type == 4 )
402
412
{
403
413
int batch = input_tensor -> dims [0 ];
404
414
int channel = input_tensor -> dims [1 ];
@@ -424,8 +434,9 @@ int ref_interp_uint8(struct tensor* input_tensor, struct tensor* output_tensor,
424
434
float * alpha = (float * )(buf + param -> output_width + param -> output_height ); //new float[ow * 2];
425
435
float * beta = (float * )(buf + param -> output_width + param -> output_height + param -> output_width * 2 ); //new float[oh * 2];
426
436
427
- linear_coeffs (in_w , out_w , xofs , alpha );
428
- linear_coeffs (in_h , out_h , yofs , beta );
437
+ int align_corner = param -> resize_type == 2 ? 0 : 1 ;
438
+ linear_coeffs (in_w , out_w , xofs , alpha , align_corner );
439
+ linear_coeffs (in_h , out_h , yofs , beta , align_corner );
429
440
430
441
for (int q = 0 ; q < channel ; ++ q )
431
442
{
0 commit comments