From 79ea1036bfc7ebea40368bdf5af7b931ced9d4f9 Mon Sep 17 00:00:00 2001 From: Siju Samuel Date: Thu, 11 Jun 2020 21:09:39 +0530 Subject: [PATCH 1/2] [TENSORFLOW]Conv3d Transpose OP added --- python/tvm/relay/frontend/tensorflow.py | 3 +- .../frontend/tensorflow/test_forward.py | 54 +++++++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/python/tvm/relay/frontend/tensorflow.py b/python/tvm/relay/frontend/tensorflow.py index 8a10cbe8d59e..ba958e95bd95 100644 --- a/python/tvm/relay/frontend/tensorflow.py +++ b/python/tvm/relay/frontend/tensorflow.py @@ -595,7 +595,7 @@ def _impl(inputs, attr, params, mod): out = AttrCvt( op_name=_dimension_picker('conv', surfix="_transpose" if opname == 'conv_transpose' else ""), - ignores=['explicit_paddings'], + ignores=['explicit_paddings', 'Tshape'], transforms={ 'kernel_shape': 'kernel_size', 'data_format': 'data_layout', @@ -2029,6 +2029,7 @@ def _impl(inputs, attr, params, mod): 'Conv2D' : _conv('conv'), 'Conv2DBackpropInput' : _conv('conv_transpose'), 'Conv3D' : _conv3d('conv'), + 'Conv3DBackpropInputV2' : _conv3d('conv_transpose'), 'Cos' : AttrCvt('cos'), 'Cosh' : AttrCvt('cosh'), 'CropAndResize' : _crop_and_resize(), diff --git a/tests/python/frontend/tensorflow/test_forward.py b/tests/python/frontend/tensorflow/test_forward.py index 07c1cd343bcd..6d10b9e51be1 100644 --- a/tests/python/frontend/tensorflow/test_forward.py +++ b/tests/python/frontend/tensorflow/test_forward.py @@ -523,6 +523,59 @@ def test_forward_convolution3d(): _test_convolution3d('conv', [4, 17, 17, 17, 12], [3, 3, 3, 12, 32], [1, 1, 1], [2, 2, 2], 'VALID', 'NDHWC') +####################################################################### +# Convolution3D Transpose +# ----------------------- + +def _test_convolution3d_transpose(data_shape, filter_shape, strides, padding, output_shape): + """ One iteration of 3D convolution transpose with given shapes and attributes """ + + dtype = 'float32' + data_array = np.random.uniform(size=data_shape).astype(dtype) + filter_array = np.random.uniform(size=filter_shape).astype(dtype) + + with tf.Graph().as_default(): + in_data = array_ops.placeholder(shape=data_shape, dtype=dtype) + in_filter = constant_op.constant( + filter_array, shape=filter_shape, dtype=dtype) + strides = [1, 1] + strides + + nn_ops.conv3d_transpose(in_data, + in_filter, + output_shape=output_shape, + strides=strides, + padding=padding, + data_format='NCDHW') + + compare_tf_with_tvm(data_array, 'Placeholder:0', 'conv3d_transpose:0', cuda_layout="NDHWC") + + +def test_forward_convolution3d_transpose(): + _test_convolution3d_transpose(data_shape=[1, 10, 8, 8, 8], + filter_shape=[1, 1, 1, 6, 10], + strides=[1, 1, 1], + padding='VALID', + output_shape=[1, 6, 8, 8, 8]) + + _test_convolution3d_transpose(data_shape=[4, 9, 8, 8, 8], + filter_shape=[1, 1, 1, 6, 9], + strides=[1, 1, 1], + padding='VALID', + output_shape=[4, 6, 8, 8, 8]) + + _test_convolution3d_transpose(data_shape=[1, 3, 8, 8, 8], + filter_shape=[1, 1, 1, 6, 3], + strides=[2, 2, 2], + padding='SAME', + output_shape=[1, 6, 15, 15, 15]) + + _test_convolution3d_transpose(data_shape=[1, 16, 8, 8, 8], + filter_shape=[3, 3, 3, 6, 16], + strides=[3, 3, 3], + padding='VALID', + output_shape=[1, 6, 24, 24, 24]) + + ####################################################################### # BiasAdd # ----------- @@ -3651,6 +3704,7 @@ def test_forward_spop(): # NN test_forward_convolution() test_forward_convolution3d() + test_forward_convolution3d_transpose() test_forward_pooling() test_forward_concat_v2() test_forward_lrn() From d687ee249ea054e0d7cc8ab15ac0939c49d07223 Mon Sep 17 00:00:00 2001 From: Siju Samuel Date: Fri, 12 Jun 2020 11:21:32 +0530 Subject: [PATCH 2/2] Testcase updated, tf cpu supports only ndhwc --- .../frontend/tensorflow/test_forward.py | 55 +++++++++++++++---- 1 file changed, 44 insertions(+), 11 deletions(-) diff --git a/tests/python/frontend/tensorflow/test_forward.py b/tests/python/frontend/tensorflow/test_forward.py index 6d10b9e51be1..1958844d19fc 100644 --- a/tests/python/frontend/tensorflow/test_forward.py +++ b/tests/python/frontend/tensorflow/test_forward.py @@ -527,53 +527,86 @@ def test_forward_convolution3d(): # Convolution3D Transpose # ----------------------- -def _test_convolution3d_transpose(data_shape, filter_shape, strides, padding, output_shape): +def _test_convolution3d_transpose(data_shape, filter_shape, strides, + padding, output_shape, data_format='NCDHW'): """ One iteration of 3D convolution transpose with given shapes and attributes """ dtype = 'float32' data_array = np.random.uniform(size=data_shape).astype(dtype) filter_array = np.random.uniform(size=filter_shape).astype(dtype) + if data_format == 'NDHWC': + strides = [1] + strides + [1] + else: + strides = [1, 1] + strides with tf.Graph().as_default(): in_data = array_ops.placeholder(shape=data_shape, dtype=dtype) in_filter = constant_op.constant( filter_array, shape=filter_shape, dtype=dtype) - strides = [1, 1] + strides nn_ops.conv3d_transpose(in_data, in_filter, output_shape=output_shape, strides=strides, padding=padding, - data_format='NCDHW') + data_format=data_format) compare_tf_with_tvm(data_array, 'Placeholder:0', 'conv3d_transpose:0', cuda_layout="NDHWC") def test_forward_convolution3d_transpose(): - _test_convolution3d_transpose(data_shape=[1, 10, 8, 8, 8], + if is_gpu_available(): + _test_convolution3d_transpose(data_shape=[1, 10, 8, 8, 8], + filter_shape=[1, 1, 1, 6, 10], + strides=[1, 1, 1], + padding='VALID', + output_shape=[1, 6, 8, 8, 8]) + + _test_convolution3d_transpose(data_shape=[4, 9, 8, 8, 8], + filter_shape=[1, 1, 1, 6, 9], + strides=[1, 1, 1], + padding='VALID', + output_shape=[4, 6, 8, 8, 8]) + + _test_convolution3d_transpose(data_shape=[1, 3, 8, 8, 8], + filter_shape=[1, 1, 1, 6, 3], + strides=[2, 2, 2], + padding='SAME', + output_shape=[1, 6, 15, 15, 15]) + + _test_convolution3d_transpose(data_shape=[1, 16, 8, 8, 8], + filter_shape=[3, 3, 3, 6, 16], + strides=[3, 3, 3], + padding='VALID', + output_shape=[1, 6, 24, 24, 24]) + + _test_convolution3d_transpose(data_shape=[1, 8, 8, 8, 10], filter_shape=[1, 1, 1, 6, 10], strides=[1, 1, 1], padding='VALID', - output_shape=[1, 6, 8, 8, 8]) + output_shape=[1, 8, 8, 8, 6], + data_format='NDHWC') - _test_convolution3d_transpose(data_shape=[4, 9, 8, 8, 8], + _test_convolution3d_transpose(data_shape=[4, 8, 8, 8, 9], filter_shape=[1, 1, 1, 6, 9], strides=[1, 1, 1], padding='VALID', - output_shape=[4, 6, 8, 8, 8]) + output_shape=[4, 8, 8, 8, 6], + data_format='NDHWC') - _test_convolution3d_transpose(data_shape=[1, 3, 8, 8, 8], + _test_convolution3d_transpose(data_shape=[1, 8, 8, 8, 3], filter_shape=[1, 1, 1, 6, 3], strides=[2, 2, 2], padding='SAME', - output_shape=[1, 6, 15, 15, 15]) + output_shape=[1, 15, 15, 15, 6], + data_format='NDHWC') - _test_convolution3d_transpose(data_shape=[1, 16, 8, 8, 8], + _test_convolution3d_transpose(data_shape=[1, 8, 8, 8, 16], filter_shape=[3, 3, 3, 6, 16], strides=[3, 3, 3], padding='VALID', - output_shape=[1, 6, 24, 24, 24]) + output_shape=[1, 24, 24, 24, 6], + data_format='NDHWC') #######################################################################