@@ -3192,7 +3192,7 @@ def func(x):
3192
3192
def test_resize_nearest_neighbor (self ):
3193
3193
x_shape = [1 , 15 , 20 , 2 ]
3194
3194
x_new_size = [30 , 40 ]
3195
- x_val = np .arange (1 , 1 + np .prod (x_shape )).astype ("float32" ).reshape (x_shape )
3195
+ x_val = np .arange (1 , 1 + np .prod (x_shape )/ 10 , 0.1 ).astype ("float32" ).reshape (x_shape )
3196
3196
def func (x ):
3197
3197
x_new_size_ = tf .constant (x_new_size )
3198
3198
x_ = resize_nearest_neighbor (x , x_new_size_ )
@@ -3202,7 +3202,7 @@ def func(x):
3202
3202
@check_opset_min_version (9 , "resize_nearest_neighbor" )
3203
3203
def test_resize_nearest_neighbor_with_non_const (self ):
3204
3204
x_shape = [3 , 10 , 8 , 5 ]
3205
- x_val = np .arange (1 , 1 + np .prod (x_shape ), dtype = np .float32 ).reshape (x_shape )
3205
+ x_val = np .arange (1 , 1 + np .prod (x_shape )/ 10 , 0.1 , dtype = np .float32 ).reshape (x_shape )
3206
3206
x_new_size = np .array ([20 , 16 ]).astype (np .int32 )
3207
3207
def func (x , x_new_size_ ):
3208
3208
x_ = resize_nearest_neighbor (x , x_new_size_ )
@@ -3221,13 +3221,26 @@ def func(x):
3221
3221
return tf .identity (x_ , name = _TFOUTPUT )
3222
3222
_ = self ._run_test_case (func , [_OUTPUT ], {_INPUT : x_val })
3223
3223
3224
+ @skip_caffe2_backend ()
3225
+ @check_tf_min_version ("1.14" )
3226
+ @check_opset_min_version (11 , "coordinate_transformation_mode attr of resize_bilinear" )
3227
+ def test_resize_bilinear_align_coreners (self ):
3228
+ x_shape = [1 , 15 , 20 , 2 ]
3229
+ x_new_size = [30 , 40 ]
3230
+ x_val = np .arange (1 , 1 + np .prod (x_shape )/ 10 , 0.1 ).astype ("float32" ).reshape (x_shape )
3231
+ def func (x ):
3232
+ x_new_size_ = tf .constant (x_new_size )
3233
+ x_ = resize_bilinear (x , x_new_size_ , align_corners = True )
3234
+ return tf .identity (x_ , name = _TFOUTPUT )
3235
+ _ = self ._run_test_case (func , [_OUTPUT ], {_INPUT : x_val })
3236
+
3224
3237
@skip_caffe2_backend ()
3225
3238
@check_tf_min_version ("1.14" )
3226
3239
@check_opset_min_version (11 , "coordinate_transformation_mode attr" )
3227
3240
def test_resize_bilinear_half_pixel_centers (self ):
3228
3241
x_shape = [1 , 15 , 20 , 2 ]
3229
3242
x_new_size = [30 , 40 ]
3230
- x_val = np .arange (1 , 1 + np .prod (x_shape )).astype ("float32" ).reshape (x_shape )
3243
+ x_val = np .arange (1 , 1 + np .prod (x_shape )/ 10 , 0.1 ).astype ("float32" ).reshape (x_shape )
3231
3244
def func (x ):
3232
3245
x_new_size_ = tf .constant (x_new_size )
3233
3246
x_ = resize_bilinear (x , x_new_size_ , half_pixel_centers = True )
@@ -3237,7 +3250,7 @@ def func(x):
3237
3250
@check_opset_min_version (9 , "resize_bilinear" )
3238
3251
def test_resize_bilinear_with_non_const (self ):
3239
3252
x_shape = [3 , 10 , 8 , 5 ]
3240
- x_val = np .arange (1 , 1 + np .prod (x_shape ), dtype = np .float32 ).reshape (x_shape )
3253
+ x_val = np .arange (1 , 1 + np .prod (x_shape )/ 10 , 0.1 , dtype = np .float32 ).reshape (x_shape )
3241
3254
x_new_size = np .array ([20 , 16 ]).astype (np .int32 )
3242
3255
def func (x , x_new_size_ ):
3243
3256
x_ = resize_bilinear (x , x_new_size_ )
@@ -3248,7 +3261,7 @@ def func(x, x_new_size_):
3248
3261
def test_resize_bilinear_with_non_const2 (self ):
3249
3262
# scales has an element larger than 1 and also has an element less that 1
3250
3263
x_shape = [3 , 100 , 8 , 5 ]
3251
- x_val = np .arange (1 , 1 + np .prod (x_shape ), dtype = np .float32 ).reshape (x_shape )
3264
+ x_val = np .arange (1 , 1 + np .prod (x_shape )/ 10 , 0.1 , dtype = np .float32 ).reshape (x_shape )
3252
3265
x_new_size = np .array ([20 , 16 ]).astype (np .int32 )
3253
3266
def func (x , x_new_size_ ):
3254
3267
x_ = resize_bilinear (x , x_new_size_ )
@@ -3259,7 +3272,7 @@ def func(x, x_new_size_):
3259
3272
@check_opset_min_version (11 , "resize_bilinear_v2" )
3260
3273
def test_resize_bilinear_v2_with_non_const (self ):
3261
3274
x_shape = [3 , 10 , 8 , 5 ]
3262
- x_val = np .arange (1 , 1 + np .prod (x_shape ), dtype = np .float32 ).reshape (x_shape )
3275
+ x_val = np .arange (1 , 1 + np .prod (x_shape )/ 10 , 0.1 , dtype = np .float32 ).reshape (x_shape )
3263
3276
x_new_size = np .array ([20 , 16 ]).astype (np .int32 )
3264
3277
def func (x , x_new_size_ ):
3265
3278
x_ = resize_bilinear_v2 (x , x_new_size_ )
@@ -3304,7 +3317,7 @@ def func(x, y):
3304
3317
def test_resize_bicubic (self ):
3305
3318
x_shape = [1 , 15 , 20 , 2 ]
3306
3319
new_size_val = np .array ([30 , 40 ], dtype = np .int32 )
3307
- x_val = np .arange (1 , 1 + np .prod (x_shape )).astype ("float32" ).reshape (x_shape )
3320
+ x_val = np .arange (1 , 1 + np .prod (x_shape )/ 10 , 0.1 ).astype ("float32" ).reshape (x_shape )
3308
3321
def func (x , new_size ):
3309
3322
y = tf .image .resize (x , new_size , method = tf .image .ResizeMethod .BICUBIC )
3310
3323
return tf .identity (y , name = _TFOUTPUT )
@@ -3314,7 +3327,7 @@ def func(x, new_size):
3314
3327
def test_resize_nearest_neighbor2 (self ):
3315
3328
x_shape = [1 , 300 , 20 , 2 ]
3316
3329
x_new_size = [30 , 40 ]
3317
- x_val = np .arange (1 , 1 + np .prod (x_shape )).astype ("float32" ).reshape (x_shape )
3330
+ x_val = np .arange (1 , 1 + np .prod (x_shape )/ 10 , 0.1 ).astype ("float32" ).reshape (x_shape )
3318
3331
def func (x ):
3319
3332
x_new_size_ = tf .constant (x_new_size )
3320
3333
x_ = resize_nearest_neighbor (x , x_new_size_ )
@@ -3326,13 +3339,25 @@ def func(x):
3326
3339
def test_resize_nearest_neighbor_half_pixel_centers (self ):
3327
3340
x_shape = [1 , 10 , 20 , 2 ]
3328
3341
x_new_size = [20 , 40 ]
3329
- x_val = np .arange (1 , 1 + np .prod (x_shape )).astype ("float32" ).reshape (x_shape )
3342
+ x_val = np .arange (1 , 1 + np .prod (x_shape )/ 10 , 0.1 ).astype ("float32" ).reshape (x_shape )
3330
3343
def func (x ):
3331
3344
x_new_size_ = tf .constant (x_new_size )
3332
3345
x_ = resize_nearest_neighbor (x , x_new_size_ , half_pixel_centers = True )
3333
3346
return tf .identity (x_ , name = _TFOUTPUT )
3334
3347
_ = self ._run_test_case (func , [_OUTPUT ], {_INPUT : x_val })
3335
3348
3349
+ @check_tf_min_version ("1.14" )
3350
+ @check_opset_min_version (11 , "coordinate_transformation_mode and nearest_mode attr" )
3351
+ def test_resize_nearest_neighbor_align_corners (self ):
3352
+ x_shape = [1 , 10 , 20 , 2 ]
3353
+ x_new_size = [20 , 40 ]
3354
+ x_val = np .arange (1 , 1 + np .prod (x_shape )/ 10 , 0.1 ).astype ("float32" ).reshape (x_shape )
3355
+ def func (x ):
3356
+ x_new_size_ = tf .constant (x_new_size )
3357
+ x_ = resize_nearest_neighbor (x , x_new_size_ , align_corners = True )
3358
+ return tf .identity (x_ , name = _TFOUTPUT )
3359
+ _ = self ._run_test_case (func , [_OUTPUT ], {_INPUT : x_val })
3360
+
3336
3361
@check_opset_min_version (9 , "fill" )
3337
3362
def test_fill_float32 (self ):
3338
3363
x_shape = [1 , 15 , 20 , 2 ]
0 commit comments