Added TF Convolution layer tests (#14851)

This commit is contained in:
Georgy Krivoruchko
2023-01-03 17:00:25 +04:00
committed by GitHub
parent 4248cdff28
commit 8dc946af5c
3 changed files with 158 additions and 1 deletions

View File

@@ -61,7 +61,7 @@ class CommonTFLayerTest(CommonLayerTest):
input = dict()
for key in inputs_dict.keys():
data = inputs_dict.get(key)
if self.use_old_api or self.use_new_frontend:
if not ':' in key:
key += ':0'
input[key] = transpose_nchw_to_nhwc(data, self.use_new_frontend, self.use_old_api)

View File

@@ -0,0 +1,82 @@
# Copyright (C) 2023 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
import numpy as np
import pytest
from common.tf_layer_test_class import CommonTFLayerTest
import logging
# Testing operation Conv2D
# Documentation: https://www.tensorflow.org/api_docs/python/tf/raw_ops/Conv2D
class TestConv2D(CommonTFLayerTest):
# input_shape - should be an array, shape of input tensor in format [batch, height, width, channels]
# input_filter - should be an array, defines a filter
# input_strides - should be an array, defines strides of a sliding window to use
# input_padding - should be a string, defines padding algorithm
# ir_version - common parameter
# use_new_frontend - common parameter
def create_conv2d_placeholder_const_net(self, input_shape, input_filter, input_strides, input_padding, dilations, ir_version, use_new_frontend):
"""
Tensorflow net IR net
Placeholder->Conv2D => Placeholder->Transpose->Convolution->Transpose
/ /
Placeholder-/ Placeholder->Transpose-/
"""
import tensorflow as tf
if dilations is None:
dilations = [1, 1, 1, 1] #default value regarding Documentation
# Batch Height Width Channel
expl_paddings = [0, 0, 1, 1, 1, 1, 0, 0]
if input_padding == 'EXPLICIT' and use_new_frontend == False:
pytest.xfail(reason="100300")
tf.compat.v1.reset_default_graph()
# Create the graph and model
with tf.compat.v1.Session() as sess:
tf_input = tf.compat.v1.placeholder(tf.float32, input_shape, "InputShape")
tf_filter = tf.compat.v1.placeholder(tf.float32, input_filter, "InputFilter")
if input_padding != 'EXPLICIT':
tf.raw_ops.Conv2D(input = tf_input, filter = tf_filter, strides = input_strides, padding = input_padding, dilations = dilations)
else:
tf.raw_ops.Conv2D(input = tf_input, filter = tf_filter, strides = input_strides, padding = input_padding, explicit_paddings=expl_paddings, dilations = dilations)
tf.compat.v1.global_variables_initializer()
tf_net = sess.graph_def
ref_net = None
return tf_net, ref_net
test_data = [
dict(input_shape=[1, 10, 10, 1], input_filter=[3, 3, 1, 1], input_strides=[1, 1, 1, 1], dilations=None),
dict(input_shape=[1, 10, 10, 2], input_filter=[3, 3, 2, 2], input_strides=[1, 1, 1, 1], dilations=None),
dict(input_shape=[1, 10, 10, 2], input_filter=[3, 3, 2, 1], input_strides=[1, 1, 1, 1], dilations=None),
dict(input_shape=[1, 10, 10, 3], input_filter=[2, 2, 3, 3], input_strides=[1, 1, 1, 1], dilations=None),
dict(input_shape=[1, 16, 16, 3], input_filter=[2, 2, 3, 3], input_strides=[1, 2, 2, 1], dilations=None),
dict(input_shape=[1, 10, 10, 4], input_filter=[2, 2, 4, 2], input_strides=[1, 1, 1, 1], dilations=None),
dict(input_shape=[1, 16, 16, 3], input_filter=[2, 2, 3, 3], input_strides=[1, 2, 2, 1], dilations=[1, 2, 2, 1]),
pytest.param(
dict(input_shape=[1, 224, 224, 3], input_filter=[4, 4, 3, 2], input_strides=[1, 2, 2, 1], dilations=[1, 2, 2, 1]),
marks=pytest.mark.precommit_tf_fe),
]
@pytest.mark.parametrize("params", test_data)
@pytest.mark.parametrize("padding", ['EXPLICIT', 'SAME', 'VALID'])
@pytest.mark.nightly
def test_conv2d_placeholder_const(self, params, padding, ie_device, precision, ir_version, temp_dir,
use_new_frontend, use_old_api):
self._test(*self.create_conv2d_placeholder_const_net(**params, input_padding=padding, ir_version=ir_version,
use_new_frontend=use_new_frontend),
ie_device, precision, ir_version, input_padding=padding, temp_dir=temp_dir,
use_new_frontend=use_new_frontend, use_old_api=use_old_api)

View File

@@ -0,0 +1,75 @@
# Copyright (C) 2023 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
import numpy as np
import pytest
from common.tf_layer_test_class import CommonTFLayerTest
import logging
# Testing operation Conv3D
# Documentation: https://www.tensorflow.org/api_docs/python/tf/raw_ops/Conv3D
class TestConv3D(CommonTFLayerTest):
# input_shape - should be an array, shape of input tensor in format [batch, depth, height, width, channels]
# input_filter - should be an array, defines a filter
# input_strides - should be an array, defines strides of a sliding window to use
# input_padding - should be a string, defines padding algorithm
# ir_version - common parameter
# use_new_frontend - common parameter
def create_conv3d_placeholder_const_net(self, input_shape, input_filter, input_strides, input_padding, dilations, ir_version, use_new_frontend):
"""
Tensorflow net IR net
Placeholder->Conv3D => Placeholder->Transpose->Convolution->Transpose
/ /
Placeholder-/ Placeholder->Transpose-/
"""
import tensorflow as tf
if dilations is None:
dilations = [1, 1, 1, 1, 1] #default value regarding Documentation
else:
pytest.skip('Dilations != 1 isn\' supported on CPU by Tensorflow')
tf.compat.v1.reset_default_graph()
# Create the graph and model
with tf.compat.v1.Session() as sess:
tf_input = tf.compat.v1.placeholder(tf.float32, input_shape, "InputShape")
tf_filter = tf.compat.v1.placeholder(tf.float32, input_filter, "InputFilter")
tf.raw_ops.Conv3D(input = tf_input, filter = tf_filter, strides = input_strides, padding = input_padding, dilations = dilations)
tf.compat.v1.global_variables_initializer()
tf_net = sess.graph_def
ref_net = None
return tf_net, ref_net
test_data = [
dict(input_shape=[1, 10, 10, 10, 1], input_filter=[3, 3, 3, 1, 1], input_strides=[1, 1, 1, 1, 1], dilations=None),
dict(input_shape=[1, 10, 10, 10, 2], input_filter=[3, 3, 3, 2, 2], input_strides=[1, 1, 1, 1, 1], dilations=None),
dict(input_shape=[1, 10, 10, 10, 2], input_filter=[3, 3, 3, 2, 1], input_strides=[1, 1, 1, 1, 1], dilations=None),
dict(input_shape=[1, 16, 16, 16, 3], input_filter=[4, 2, 4, 3, 3], input_strides=[1, 2, 2, 2, 1], dilations=None),
dict(input_shape=[1, 10, 10, 20, 3], input_filter=[2, 4, 2, 3, 3], input_strides=[1, 2, 2, 2, 1], dilations=None),
dict(input_shape=[1, 10, 10, 10, 4], input_filter=[3, 3, 3, 4, 2], input_strides=[1, 1, 1, 1, 1], dilations=None),
dict(input_shape=[1, 10, 10, 20, 3], input_filter=[2, 4, 2, 3, 3], input_strides=[1, 2, 2, 2, 1], dilations=[1, 2, 2, 2, 1]),
pytest.param(
dict(input_shape=[1, 224, 224, 224, 3], input_filter=[1, 2, 3, 3, 2], input_strides=[1, 2, 2, 2, 1], dilations=None),
marks=pytest.mark.precommit_tf_fe),
]
@pytest.mark.parametrize("params", test_data)
@pytest.mark.parametrize("padding", ['SAME', 'VALID'])
@pytest.mark.nightly
def test_conv3d_placeholder_const(self, params, padding, ie_device, precision, ir_version, temp_dir,
use_new_frontend, use_old_api):
self._test(*self.create_conv3d_placeholder_const_net(**params, input_padding=padding, ir_version=ir_version,
use_new_frontend=use_new_frontend),
ie_device, precision, ir_version, input_padding=padding, temp_dir=temp_dir,
use_new_frontend=use_new_frontend, use_old_api=use_old_api)