Skip to content

Commit 24119b5

Browse files
authored
Merge pull request #44 from onnx/gs/onnx-1.2
add support for tf.space_to_depth()
2 parents 9c96a6d + f5f349a commit 24119b5

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

tests/test_backend.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -773,6 +773,16 @@ def test_topk(self):
773773
actual, expected = self._run(output, {x: x_val}, {_INPUT: x_val})
774774
self.assertAllClose(expected, actual)
775775

776+
@unittest.skipIf(BACKEND in ["caffe2", "onnxmsrt"], "Space2Depth not implemented, works on onnxmsrtnext")
777+
def test_space_to_depth(self):
778+
x_val = make_xval([1, 2, 2, 1])
779+
x = tf.placeholder(tf.float32, x_val.shape, name=_TFINPUT)
780+
x_ = tf.space_to_depth(x, block_size=2)
781+
output = tf.identity(x_, name=_TFOUTPUT)
782+
actual, expected = self._run(output, {x: x_val}, {_INPUT: x_val})
783+
self.assertAllClose(expected, actual)
784+
785+
776786
@unittest.skipIf(OPSET < 6, "supported since opset 6")
777787
def test_addn(self):
778788
x_val = np.arange(3*2*3).astype("float32")

tf2onnx/tfonnx.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -793,6 +793,13 @@ def tile_op7(ctx, node, name, args):
793793
return _convert_shapenode_to_int64(ctx, node, 1)
794794

795795

796+
def spacetodepth_op(ctx, node, name, args):
797+
block_size = node.get_attr("block_size")
798+
node.set_attr("blocksize", block_size.i)
799+
nodes = conv_convert_inputs(ctx, node, with_kernel=False)
800+
return nodes
801+
802+
796803
# pylint: enable=W0613,C0111,W0612
797804

798805
# map tensorflow ops to onnx ops. The format below is
@@ -876,6 +883,7 @@ def tile_op7(ctx, node, name, args):
876883
"Tanh": (direct_op, []),
877884
"Transpose": (transpose_op, []),
878885
"TopKV2": (topk_op, []),
886+
"SpaceToDepth": (spacetodepth_op, []),
879887
}
880888

881889
_OPSET_5 = {

tf2onnx/utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@
7575
'min', 'seed', 'ends', 'paddings', 'to', 'gamma', 'width_scale', 'normalize_variance', 'group', 'ratio', 'values',
7676
'dtype', 'output_shape', 'spatial', 'split', 'input_forget', 'keepdims', 'transA', 'auto_pad', 'border', 'low',
7777
'linear_before_reset', 'height_scale', 'output_padding', 'shape', 'kernel_shape', 'epsilon', 'size', 'starts',
78-
'direction', 'max', 'clip', 'across_channels', 'value', 'strides', 'extra_shape', 'scales', 'k', 'sample_size'
78+
'direction', 'max', 'clip', 'across_channels', 'value', 'strides', 'extra_shape', 'scales', 'k', 'sample_size',
79+
'blocksize'
7980
}
8081

8182

0 commit comments

Comments
 (0)