Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions python/tvm/relay/frontend/tensorflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,12 @@ def _impl(inputs, attr, params, mod):
)
attr["data_format"] = "NCHW"

if opname == "conv_transpose" and len(attr["_output_shapes"]) > 0:
# Check whether output shapes attribute is set and not None
if (
opname == "conv_transpose"
and len(attr["_output_shapes"]) > 0
and attr["_output_shapes"][0]
):
tmp_shape = attr["_output_shapes"][0]
tmp_shape = [tmp_shape[ii] for ii in (0, 3, 1, 2)]
attr["_output_shapes"][0] = tmp_shape
Expand Down Expand Up @@ -385,7 +390,12 @@ def _impl(inputs, attr, params, mod):
kernel_h, kernel_w = attr["kernel_shape"]

pdata_shape = input_shape
if opname == "conv_transpose" and len(attr["_output_shapes"]) > 0:
# Check whether output shapes attribute is set and not None
if (
opname == "conv_transpose"
and len(attr["_output_shapes"]) > 0
and attr["_output_shapes"][0]
):
pdata_shape = attr["_output_shapes"][0]

if attr["data_format"] == "NHWC":
Expand Down
84 changes: 81 additions & 3 deletions tests/python/frontend/tensorflow/test_forward.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ def compare_tf_with_tvm(
opt_level=3,
mode="graph_runtime",
cuda_layout="NCHW",
add_shapes_to_graph_def=True,
):
"""Generic function to generate and compare tensorflow and TVM output"""

Expand All @@ -219,7 +220,11 @@ def name_without_num(name):
with tf.Session() as sess:
if init_global_variables:
sess.run(variables.global_variables_initializer())
final_graph_def = tf_testing.AddShapesToGraphDef(sess, out_node)
final_graph_def = (
tf_testing.AddShapesToGraphDef(sess, out_node)
if add_shapes_to_graph_def
else tf.get_default_graph().as_graph_def()
)

tf_output = run_tf_graph(sess, in_data, in_name, out_name)

Expand Down Expand Up @@ -420,6 +425,7 @@ def _test_convolution(
padding,
data_format,
deconv_output_shape=[],
add_shapes_to_graph_def=True,
):
""" One iteration of convolution with given shapes and attributes """

Expand Down Expand Up @@ -454,6 +460,7 @@ def _test_convolution(
np.reshape(data_array, tensor_in_sizes).astype("float32"),
"Placeholder:0",
"Conv2D:0",
add_shapes_to_graph_def=add_shapes_to_graph_def,
)
elif opname == "conv_transpose":
nn_ops.conv2d_transpose(
Expand All @@ -469,6 +476,7 @@ def _test_convolution(
np.reshape(data_array, tensor_in_sizes).astype("float32"),
"Placeholder:0",
"conv2d_transpose:0",
add_shapes_to_graph_def=add_shapes_to_graph_def,
)
else:
nn_ops.depthwise_conv2d_native(
Expand All @@ -484,6 +492,7 @@ def _test_convolution(
np.reshape(data_array, tensor_in_sizes).astype("float32"),
"Placeholder:0",
"DepthwiseConv2dNative:0",
add_shapes_to_graph_def=add_shapes_to_graph_def,
)


Expand Down Expand Up @@ -646,11 +655,32 @@ def test_forward_convolution():
_test_convolution("conv", [4, 17, 17, 19], [3, 3, 19, 19], [1, 1], [2, 2], "VALID", "NHWC")
_test_convolution("conv", [4, 17, 17, 124], [1, 1, 124, 19], [1, 1], [1, 1], "SAME", "NHWC")
_test_convolution("conv", [4, 17, 17, 12], [3, 3, 12, 32], [1, 1], [2, 2], "VALID", "NHWC")
_test_convolution(
"conv",
[4, 17, 17, 12],
[3, 3, 12, 32],
[1, 1],
[2, 2],
"VALID",
"NHWC",
add_shapes_to_graph_def=False,
)
_test_convolution("depthwise", [4, 8, 8, 176], [1, 1, 176, 1], [1, 1], [1, 1], "SAME", "NHWC")
_test_convolution("depthwise", [4, 17, 17, 19], [3, 3, 19, 1], [1, 1], [2, 2], "VALID", "NHWC")
_test_convolution("depthwise", [4, 17, 17, 124], [1, 1, 124, 1], [1, 1], [1, 1], "SAME", "NHWC")
_test_convolution("depthwise", [4, 17, 17, 12], [3, 3, 12, 1], [1, 1], [2, 2], "VALID", "NHWC")
_test_convolution("depthwise", [4, 17, 17, 12], [3, 3, 12, 2], [1, 1], [2, 2], "VALID", "NHWC")
_test_convolution(
"depthwise",
[4, 17, 17, 12],
[3, 3, 12, 2],
[1, 1],
[2, 2],
"VALID",
"NHWC",
add_shapes_to_graph_def=False,
)

_test_convolution(
"conv_transpose",
[4, 8, 8, 32],
Expand Down Expand Up @@ -783,6 +813,18 @@ def test_forward_convolution():
"NHWC",
[1, 8, 8, 1],
)
# Test without adding shapes to graph def
_test_convolution(
"conv_transpose",
[4, 8, 8, 32],
[1, 1, 176, 32],
[1, 1],
[1, 1],
"SAME",
"NHWC",
[4, 8, 8, 176],
add_shapes_to_graph_def=False,
)


#######################################################################
Expand All @@ -799,6 +841,7 @@ def _test_convolution3d(
padding,
data_format,
deconv_output_shape=[],
add_shapes_to_graph_def=True,
):
""" One iteration of 3D convolution with given shapes and attributes """

Expand Down Expand Up @@ -834,6 +877,7 @@ def _test_convolution3d(
"Placeholder:0",
"Conv3D:0",
cuda_layout="NCDHW",
add_shapes_to_graph_def=add_shapes_to_graph_def,
)


Expand Down Expand Up @@ -864,6 +908,17 @@ 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"
)
# Test without adding shapes to graph def
_test_convolution3d(
"conv",
[4, 17, 17, 17, 12],
[3, 3, 3, 12, 32],
[1, 1, 1],
[2, 2, 2],
"VALID",
"NDHWC",
add_shapes_to_graph_def=False,
)


#######################################################################
Expand All @@ -872,7 +927,13 @@ def test_forward_convolution3d():


def _test_convolution3d_transpose(
data_shape, filter_shape, strides, padding, output_shape, data_format="NCDHW"
data_shape,
filter_shape,
strides,
padding,
output_shape,
data_format="NCDHW",
add_shapes_to_graph_def=True,
):
""" One iteration of 3D convolution transpose with given shapes and attributes """

Expand All @@ -897,7 +958,13 @@ def _test_convolution3d_transpose(
data_format=data_format,
)

compare_tf_with_tvm(data_array, "Placeholder:0", "conv3d_transpose:0", cuda_layout="NDHWC")
compare_tf_with_tvm(
data_array,
"Placeholder:0",
"conv3d_transpose:0",
cuda_layout="NDHWC",
add_shapes_to_graph_def=add_shapes_to_graph_def,
)


@tvm.testing.uses_gpu
Expand Down Expand Up @@ -971,6 +1038,17 @@ def test_forward_convolution3d_transpose():
data_format="NDHWC",
)

# Test without adding shapes to graph def
_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, 24, 24, 24, 6],
data_format="NDHWC",
add_shapes_to_graph_def=False,
)


#######################################################################
# BiasAdd
Expand Down