[TF FE] Implement and refactor tensorflow layer tests (#8051)

* Revert submodule changes

* Fix build on Win

* Fix precommit: set correct shapes for broadcasting; disable check with ref for use_new_frontend mode

* fix precommit

* Fix precommits

* Temporary skip new tests on GPU with FP16

* Resolve review comments, trigger CI

* Resolve review comments

* Resolve review comments
This commit is contained in:
Ivan Tikhonov
2021-11-12 11:03:45 +03:00
committed by GitHub
parent 6ac18bbd1b
commit 00c7da0f5f
41 changed files with 868 additions and 1058 deletions

View File

@@ -5,10 +5,11 @@ import numpy as np
import pytest
from common.tf_layer_test_class import CommonTFLayerTest
from common.utils.tf_utils import permute_nchw_to_nhwc
class TestMul(CommonTFLayerTest):
def create_mul_placeholder_const_net(self, x_shape, y_shape, ir_version):
def create_mul_placeholder_const_net(self, x_shape, y_shape, ir_version, use_new_frontend):
"""
Tensorflow net IR net
@@ -30,11 +31,9 @@ class TestMul(CommonTFLayerTest):
with tf.compat.v1.Session() as sess:
tf_x_shape = x_shape.copy()
tf_y_shape = y_shape.copy()
# reshaping
if len(tf_x_shape) >= 3:
tf_x_shape.append(tf_x_shape.pop(1))
if len(tf_y_shape) >= 3:
tf_y_shape.append(tf_y_shape.pop(1))
tf_x_shape = permute_nchw_to_nhwc(tf_x_shape, use_new_frontend)
tf_y_shape = permute_nchw_to_nhwc(tf_y_shape, use_new_frontend)
x = tf.compat.v1.placeholder(tf.float32, tf_x_shape, 'Input')
constant_value = np.random.randint(-255, 255, tf_y_shape).astype(np.float32)
@@ -44,7 +43,6 @@ class TestMul(CommonTFLayerTest):
y = tf.constant(constant_value)
mul = tf.multiply(x, y, name="Operation")
mul_shape = mul.shape.as_list()
tf.compat.v1.global_variables_initializer()
tf_net = sess.graph_def
@@ -55,23 +53,6 @@ class TestMul(CommonTFLayerTest):
# Moreover, do not forget to validate ALL layer attributes!!!
#
if len(mul_shape) >= 3:
# Permute mul_shape to (N,C,...) format
order = [0, len(mul_shape) - 1] + list(range(1, len(mul_shape) - 1))
mul_shape = [mul_shape[i] for i in order]
y_shape_to_compare = tf_y_shape.copy()
while len(y_shape_to_compare) < len(x_shape):
# Expand shape of constant with 1
y_shape_to_compare = [1] + y_shape_to_compare
constant_value = np.expand_dims(constant_value, axis=0)
if len(y_shape_to_compare) >= 3:
# Permute constant_value to (N,C,...) format for correct further reshape
order = [0, len(y_shape_to_compare) - 1] + list(range(1, len(y_shape_to_compare) - 1))
y_shape_to_compare = [y_shape_to_compare[i] for i in order]
constant_value = np.transpose(constant_value, order)
ref_net = None
return tf_net, ref_net
@@ -87,9 +68,9 @@ class TestMul(CommonTFLayerTest):
@pytest.mark.parametrize("params", test_data_1D)
@pytest.mark.nightly
def test_mul_placeholder_const_1D(self, params, ie_device, precision, ir_version, temp_dir):
self._test(*self.create_mul_placeholder_const_net(**params, ir_version=ir_version),
ie_device, precision, ir_version, temp_dir=temp_dir)
def test_mul_placeholder_const_1D(self, params, ie_device, precision, ir_version, temp_dir, use_new_frontend):
self._test(*self.create_mul_placeholder_const_net(**params, ir_version=ir_version, use_new_frontend=use_new_frontend),
ie_device, precision, ir_version, temp_dir=temp_dir, use_new_frontend=use_new_frontend)
test_data_2D = [
# Power
@@ -104,9 +85,9 @@ class TestMul(CommonTFLayerTest):
@pytest.mark.parametrize("params", test_data_2D)
@pytest.mark.nightly
def test_mul_placeholder_const_2D(self, params, ie_device, precision, ir_version, temp_dir):
self._test(*self.create_mul_placeholder_const_net(**params, ir_version=ir_version),
ie_device, precision, ir_version, temp_dir=temp_dir)
def test_mul_placeholder_const_2D(self, params, ie_device, precision, ir_version, temp_dir, use_new_frontend):
self._test(*self.create_mul_placeholder_const_net(**params, ir_version=ir_version, use_new_frontend=use_new_frontend),
ie_device, precision, ir_version, temp_dir=temp_dir, use_new_frontend=use_new_frontend)
test_data_3D = [
# Power
@@ -122,9 +103,9 @@ class TestMul(CommonTFLayerTest):
@pytest.mark.parametrize("params", test_data_3D)
@pytest.mark.nightly
def test_mul_placeholder_const_3D(self, params, ie_device, precision, ir_version, temp_dir):
self._test(*self.create_mul_placeholder_const_net(**params, ir_version=ir_version),
ie_device, precision, ir_version, temp_dir=temp_dir)
def test_mul_placeholder_const_3D(self, params, ie_device, precision, ir_version, temp_dir, use_new_frontend):
self._test(*self.create_mul_placeholder_const_net(**params, ir_version=ir_version, use_new_frontend=use_new_frontend),
ie_device, precision, ir_version, temp_dir=temp_dir, use_new_frontend=use_new_frontend)
test_data_4D = [
# Power
@@ -139,9 +120,9 @@ class TestMul(CommonTFLayerTest):
@pytest.mark.parametrize("params", test_data_4D)
@pytest.mark.nightly
def test_mul_placeholder_const_4D(self, params, ie_device, precision, ir_version, temp_dir):
self._test(*self.create_mul_placeholder_const_net(**params, ir_version=ir_version),
ie_device, precision, ir_version, temp_dir=temp_dir)
def test_mul_placeholder_const_4D(self, params, ie_device, precision, ir_version, temp_dir, use_new_frontend):
self._test(*self.create_mul_placeholder_const_net(**params, ir_version=ir_version, use_new_frontend=use_new_frontend),
ie_device, precision, ir_version, temp_dir=temp_dir, use_new_frontend=use_new_frontend)
test_data_5D = [
# Power
@@ -158,9 +139,9 @@ class TestMul(CommonTFLayerTest):
# TODO mark as precommit (after successfully passing in nightly)
@pytest.mark.parametrize("params", test_data_5D)
@pytest.mark.nightly
def test_mul_placeholder_const_5D(self, params, ie_device, precision, ir_version, temp_dir):
self._test(*self.create_mul_placeholder_const_net(**params, ir_version=ir_version),
ie_device, precision, ir_version, temp_dir=temp_dir)
def test_mul_placeholder_const_5D(self, params, ie_device, precision, ir_version, temp_dir, use_new_frontend):
self._test(*self.create_mul_placeholder_const_net(**params, ir_version=ir_version, use_new_frontend=use_new_frontend),
ie_device, precision, ir_version, temp_dir=temp_dir, use_new_frontend=use_new_frontend)
###############################################################################################
# #
@@ -174,9 +155,9 @@ class TestMul(CommonTFLayerTest):
@pytest.mark.parametrize("params", test_data_broadcast_1D)
@pytest.mark.nightly
def test_mul_placeholder_const_broadcast_1D(self, params, ie_device, precision, ir_version, temp_dir):
self._test(*self.create_mul_placeholder_const_net(**params, ir_version=ir_version),
ie_device, precision, ir_version, temp_dir=temp_dir)
def test_mul_placeholder_const_broadcast_1D(self, params, ie_device, precision, ir_version, temp_dir, use_new_frontend):
self._test(*self.create_mul_placeholder_const_net(**params, ir_version=ir_version, use_new_frontend=use_new_frontend),
ie_device, precision, ir_version, temp_dir=temp_dir, use_new_frontend=use_new_frontend)
test_data_broadcast_2D = [
# Power
@@ -193,9 +174,9 @@ class TestMul(CommonTFLayerTest):
@pytest.mark.parametrize("params", test_data_broadcast_2D)
@pytest.mark.nightly
def test_mul_placeholder_const_broadcast_2D(self, params, ie_device, precision, ir_version, temp_dir):
self._test(*self.create_mul_placeholder_const_net(**params, ir_version=ir_version),
ie_device, precision, ir_version, temp_dir=temp_dir)
def test_mul_placeholder_const_broadcast_2D(self, params, ie_device, precision, ir_version, temp_dir, use_new_frontend):
self._test(*self.create_mul_placeholder_const_net(**params, ir_version=ir_version, use_new_frontend=use_new_frontend),
ie_device, precision, ir_version, temp_dir=temp_dir, use_new_frontend=use_new_frontend)
test_data_broadcast_3D = [
# Power
@@ -217,9 +198,9 @@ class TestMul(CommonTFLayerTest):
# TODO mark as precommit (after successfully passing in nightly)
@pytest.mark.parametrize("params", test_data_broadcast_3D)
@pytest.mark.nightly
def test_mul_placeholder_const_broadcast_3D(self, params, ie_device, precision, ir_version, temp_dir):
self._test(*self.create_mul_placeholder_const_net(**params, ir_version=ir_version),
ie_device, precision, ir_version, temp_dir=temp_dir)
def test_mul_placeholder_const_broadcast_3D(self, params, ie_device, precision, ir_version, temp_dir, use_new_frontend):
self._test(*self.create_mul_placeholder_const_net(**params, ir_version=ir_version, use_new_frontend=use_new_frontend),
ie_device, precision, ir_version, temp_dir=temp_dir, use_new_frontend=use_new_frontend)
test_data_broadcast_4D = [
# Power
@@ -235,9 +216,9 @@ class TestMul(CommonTFLayerTest):
# Eltwise
dict(x_shape=[1, 3, 1, 1], y_shape=[3, 1]),
# Eltwise
dict(x_shape=[1, 3, 1, 2], y_shape=[3, 1, 2]),
dict(x_shape=[1, 2, 1, 3], y_shape=[3, 1, 2]),
# Eltwise
dict(x_shape=[1, 3, 1, 2], y_shape=[1, 3, 2]),
dict(x_shape=[1, 2, 1, 3], y_shape=[1, 3, 2]),
# Eltwise
dict(x_shape=[1, 3, 100, 224], y_shape=[1, 1, 1, 224]),
# Eltwise
@@ -247,9 +228,9 @@ class TestMul(CommonTFLayerTest):
@pytest.mark.parametrize("params", test_data_broadcast_4D)
@pytest.mark.nightly
@pytest.mark.precommit
def test_mul_placeholder_const_broadcast_4D(self, params, ie_device, precision, ir_version, temp_dir):
self._test(*self.create_mul_placeholder_const_net(**params, ir_version=ir_version),
ie_device, precision, ir_version, temp_dir=temp_dir)
def test_mul_placeholder_const_broadcast_4D(self, params, ie_device, precision, ir_version, temp_dir, use_new_frontend):
self._test(*self.create_mul_placeholder_const_net(**params, ir_version=ir_version, use_new_frontend=use_new_frontend),
ie_device, precision, ir_version, temp_dir=temp_dir, use_new_frontend=use_new_frontend)
test_data_broadcast_5D = [
# Power
@@ -274,6 +255,6 @@ class TestMul(CommonTFLayerTest):
@pytest.mark.parametrize("params", test_data_broadcast_5D)
@pytest.mark.nightly
def test_mul_placeholder_const_broadcast_5D(self, params, ie_device, precision, ir_version, temp_dir):
self._test(*self.create_mul_placeholder_const_net(**params, ir_version=ir_version),
ie_device, precision, ir_version, temp_dir=temp_dir)
def test_mul_placeholder_const_broadcast_5D(self, params, ie_device, precision, ir_version, temp_dir, use_new_frontend):
self._test(*self.create_mul_placeholder_const_net(**params, ir_version=ir_version, use_new_frontend=use_new_frontend),
ie_device, precision, ir_version, temp_dir=temp_dir, use_new_frontend=use_new_frontend)