@@ -2473,26 +2473,46 @@ def test_batch_to_spacend(self):
2473
2473
self ._run_test_case ([_OUTPUT ], {_INPUT : input_val })
2474
2474
2475
2475
@check_opset_min_version (11 , "BatchToSpaceND" )
2476
- def test_batch_to_spacend_non_const (self ):
2477
- input_x_val = np .random .random_sample ([40 , 3 , 5 , 100 ]).astype (np .float32 ) # NHWC
2478
- block_shape_val = np .array ([2 , 2 ]).astype (np .int64 )
2479
- crops_val = np .array ([[1 , 0 ], [2 , 1 ]]).astype (np .int64 )
2480
- input_x = tf .placeholder (dtype = tf .float32 , shape = input_x_val .shape , name = _TFINPUT )
2481
- block_shape = tf .placeholder (dtype = tf .int64 , shape = block_shape_val .shape , name = _TFINPUT1 )
2482
- crops = tf .placeholder (dtype = tf .int64 , shape = crops_val .shape , name = _TFINPUT2 )
2483
- _ = tf .batch_to_space_nd (input_x , block_shape , crops , name = _TFOUTPUT )
2484
- self ._run_test_case ([_OUTPUT ], {_INPUT : input_x_val , _INPUT1 : block_shape_val , _INPUT2 : crops_val })
2476
+ def test_batch_to_spacend_non_const_7d (self ):
2477
+ x_type , y_type , z_type = np .int64 , np .int64 , np .int64
2478
+ # test 3D upto 6D input tensors
2479
+ for x_shape in [[12 , 4 , 4 ], [12 , 4 , 8 , 3 ], [12 , 4 , 8 , 3 , 2 ], [12 , 4 , 8 , 3 , 2 , 3 ], [12 , 4 , 8 , 3 , 2 , 1 , 3 ]]:
2480
+ # test 1D upto 7D block shapes
2481
+ for block_shape in [[2 , 3 ], [2 ]]:
2482
+ tf .reset_default_graph ()
2483
+ # crop 1 layer at end of each dim
2484
+ crops = [[0 , 1 ] for dim in block_shape ]
2485
+ y_val = np .array (block_shape ).astype (y_type )
2486
+ x_val = np .array ([x + 1 for x in range (0 , np .prod (x_shape ))], dtype = x_type ).reshape (x_shape )
2487
+ z_val = np .array (crops ).astype (z_type )
2488
+ # x and z can be dynamic.
2489
+ # y = block_shape cannot be dynamic without change to Transpose op spec
2490
+ x = tf .placeholder (dtype = x_type , shape = x_val .shape , name = _TFINPUT )
2491
+ y = tf .constant (dtype = y_type , value = y_val , shape = y_val .shape , name = _TFINPUT1 )
2492
+ z = tf .placeholder (dtype = z_type , shape = z_val .shape , name = _TFINPUT2 )
2493
+ _ = tf .batch_to_space_nd (x , y , z , name = _TFOUTPUT )
2494
+ self ._run_test_case ([_OUTPUT ], {_INPUT : x_val , _INPUT2 : z_val })
2485
2495
2486
2496
@check_opset_min_version (11 , "SpaceToBatchND" )
2487
- def test_space_to_batchnd_non_const (self ):
2488
- input_x_val = np .random .random_sample ([40 , 5 , 7 , 66 ]).astype (np .float32 ) # NHWC
2489
- block_size_val = np .array ([2 , 2 ]).astype (np .int64 )
2490
- pad_val = np .array ([[0 , 1 ], [2 , 1 ]]).astype (np .int64 )
2491
- input_x = tf .placeholder (dtype = tf .float32 , shape = input_x_val .shape , name = _TFINPUT )
2492
- block_size = tf .placeholder (dtype = tf .int64 , shape = block_size_val .shape , name = _TFINPUT1 )
2493
- pad = tf .placeholder (dtype = tf .int64 , shape = pad_val .shape , name = _TFINPUT2 )
2494
- _ = tf .space_to_batch_nd (input_x , block_size , pad , name = _TFOUTPUT )
2495
- self ._run_test_case ([_OUTPUT ], {_INPUT : input_x_val , _INPUT1 : block_size_val , _INPUT2 : pad_val })
2497
+ def test_space_to_batchnd_non_const_7d (self ):
2498
+ x_type , y_type , z_type = np .int64 , np .int64 , np .int64
2499
+ # test 3D upto 6D input tensors
2500
+ for x_shape in [[2 , 4 , 4 ], [1 , 4 , 8 , 3 ], [1 , 4 , 8 , 3 , 2 ], [1 , 4 , 8 , 3 , 2 , 3 ], [1 , 4 , 8 , 3 , 2 , 1 , 3 ]]:
2501
+ # test 1D upto 7D block shapes
2502
+ for block_shape in [[2 ], [2 , 2 ]]:
2503
+ tf .reset_default_graph ()
2504
+ # pad 1 layer at begin and end of each dim
2505
+ pads = [[1 , 1 ] for dim in block_shape ]
2506
+ y_val = np .array (block_shape ).astype (y_type )
2507
+ x_val = np .array ([x + 1 for x in range (0 , np .prod (x_shape ))], dtype = x_type ).reshape (x_shape )
2508
+ z_val = np .array (pads ).astype (z_type )
2509
+ # x and z can be dynamic.
2510
+ # y = block_shape cannot be dynamic without change to Transpose op spec
2511
+ x = tf .placeholder (dtype = x_type , shape = x_val .shape , name = _TFINPUT )
2512
+ y = tf .constant (dtype = y_type , value = y_val , shape = y_val .shape , name = _TFINPUT1 )
2513
+ z = tf .placeholder (dtype = z_type , shape = z_val .shape , name = _TFINPUT2 )
2514
+ _ = tf .space_to_batch_nd (x , y , z , name = _TFOUTPUT )
2515
+ self ._run_test_case ([_OUTPUT ], {_INPUT : x_val , _INPUT2 : z_val })
2496
2516
2497
2517
@check_opset_min_version (11 , "CropAndResize" )
2498
2518
def test_crop_and_resize_linear (self ):
0 commit comments