Skip to content

Commit 594f9ae

Browse files
committed
add unittest
Signed-off-by: Dom Miketa <[email protected]>
1 parent 133db14 commit 594f9ae

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

test/backend/test_dynamic_shape.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,32 @@ def test_conv_transpose(self):
248248

249249
np.testing.assert_almost_equal(tf_model_output[0], test_output, decimal=5)
250250

251+
def test_depth_to_space(self):
252+
b,c,h,w = shape = [2, 48, 5, 6]
253+
blocksize = 4
254+
x = self._get_rnd_float32(shape=shape)
255+
node_def = helper.make_node("DepthToSpace", ["X"], ["Y"], blocksize=blocksize, mode="DCR")
256+
graph_def = helper.make_graph(
257+
[node_def],
258+
name="test_unknown_shape",
259+
inputs=[
260+
helper.make_tensor_value_info("X", TensorProto.FLOAT,
261+
[None, None, None, None])
262+
],
263+
outputs=[helper.make_tensor_value_info("Y", TensorProto.FLOAT, [None, None, None, None])])
264+
tf_rep = onnx_graph_to_tensorflow_rep(graph_def)
265+
# export to tf.saved_model
266+
model_path = 'test_dynamic_shape/depth_to_space'
267+
tf_rep.export_graph(model_path)
268+
# load the saved_model back
269+
tf_model = tf.saved_model.load(model_path)
270+
# run the model
271+
tf_model_output = tf_model(X=x)
272+
tmp = np.reshape(x, [b, blocksize, blocksize, c // (blocksize**2), h, w])
273+
tmp = np.transpose(tmp, [0, 3, 4, 1, 5 ,2])
274+
y = np.reshape(tmp, [b, c // (blocksize**2), h*blocksize, w*blocksize])
275+
np.testing.assert_almost_equal(tf_model_output[0], y)
276+
251277
def test_eye_like(self):
252278
if legacy_opset_pre_ver(9):
253279
raise unittest.SkipTest("ONNX version {} doesn't support EyeLike.".format(

0 commit comments

Comments
 (0)