Layer test tflite (#17410)

* tfl argvalue test

* tfl add_n test

* tfl batch to space and space to batch

* tfl batch to space and space to batch

* tfl broadcast

* tfl avgpool

* tfl concat

* tfl conv2d and depthtospace

* tfl depthwise_conv2d

* tfl broadcast_args

* tfl fill

* tfl floordiv

* tfl fully_connected

* tfl fully_connected

* tfl gather

* tfl gather_nd

* tfl l2_normalization

* tfl matrix_diag

* tfl maxpool2d

* tfl mirror_pad

* tfl one_hot

* tfl pack

* tfl pad

* tfl range

* tfl relu

* tfl reshape

* tfl resize_bilinear

* tfl resize

* tfl reverse

* tfl tfft2d

* tfl scatter_nd

* tfl rfft2d fix

* tfl segment_sum

* tfl select

* tfl select_v2

* tfl slice

* tfl space_to_depth

* tfl split

* tfl split_v

* tfl strided_slice

* tfl tile

* tfl topk_v2

* tfl transpose

* tfl transpose_conv

* tfl fix conv tests

* tfl unique + refactoring

* tfl unpack

* refactoring

* tfl review - reformat params

* tfl review - fixes

* tfl review - fixes

* tfl review - xfails

* tfl review - remove redundant tickets

* tfl review - xfail for pad
This commit is contained in:
Ruslan Nugmanov 2023-05-15 13:03:09 +02:00 committed by GitHub
parent 8fed094168
commit aa932d341a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
47 changed files with 1712 additions and 81 deletions

View File

@ -5,7 +5,7 @@ os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
import tensorflow as tf import tensorflow as tf
from tensorflow.lite.tools import flatbuffer_utils as utils from tensorflow.lite.tools import flatbuffer_utils as utils
from common.layer_test_class import CommonLayerTest from common.layer_test_class import CommonLayerTest
from common.utils.tflite_utils import get_tflite_results, get_tensors_from_graph from common.utils.tflite_utils import get_tflite_results, get_tensors_from_graph, data_generators
class TFLiteLayerTest(CommonLayerTest): class TFLiteLayerTest(CommonLayerTest):
@ -14,6 +14,11 @@ class TFLiteLayerTest(CommonLayerTest):
outputs = None outputs = None
allowed_ops = None allowed_ops = None
def _prepare_input(self, inputs_dict, generator=None):
if generator is None:
return super()._prepare_input(inputs_dict)
return data_generators[generator](inputs_dict)
def make_model(self, params): def make_model(self, params):
raise RuntimeError("This is TensorFlow Lite base layer test class, " raise RuntimeError("This is TensorFlow Lite base layer test class, "
"please implement make_model function for the specific test") "please implement make_model function for the specific test")

View File

@ -1,7 +1,9 @@
import itertools
import os import os
import tensorflow as tf
import numpy as np import numpy as np
import tensorflow as tf
from common.utils.tf_utils import summarize_graph, transpose_nhwc_to_nchw from common.utils.tf_utils import summarize_graph, transpose_nhwc_to_nchw
@ -23,10 +25,17 @@ def make_boolean_array(inputs_dict):
return inputs_dict return inputs_dict
def make_int32_positive_array(inputs_dict):
for input in inputs_dict.keys():
inputs_dict[input] = np.random.randint(1, 10, inputs_dict[input]).astype(np.int32)
return inputs_dict
data_generators = { data_generators = {
'positive': make_positive_array, 'positive': make_positive_array,
'short_range': short_range, 'short_range': short_range,
'boolean': make_boolean_array, 'boolean': make_boolean_array,
'int32_positive': make_int32_positive_array,
} }
@ -41,7 +50,7 @@ additional_test_params = [
[ [
{'axis': None}, {'axis': None},
{'axis': -1} {'axis': -1}
], ],
[ [
{'activation': None}, {'activation': None},
{'activation': tf.nn.relu}, {'activation': tf.nn.relu},
@ -51,7 +60,7 @@ additional_test_params = [
# {'activation': tf.math.tanh}, # {'activation': tf.math.tanh},
# {'activation': lambda x, name: tf.identity(tf.experimental.numpy.signbit(x), name=name)}, # {'activation': lambda x, name: tf.identity(tf.experimental.numpy.signbit(x), name=name)},
{'activation': lambda x, name: tf.math.minimum(tf.math.maximum(-1., x), 1., name=name)} {'activation': lambda x, name: tf.math.minimum(tf.math.maximum(-1., x), 1., name=name)}
] ]
] ]
@ -119,3 +128,10 @@ def get_tensors_from_graph(graph, ops: list):
return tensors return tensors
def parametrize_tests(lhs, rhs):
test_data = list(itertools.product(lhs, rhs))
for i, (parameters, shapes) in enumerate(test_data):
parameters.update(shapes)
test_data[i] = parameters.copy()
return test_data

View File

@ -0,0 +1,46 @@
import pytest
import tensorflow as tf
from common.tflite_layer_test_class import TFLiteLayerTest
from common.utils.tflite_utils import parametrize_tests
num_inputs = [
{'num_inputs': 2},
{'num_inputs': 4},
{'num_inputs': 5},
]
test_params = [
{'shape': [2, 10, 10, 3]},
{'shape': [2, 10]}
]
test_data = parametrize_tests(num_inputs, test_params)
class TestTFLiteAddNLayerTest(TFLiteLayerTest):
inputs = []
outputs = ["AddN"]
allowed_ops = ['ADD_N']
def make_model(self, params):
assert len(set(params.keys()).intersection({'shape', 'num_inputs'})) == 2, \
'Unexpected parameters for test: ' + ','.join(params.keys())
self.inputs = []
tf.compat.v1.reset_default_graph()
with tf.compat.v1.Session() as sess:
inputs = []
for j in range(params['num_inputs']):
name = f"Input_{j}"
self.inputs.append(name)
placeholder = tf.compat.v1.placeholder(params.get('dtype', tf.float32), params['shape'],
name=name)
inputs.append(placeholder)
tf.math.add_n(inputs, name=self.outputs[0])
net = sess.graph_def
return net
@pytest.mark.parametrize("params", test_data)
@pytest.mark.nightly
def test_add_n(self, params, ie_device, precision, temp_dir):
self._test(ie_device, precision, temp_dir, params)

View File

@ -0,0 +1,41 @@
import pytest
import tensorflow as tf
from common.tflite_layer_test_class import TFLiteLayerTest
from common.utils.tflite_utils import additional_test_params
from common.utils.tflite_utils import parametrize_tests
test_ops = [
{'op_name': 'ARG_MAX', 'op_func': tf.math.argmax},
{'op_name': 'ARG_MIN', 'op_func': tf.math.argmin},
]
test_params = [
{'shape': [2, 10, 10, 3]},
{'shape': [2, 10]}
]
test_data = parametrize_tests(test_ops, test_params)
test_data = parametrize_tests(test_data, additional_test_params[0])
class TestTFLiteArgValueLayerTest(TFLiteLayerTest):
inputs = ["Input"]
outputs = ["ArgValue"]
def make_model(self, params):
assert len(set(params.keys()).intersection({'op_name', 'op_func', 'shape', 'axis'})) == 4, \
'Unexpected parameters for test: ' + ','.join(params.keys())
self.allowed_ops = [params['op_name']]
tf.compat.v1.reset_default_graph()
with tf.compat.v1.Session() as sess:
place_holder = tf.compat.v1.placeholder(params.get('dtype', tf.float32), params['shape'],
name=self.inputs[0])
params['op_func'](place_holder, axis=params['axis'], name=self.outputs[0])
net = sess.graph_def
return net
@pytest.mark.parametrize("params", test_data)
@pytest.mark.nightly
def test_arg_value(self, params, ie_device, precision, temp_dir):
self._test(ie_device, precision, temp_dir, params)

View File

@ -0,0 +1,32 @@
import pytest
import tensorflow as tf
from common.tflite_layer_test_class import TFLiteLayerTest
test_params = [
{'shape': [8, 10, 10, 3], 'block_shape': [2, 2], 'crops': [[0, 2], [0, 0]]},
{'shape': [24, 10, 10, 1], 'block_shape': [2, 12], 'crops': [[2, 0], [0, 2]]}
]
class TestTFLiteBatchToSpaceNDLayerTest(TFLiteLayerTest):
inputs = ["Input"]
outputs = ["BatchToSpaceND"]
allowed_ops = ['BATCH_TO_SPACE_ND']
def make_model(self, params):
assert len(set(params.keys()).intersection({'shape', 'block_shape', 'crops'})) == 3, \
'Unexpected parameters for test: ' + ','.join(params.keys())
tf.compat.v1.reset_default_graph()
with tf.compat.v1.Session() as sess:
place_holder = tf.compat.v1.placeholder(params.get('dtype', tf.float32), params['shape'],
name=self.inputs[0])
tf.batch_to_space(place_holder, params['block_shape'], params['crops'],
name=self.outputs[0])
net = sess.graph_def
return net
@pytest.mark.parametrize("params", test_params)
@pytest.mark.nightly
def test_batch_to_space_nd(self, params, ie_device, precision, temp_dir):
self._test(ie_device, precision, temp_dir, params)

View File

@ -1,14 +1,13 @@
import itertools
import pytest import pytest
import tensorflow as tf import tensorflow as tf
from common.tflite_layer_test_class import TFLiteLayerTest from common.tflite_layer_test_class import TFLiteLayerTest
from tensorflow_lite_tests.test_tfl_Unary import data_generators from common.utils.tflite_utils import parametrize_tests
test_ops = [ test_ops = [
{'op_name': 'EQUAL', 'op_func': tf.math.equal}, {'op_name': 'EQUAL', 'op_func': tf.math.equal},
{'op_name': 'FLOOR_MOD', 'op_func': tf.math.floormod}, {'op_name': 'FLOOR_MOD', 'op_func': tf.math.floormod, 'kwargs_to_prepare_input': 'positive'},
{'op_name': 'FLOOR_DIV', 'op_func': tf.math.floordiv, 'kwargs_to_prepare_input': 'positive'},
{'op_name': 'GREATER', 'op_func': tf.math.greater}, {'op_name': 'GREATER', 'op_func': tf.math.greater},
{'op_name': 'GREATER_EQUAL', 'op_func': tf.math.greater_equal}, {'op_name': 'GREATER_EQUAL', 'op_func': tf.math.greater_equal},
{'op_name': 'LESS', 'op_func': tf.math.less}, {'op_name': 'LESS', 'op_func': tf.math.less},
@ -27,21 +26,13 @@ test_params = [
{'shape': [2, 10]} {'shape': [2, 10]}
] ]
test_data = list(itertools.product(test_ops, test_params)) test_data = parametrize_tests(test_ops, test_params)
for i, (parameters, shapes) in enumerate(test_data):
parameters.update(shapes)
test_data[i] = parameters.copy()
class TestTFLiteBinaryLayerTest(TFLiteLayerTest): class TestTFLiteBinaryLayerTest(TFLiteLayerTest):
inputs = ["Input_0", "Input_1"] inputs = ["Input_0", "Input_1"]
outputs = ["BinaryOperation"] outputs = ["BinaryOperation"]
def _prepare_input(self, inputs_dict, generator=None):
if generator is None:
return super()._prepare_input(inputs_dict)
return data_generators[generator](inputs_dict)
def make_model(self, params): def make_model(self, params):
assert len(set(params.keys()).intersection({'op_name', 'op_func', 'shape'})) == 3, \ assert len(set(params.keys()).intersection({'op_name', 'op_func', 'shape'})) == 3, \
'Unexpected parameters for test: ' + ','.join(params.keys()) 'Unexpected parameters for test: ' + ','.join(params.keys())
@ -49,10 +40,10 @@ class TestTFLiteBinaryLayerTest(TFLiteLayerTest):
tf.compat.v1.reset_default_graph() tf.compat.v1.reset_default_graph()
with tf.compat.v1.Session() as sess: with tf.compat.v1.Session() as sess:
place_holder0 = tf.compat.v1.placeholder(params.get('dtype', tf.float32), params['shape'], place_holder0 = tf.compat.v1.placeholder(params.get('dtype', tf.float32), params['shape'],
name=TestTFLiteBinaryLayerTest.inputs[0]) name=self.inputs[0])
place_holder1 = tf.compat.v1.placeholder(params.get('dtype', tf.float32), params['shape'], place_holder1 = tf.compat.v1.placeholder(params.get('dtype', tf.float32), params['shape'],
name=TestTFLiteBinaryLayerTest.inputs[1]) name=self.inputs[1])
params['op_func'](place_holder0, place_holder1, name=TestTFLiteBinaryLayerTest.outputs[0]) params['op_func'](place_holder0, place_holder1, name=self.outputs[0])
net = sess.graph_def net = sess.graph_def
return net return net

View File

@ -1,10 +1,9 @@
import itertools
import tensorflow as tf
import pytest import pytest
import tensorflow as tf
from common.tflite_layer_test_class import TFLiteLayerTest from common.tflite_layer_test_class import TFLiteLayerTest
from common.utils.tflite_utils import data_generators, additional_test_params, activation_helper from common.utils.tflite_utils import additional_test_params, activation_helper
from common.utils.tflite_utils import parametrize_tests
test_ops = [ test_ops = [
{'op_name': 'ADD', 'op_func': tf.math.add}, {'op_name': 'ADD', 'op_func': tf.math.add},
@ -18,41 +17,26 @@ test_params = [
{'shape': [2, 10]} {'shape': [2, 10]}
] ]
test_data = parametrize_tests(test_ops, test_params)
test_data = list(itertools.product(test_ops, test_params)) test_data = parametrize_tests(test_data, additional_test_params[1])
for i, (parameters, shapes) in enumerate(test_data):
parameters.update(shapes)
test_data[i] = parameters.copy()
test_data = list(itertools.product(test_data, additional_test_params[1]))
for i, (parameters, additional_test_params[1]) in enumerate(test_data):
parameters.update(additional_test_params[1])
test_data[i] = parameters.copy()
class TestTFLiteBinaryWithActivationLayerTest(TFLiteLayerTest): class TestTFLiteBinaryWithActivationLayerTest(TFLiteLayerTest):
inputs = ["Input_0", "Input_1"] inputs = ["Input_0", "Input_1"]
outputs = ["BinaryOperation"] outputs = ["BinaryOperation"]
def _prepare_input(self, inputs_dict, generator=None):
if generator is None:
return super()._prepare_input(inputs_dict)
return data_generators[generator](inputs_dict)
def make_model(self, params): def make_model(self, params):
assert len(set(params.keys()).intersection({'op_name', 'op_func', 'shape', 'activation'})) == 4, \ assert len(set(params.keys()).intersection({'op_name', 'op_func', 'shape', 'activation'})) == 4, \
'Unexpected parameters for test: ' + ','.join(params.keys()) 'Unexpected parameters for test: ' + ','.join(params.keys())
self.allowed_ops = [params['op_name']] self.allowed_ops = [params['op_name']]
tf.compat.v1.reset_default_graph() tf.compat.v1.reset_default_graph()
with tf.compat.v1.Session() as sess: with tf.compat.v1.Session() as sess:
in0 = tf.compat.v1.placeholder(params.get('dtype', tf.float32), params['shape'], in0 = tf.compat.v1.placeholder(params.get('dtype', tf.float32), params['shape'], name=self.inputs[0])
name=TestTFLiteBinaryWithActivationLayerTest.inputs[0]) in1 = tf.compat.v1.placeholder(params.get('dtype', tf.float32), params['shape'], name=self.inputs[1])
in1 = tf.compat.v1.placeholder(params.get('dtype', tf.float32), params['shape'], bin_op_name = self.outputs[0] if not params['activation'] else \
name=TestTFLiteBinaryWithActivationLayerTest.inputs[1]) self.outputs[0] + "/op"
bin_op_name = TestTFLiteBinaryWithActivationLayerTest.outputs[0] if not params['activation'] else \
TestTFLiteBinaryWithActivationLayerTest.outputs[0] + "/op"
op = params['op_func'](in0, in1, name=bin_op_name) op = params['op_func'](in0, in1, name=bin_op_name)
op = activation_helper(op, params['activation'], TestTFLiteBinaryWithActivationLayerTest.outputs[0]) op = activation_helper(op, params['activation'], self.outputs[0])
net = sess.graph_def net = sess.graph_def
return net return net

View File

@ -0,0 +1,42 @@
import numpy as np
import pytest
import tensorflow as tf
from common.tflite_layer_test_class import TFLiteLayerTest
test_params = [
{'shape': [1, 5], 'broadcast_shape': [5, 5]},
{'shape': [1], 'broadcast_shape': [7]}
]
class TestTFLiteBroadcastArgsLayerTest(TFLiteLayerTest):
inputs = ["Input", "Input1"]
outputs = ["BroadcastArgsOP"]
allowed_ops = ['BROADCAST_ARGS']
def _prepare_input(self, inputs_dict, generator=None):
inputs_dict["Input"] = np.array(self.shape).astype(np.int32)
inputs_dict["Input1"] = np.array(self.broadcast_shape).astype(np.int32)
return inputs_dict
def make_model(self, params):
assert len(set(params.keys()).intersection({'shape', 'broadcast_shape'})) == 2, \
'Unexpected parameters for test: ' + ','.join(params.keys())
tf.compat.v1.reset_default_graph()
self.shape = params['shape']
self.broadcast_shape = params['broadcast_shape']
with tf.compat.v1.Session() as sess:
s0 = tf.compat.v1.placeholder(params.get('dtype', tf.int32), [len(self.shape)],
name=self.inputs[0])
s1 = tf.compat.v1.placeholder(params.get('dtype', tf.int32), [len(self.shape)],
name=self.inputs[1])
tf.raw_ops.BroadcastArgs(s0=s0, s1=s1, name=self.outputs[0])
net = sess.graph_def
return net
@pytest.mark.parametrize("params", test_params)
@pytest.mark.nightly
def test_broadcast_args(self, params, ie_device, precision, temp_dir):
self._test(ie_device, precision, temp_dir, params)

View File

@ -0,0 +1,33 @@
import pytest
import tensorflow as tf
from common.tflite_layer_test_class import TFLiteLayerTest
test_params = [
{'shape': [1, 1, 1, 1, 40], 'broadcast_shape': [1, 1, 56, 56, 40]},
{'shape': [1, 1, 1, 1, 10], 'broadcast_shape': [1, 1, 10, 10, 10]}
]
class TestTFLiteBroadcastToLayerTest(TFLiteLayerTest):
inputs = ["Input"]
outputs = ["BroadcastToOP"]
allowed_ops = ['BROADCAST_TO']
def make_model(self, params):
assert len(set(params.keys()).intersection({'shape', 'broadcast_shape'})) == 2, \
'Unexpected parameters for test: ' + ','.join(params.keys())
tf.compat.v1.reset_default_graph()
with tf.compat.v1.Session() as sess:
place_holder = tf.compat.v1.placeholder(params.get('dtype', tf.float32), params['shape'],
name=self.inputs[0])
shape_of = tf.reshape(place_holder, params['shape'])
tf.broadcast_to(input=shape_of, shape=params['broadcast_shape'],
name=self.outputs[0])
net = sess.graph_def
return net
@pytest.mark.parametrize("params", test_params)
@pytest.mark.nightly
def test_broadcast_to(self, params, ie_device, precision, temp_dir):
self._test(ie_device, precision, temp_dir, params)

View File

@ -0,0 +1,39 @@
import pytest
import tensorflow as tf
from common.tflite_layer_test_class import TFLiteLayerTest
test_params = [
{'shapes': [[1, 3], [1, 7]], 'axis': -1},
{'shapes': [[1, 3, 10], [1, 3, 56], [1, 3, 2]], 'axis': -1},
{'shapes': [[1, 3, 10, 17], [1, 3, 10, 1], [1, 3, 10, 5], [1, 3, 10, 3]], 'axis': -1},
{'shapes': [[2, 7], [2, 8]], 'axis': 1},
{'shapes': [[1, 3, 10], [1, 2, 10], [1, 5, 10]], 'axis': 1},
{'shapes': [[1, 3, 10, 17], [1, 10, 10, 17], [1, 12, 10, 17], [1, 1, 10, 17]], 'axis': 1},
]
class TestTFLiteConcatTest(TFLiteLayerTest):
outputs = ['Concat']
allowed_ops = ['CONCATENATION']
def make_model(self, params):
assert len(set(params.keys()).intersection({'shapes', 'axis'})) == 2, \
'Unexpected parameters for test: ' + ','.join(params.keys())
tf.compat.v1.reset_default_graph()
with tf.compat.v1.Session() as sess:
placeholders = []
self.inputs = []
for j, placeholder_shape in enumerate(params['shapes']):
concat_input = f'concat_input_{j}'
self.inputs.append(concat_input)
placeholders.append(tf.compat.v1.placeholder(params.get('dtype', tf.float32), placeholder_shape,
name=concat_input))
tf.concat(placeholders, params['axis'], name=self.outputs[0])
net = sess.graph_def
return net
@pytest.mark.parametrize("params", test_params)
@pytest.mark.nightly
def test_concat(self, params, ie_device, precision, temp_dir):
self._test(ie_device, precision, temp_dir, params)

View File

@ -0,0 +1,43 @@
import numpy as np
import pytest
import tensorflow as tf
from common.tflite_layer_test_class import TFLiteLayerTest
np.random.seed(42)
test_params = [
{'shape': [1, 22, 22, 8], 'ksize': [32, 3, 4, 4], 'strides': 2, 'padding': 'SAME', 'data_format': 'NHWC',
'dilations': [1, 1, 1, 1]},
{'shape': [1, 22, 22, 9], 'ksize': [32, 3, 3, 3], 'strides': (2, 1), 'padding': 'SAME', 'data_format': 'NHWC',
'dilations': [1, 2, 2, 1]},
{'shape': [1, 22, 22, 8], 'ksize': [1, 3, 4, 4], 'strides': 2, 'padding': 'VALID', 'data_format': 'NHWC',
'dilations': [1, 1, 1, 1]},
{'shape': [1, 22, 22, 3], 'ksize': [1, 3, 3, 3], 'strides': (3, 4), 'padding': 'VALID', 'data_format': 'NHWC',
'dilations': [1, 2, 2, 1]},
]
class TestTFLiteConv2DLayerTest(TFLiteLayerTest):
inputs = ["Input"]
outputs = ["Conv2D"]
allowed_ops = ['CONV_2D']
def make_model(self, params):
assert len(set(params.keys()).intersection({'shape', 'ksize', 'strides',
'padding', 'data_format', 'dilations'})) == 6, \
'Unexpected parameters for test: ' + ','.join(params.keys())
tf.compat.v1.reset_default_graph()
with tf.compat.v1.Session() as sess:
weights = tf.constant(np.random.randint(-1, 1, params['ksize']), dtype=tf.float32)
place_holder = tf.compat.v1.placeholder(params.get('dtype', tf.float32), params['shape'],
name=self.inputs[0])
tf.nn.conv2d(place_holder, weights, params['strides'], params['padding'], params['data_format'],
params['dilations'], name=self.outputs[0])
net = sess.graph_def
return net
@pytest.mark.parametrize("params", test_params)
@pytest.mark.nightly
def test_conv2d(self, params, ie_device, precision, temp_dir):
self._test(ie_device, precision, temp_dir, params)

View File

@ -0,0 +1,31 @@
import pytest
import tensorflow as tf
from common.tflite_layer_test_class import TFLiteLayerTest
test_params = [
{'shape': [8, 10, 10, 16], 'block_size': 2, 'data_format': 'NHWC'},
{'shape': [24, 10, 10, 50], 'block_size': 5, 'data_format': 'NHWC'},
]
class TestTFLiteDepthToSpaceLayerTest(TFLiteLayerTest):
inputs = ["Input"]
outputs = ["DepthToSpace"]
allowed_ops = ['DEPTH_TO_SPACE']
def make_model(self, params):
assert len(set(params.keys()).intersection({'shape', 'block_size', 'data_format'})) == 3, \
'Unexpected parameters for test: ' + ','.join(params.keys())
tf.compat.v1.reset_default_graph()
with tf.compat.v1.Session() as sess:
place_holder = tf.compat.v1.placeholder(params.get('dtype', tf.float32), params['shape'],
name=self.inputs[0])
tf.nn.depth_to_space(place_holder, params['block_size'], params['data_format'], name=self.outputs[0])
net = sess.graph_def
return net
@pytest.mark.parametrize("params", test_params)
@pytest.mark.nightly
def test_depth_to_space(self, params, ie_device, precision, temp_dir):
self._test(ie_device, precision, temp_dir, params)

View File

@ -0,0 +1,39 @@
import numpy as np
import pytest
import tensorflow as tf
from common.tflite_layer_test_class import TFLiteLayerTest
np.random.seed(42)
test_params = [
{'shape': [1, 22, 22, 8], 'ksize': [3, 3, 8, 2], 'strides': [1, 2, 2, 1], 'padding': 'SAME', 'data_format': 'NHWC',
'dilations': [1, 1]},
{'shape': [1, 22, 22, 9], 'ksize': [3, 3, 9, 1], 'strides': [1, 1, 1, 1], 'padding': 'SAME', 'data_format': 'NHWC',
'dilations': [1, 1]},
]
class TestTFLiteDepthwiseConv2DLayerTest(TFLiteLayerTest):
inputs = ["Input"]
outputs = ["DepthwiseConv2D"]
allowed_ops = ['DEPTHWISE_CONV_2D']
def make_model(self, params):
assert len(set(params.keys()).intersection({'shape', 'ksize', 'strides',
'padding', 'data_format', 'dilations'})) == 6, \
'Unexpected parameters for test: ' + ','.join(params.keys())
tf.compat.v1.reset_default_graph()
with tf.compat.v1.Session() as sess:
weights = tf.constant(np.random.randint(-1, 1, params['ksize']), dtype=tf.float32)
place_holder = tf.compat.v1.placeholder(params.get('dtype', tf.float32), params['shape'],
name=self.inputs[0])
tf.nn.depthwise_conv2d(place_holder, weights, params['strides'], params['padding'], params['data_format'],
params['dilations'], name=self.outputs[0])
net = sess.graph_def
return net
@pytest.mark.parametrize("params", test_params)
@pytest.mark.nightly
def test_depthwise_conv2d(self, params, ie_device, precision, temp_dir):
self._test(ie_device, precision, temp_dir, params)

View File

@ -0,0 +1,32 @@
import pytest
import tensorflow as tf
from common.tflite_layer_test_class import TFLiteLayerTest
test_params = [
{'shape': [2, 3], 'value': 1, 'kwargs_to_prepare_input': 'int32_positive'},
{'shape': [2, 3, 3, 4], 'value': -1, 'kwargs_to_prepare_input': 'int32_positive'},
{'shape': [1], 'value': 0, 'kwargs_to_prepare_input': 'int32_positive'}
]
class TestTFLiteBroadcastToLayerTest(TFLiteLayerTest):
inputs = ["Input"]
outputs = ["Fill"]
allowed_ops = ['FILL']
def make_model(self, params):
assert len(set(params.keys()).intersection({'shape', 'value'})) == 2, \
'Unexpected parameters for test: ' + ','.join(params.keys())
tf.compat.v1.reset_default_graph()
with tf.compat.v1.Session() as sess:
placeholder = tf.compat.v1.placeholder(params.get('dtype', tf.int32), [len(params['shape'])],
name=self.inputs[0])
tf.fill(placeholder, params['value'], name=self.outputs[0])
net = sess.graph_def
return net
@pytest.mark.parametrize("params", test_params)
@pytest.mark.nightly
def test_fill(self, params, ie_device, precision, temp_dir):
self._test(ie_device, precision, temp_dir, params)

View File

@ -0,0 +1,35 @@
import pytest
import tensorflow as tf
from common.tflite_layer_test_class import TFLiteLayerTest
test_params = [
{'shape_x': [40, 37], 'shape_y': [37, 37], 'transpose_a': False, 'transpose_b': True},
{'shape_x': [5, 5], 'shape_y': [4, 5], 'transpose_a': False, 'transpose_b': True},
{'shape_x': [1, 5, 5], 'shape_y': [4, 5], 'transpose_a': False, 'transpose_b': True},
]
class TestTFLiteFullyConnectedLayerTest(TFLiteLayerTest):
inputs = ["Input_x", "Input_y"]
outputs = ["FullyConnected"]
allowed_ops = ['FULLY_CONNECTED']
def make_model(self, params):
assert len(set(params.keys()).intersection({'shape_x', 'shape_y',
'transpose_a', 'transpose_b'})) == 4, \
'Unexpected parameters for test: ' + ','.join(params.keys())
tf.compat.v1.reset_default_graph()
with tf.compat.v1.Session() as sess:
x = tf.compat.v1.placeholder(params.get('dtype', tf.float32), params['shape_x'], name=self.inputs[0])
y = tf.compat.v1.placeholder(params.get('dtype', tf.float32), params['shape_y'], name=self.inputs[1])
tf.matmul(x, y, transpose_a=params['transpose_a'], transpose_b=params['transpose_b'],
name=self.outputs[0])
net = sess.graph_def
return net
@pytest.mark.parametrize("params", test_params)
@pytest.mark.nightly
def test_fully_connected(self, params, ie_device, precision, temp_dir):
self._test(ie_device, precision, temp_dir, params)

View File

@ -0,0 +1,38 @@
import numpy as np
import pytest
import tensorflow as tf
from common.tflite_layer_test_class import TFLiteLayerTest
np.random.seed(42)
test_params = [
{'shape': [1, 10], 'indices_shape': [1, 5]},
{'shape': [2, 3, 5, 5], 'indices_shape': [4, 5]},
{'shape': [1, 5, 5], 'indices_shape': [2, 4, 5]},
{'shape': [1, 5, 5], 'indices_shape': [2, 4, 5, 6]},
]
class TestTFLiteGatherLayerTest(TFLiteLayerTest):
inputs = ["Input_x"]
outputs = ["Gather"]
allowed_ops = ['GATHER']
def make_model(self, params):
assert len(set(params.keys()).intersection({'shape', 'indices_shape', })) == 2, \
'Unexpected parameters for test: ' + ','.join(params.keys())
tf.compat.v1.reset_default_graph()
with tf.compat.v1.Session() as sess:
placeholder = tf.compat.v1.placeholder(params.get('dtype', tf.float32),
params['shape'], name=self.inputs[0])
constant = tf.constant(np.random.randint(0, 1, size=params['indices_shape']))
tf.gather(placeholder, constant, name=self.outputs[0])
net = sess.graph_def
return net
@pytest.mark.parametrize("params", test_params)
@pytest.mark.nightly
def test_gather(self, params, ie_device, precision, temp_dir):
self._test(ie_device, precision, temp_dir, params)

View File

@ -0,0 +1,50 @@
import numpy as np
import pytest
import tensorflow as tf
from common.tflite_layer_test_class import TFLiteLayerTest
test_params = [
{'shape': [5, 1], 'indices_shape': [1, 1], 'batch_dims': 0},
{'shape': [5, 5], 'indices_shape': [2, 1], 'batch_dims': 0},
{'shape': [5, 5], 'indices_shape': [2, 2], 'batch_dims': 0},
#
{'shape': [3, 5, 10], 'indices_shape': [3, 2], 'batch_dims': 1},
{'shape': [5, 5, 10], 'indices_shape': [2, 3], 'batch_dims': 0},
{'shape': [4, 5, 10], 'indices_shape': [2, 10, 1], 'batch_dims': 2},
]
class TestTFLiteGatherLayerTest(TFLiteLayerTest):
inputs = ["Input_x"]
outputs = ["GatherND"]
allowed_ops = ['GATHER_ND']
def make_model(self, params):
assert len(set(params.keys()).intersection({'shape', 'indices_shape', 'batch_dims'})) == 3, \
'Unexpected parameters for test: ' + ','.join(params.keys())
tf.compat.v1.reset_default_graph()
self.outputs = ["GatherND"]
self.allowed_ops = ["GATHER_ND"]
if params['batch_dims'] > 0:
output_name = "GatherND"
self.outputs = [f"GatherND/Reshape_{params['batch_dims'] + 2}"]
if params['batch_dims'] > 1:
self.allowed_ops.append('RESHAPE')
else:
output_name = self.outputs[0]
with tf.compat.v1.Session() as sess:
placeholder = tf.compat.v1.placeholder(params.get('dtype', tf.float32),
params['shape'], name=self.inputs[0])
constant = tf.constant(np.random.randint(0, params['shape'][0] - 1, params['indices_shape']))
tf.gather_nd(placeholder, constant, name=output_name, batch_dims=params['batch_dims'])
net = sess.graph_def
return net
@pytest.mark.parametrize("params", test_params)
@pytest.mark.nightly
def test_gather_nd(self, params, ie_device, precision, temp_dir):
self._test(ie_device, precision, temp_dir, params)

View File

@ -0,0 +1,37 @@
import pytest
import tensorflow as tf
from common.tflite_layer_test_class import TFLiteLayerTest
from common.utils.tflite_utils import additional_test_params
from common.utils.tflite_utils import parametrize_tests
test_params = [
{'shape': [1]},
{'shape': [1, 22]},
{'shape': [1, 1, 8]},
{'shape': [1, 22, 22, 8]},
]
test_data = parametrize_tests(test_params, additional_test_params[0])
class TestTFLiteExpandDimsLayerTest(TFLiteLayerTest):
inputs = ["Input"]
outputs = ["L2_Normalization"]
allowed_ops = ['L2_NORMALIZATION']
def make_model(self, params):
assert len(set(params.keys()).intersection({'shape'})) == 1, \
'Unexpected parameters for test: ' + ','.join(params.keys())
tf.compat.v1.reset_default_graph()
with tf.compat.v1.Session() as sess:
place_holder = tf.compat.v1.placeholder(params.get('dtype', tf.float32), params['shape'],
name=self.inputs[0])
tf.math.l2_normalize(place_holder, axis=params['axis'], name=self.outputs[0])
net = sess.graph_def
return net
@pytest.mark.parametrize("params", test_data)
@pytest.mark.nightly
def test_l2_normalization(self, params, ie_device, precision, temp_dir):
self._test(ie_device, precision, temp_dir, params)

View File

@ -0,0 +1,34 @@
import pytest
import tensorflow as tf
from common.tflite_layer_test_class import TFLiteLayerTest
test_params = [
{'shape': [3]},
{'shape': [1, 22]},
{'shape': [1, 1, 8]},
{'shape': [1, 22, 22, 8]},
{'shape': [1, 22, 22, 8, 3]},
]
class TestTFLiteMatrixDiagLayerTest(TFLiteLayerTest):
inputs = ["Input"]
outputs = ["MatrixDiag"]
allowed_ops = ['MATRIX_DIAG']
def make_model(self, params):
assert len(set(params.keys()).intersection({'shape'})) == 1, \
'Unexpected parameters for test: ' + ','.join(params.keys())
tf.compat.v1.reset_default_graph()
with tf.compat.v1.Session() as sess:
place_holder = tf.compat.v1.placeholder(params.get('dtype', tf.float32), params['shape'],
name=self.inputs[0])
tf.linalg.diag(place_holder, name=self.outputs[0])
net = sess.graph_def
return net
@pytest.mark.parametrize("params", test_params)
@pytest.mark.nightly
def test_matrix_diag(self, params, ie_device, precision, temp_dir):
self._test(ie_device, precision, temp_dir, params)

View File

@ -0,0 +1,39 @@
import numpy as np
import pytest
import tensorflow as tf
from common.tflite_layer_test_class import TFLiteLayerTest
test_params = [
{'shape': [2, 3], 'padding_matrix': [[1, 1], [2, 1]], 'mode': 'REFLECT'},
{'shape': [2, 3], 'padding_matrix': [[1, 1], [1, 1]], 'mode': 'REFLECT'},
{'shape': [2, 3], 'padding_matrix': [[1, 1], [2, 1]], 'mode': 'SYMMETRIC'},
{'shape': [3], 'padding_matrix': [[0, 2]], 'mode': 'SYMMETRIC'},
{'shape': [3], 'padding_matrix': [[0, 2]], 'mode': 'REFLECT'},
{'shape': [3, 2, 4, 5], 'padding_matrix': [[1, 1], [2, 2], [1, 1], [1, 1]], 'mode': 'SYMMETRIC'},
]
class TestTFLiteMirrorPadLayerTest(TFLiteLayerTest):
inputs = ["Input"]
outputs = ["MirrorPad"]
allowed_ops = ['MIRROR_PAD']
def make_model(self, params):
assert len(set(params.keys()).intersection({'shape', 'padding_matrix', 'mode'})) == 3, \
'Unexpected parameters for test: ' + ','.join(params.keys())
tf.compat.v1.reset_default_graph()
with tf.compat.v1.Session() as sess:
place_holder = tf.compat.v1.placeholder(params.get('dtype', tf.float32), params['shape'],
name=self.inputs[0])
padding_matrix = tf.constant(np.array(params["padding_matrix"]))
tf.pad(tensor=place_holder, paddings=padding_matrix, mode=params['mode'], name=self.outputs[0])
net = sess.graph_def
return net
@pytest.mark.parametrize("params", test_params)
@pytest.mark.nightly
def test_mirror_pad(self, params, ie_device, precision, temp_dir):
self._test(ie_device, precision, temp_dir, params)

View File

@ -0,0 +1,38 @@
import pytest
import tensorflow as tf
from common.tflite_layer_test_class import TFLiteLayerTest
test_params = [
{'shape': [3], 'axis': 0, 'kwargs_to_prepare_input': 'int32_positive'},
{'shape': [4, 4], 'axis': 1, 'kwargs_to_prepare_input': 'int32_positive'},
{'shape': [1, 5, 3], 'axis': 0, 'kwargs_to_prepare_input': 'int32_positive'},
{'shape': [5, 1, 2, 4], 'axis': 1, 'kwargs_to_prepare_input': 'int32_positive'},
]
class TestTFLiteOneHotLayerTest(TFLiteLayerTest):
inputs = ['Indices', 'Depth', 'OnValue', 'OffValue']
outputs = ["OneHot"]
allowed_ops = ['ONE_HOT']
def make_model(self, params):
assert len(set(params.keys()).intersection({'axis'})) == 1, \
'Unexpected parameters for test: ' + ','.join(params.keys())
tf.compat.v1.reset_default_graph()
with tf.compat.v1.Session() as sess:
indices = tf.compat.v1.placeholder(dtype=tf.int32, name=self.inputs[0], shape=params["shape"])
depth = tf.compat.v1.placeholder(dtype=tf.int32, name=self.inputs[1], shape=())
on_value = tf.compat.v1.placeholder(dtype=tf.int32, name=self.inputs[2], shape=())
off_value = tf.compat.v1.placeholder(dtype=tf.int32, name=self.inputs[3], shape=())
tf.one_hot(indices=indices, depth=depth, on_value=on_value, off_value=off_value,
axis=params['axis'], name=self.outputs[0])
net = sess.graph_def
return net
@pytest.mark.parametrize("params", test_params)
@pytest.mark.nightly
def test_one_hot(self, params, ie_device, precision, temp_dir):
self._test(ie_device, precision, temp_dir, params)

View File

@ -0,0 +1,40 @@
import pytest
import tensorflow as tf
from common.tflite_layer_test_class import TFLiteLayerTest
test_params = [
{'shape': [3], 'num_tensors': 2},
{'shape': [1, 22], 'num_tensors': 10},
{'shape': [1, 1, 8], 'num_tensors': 5},
{'shape': [1, 22, 22, 8], 'num_tensors': 5},
{'shape': [1, 22, 22, 8, 3], 'num_tensors': 7},
]
class TestTFLitePackLayerTest(TFLiteLayerTest):
inputs = []
outputs = ["Pack"]
allowed_ops = ['PACK']
def make_model(self, params):
assert len(set(params.keys()).intersection({'shape', 'num_tensors'})) == 2, \
'Unexpected parameters for test: ' + ','.join(params.keys())
tf.compat.v1.reset_default_graph()
with tf.compat.v1.Session() as sess:
tensors = []
self.inputs = []
for j in range(params['num_tensors']):
name = f'Input_{j}'
self.inputs.append(name)
place_holder = tf.compat.v1.placeholder(params.get('dtype', tf.float32), params['shape'],
name=name)
tensors.append(place_holder)
tf.stack(tensors, name=self.outputs[0])
net = sess.graph_def
return net
@pytest.mark.parametrize("params", test_params)
@pytest.mark.nightly
def test_pack(self, params, ie_device, precision, temp_dir):
self._test(ie_device, precision, temp_dir, params)

View File

@ -0,0 +1,43 @@
import pytest
import tensorflow as tf
from common.tflite_layer_test_class import TFLiteLayerTest
test_params = [
{'shape': [1, 1, 2, 1, 1], 'paddings': [[0, 0], [0, 1], [2, 3], [0, 0], [1, 0]]},
{'shape': [2, 1, 1, 1, 1], 'paddings': [[0, 1], [0, 0], [0, 0], [2, 3], [1, 0]]},
{'shape': [1, 1, 2, 1], 'paddings': [[0, 0], [0, 1], [2, 3], [0, 0]]},
{'shape': [1, 1, 2, 1], 'paddings': [[0, 0], [0, 1], [2, 3], [0, 0]]},
{'shape': [1, 2], 'paddings': [[0, 1], [2, 1]]},
{'shape': [1, 2], 'paddings': [[2, 3], [0, 1]]},
{'shape': [1], 'paddings': [[1, 2]]},
]
class TestTFLitePadLayerTest(TFLiteLayerTest):
inputs = ["Input", 'Paddings']
outputs = ["Pad"]
allowed_ops = ['PAD']
def make_model(self, params):
assert len(set(params.keys()).intersection({'shape', 'paddings'})) == 2, \
'Unexpected parameters for test: ' + ','.join(params.keys())
tf.compat.v1.reset_default_graph()
with tf.compat.v1.Session() as sess:
place_holder = tf.compat.v1.placeholder(params.get('dtype', tf.float32), params['shape'],
name=self.inputs[0])
shape = [len(params["paddings"]), 2]
paddings = tf.compat.v1.placeholder(dtype=tf.int32, name=self.inputs[1], shape=shape)
tf.pad(tensor=place_holder, paddings=paddings, name=self.outputs[0])
net = sess.graph_def
return net
@pytest.mark.parametrize("params", test_params)
@pytest.mark.nightly
def test_pad(self, params, ie_device, precision, temp_dir):
pytest.xfail("CVS-110828")
self._test(ie_device, precision, temp_dir, params)

View File

@ -0,0 +1,44 @@
import pytest
import tensorflow as tf
from common.tflite_layer_test_class import TFLiteLayerTest
from common.utils.tflite_utils import parametrize_tests
test_ops = [
{'op_name': 'AVERAGE_POOL_2D', 'op_func': tf.nn.avg_pool2d},
{'op_name': 'MAX_POOL_2D', 'op_func': tf.nn.max_pool2d},
]
test_params = [
# TFLite doesn't support avgpool with 'NCHW' format
{'shape': [1, 22, 22, 8], 'ksize': [3, 3], 'strides': 2, 'padding': 'SAME', 'data_format': 'NHWC'},
{'shape': [1, 22, 22, 8], 'ksize': [3, 3], 'strides': (2, 1), 'padding': 'SAME', 'data_format': 'NHWC'},
{'shape': [1, 22, 22, 8], 'ksize': [3, 3], 'strides': 2, 'padding': 'VALID', 'data_format': 'NHWC'},
{'shape': [1, 22, 22, 8], 'ksize': [3, 3], 'strides': (3, 4), 'padding': 'VALID', 'data_format': 'NHWC'},
]
test_data = parametrize_tests(test_ops, test_params)
class TestTFLitePoolLayerTest(TFLiteLayerTest):
inputs = ["Input"]
outputs = ["Pool"]
def make_model(self, params):
assert len(set(params.keys()).intersection({'op_name', 'op_func', 'shape', 'ksize', 'strides',
'padding', 'data_format'})) == 7, \
'Unexpected parameters for test: ' + ','.join(params.keys())
self.allowed_ops = [params['op_name']]
tf.compat.v1.reset_default_graph()
with tf.compat.v1.Session() as sess:
place_holder = tf.compat.v1.placeholder(params.get('dtype', tf.float32), params['shape'],
name=self.inputs[0])
params['op_func'](place_holder, params['ksize'], params['strides'],
params['padding'], params['data_format'], name=self.outputs[0])
net = sess.graph_def
return net
@pytest.mark.parametrize("params", test_data)
@pytest.mark.nightly
def test_pool(self, params, ie_device, precision, temp_dir):
self._test(ie_device, precision, temp_dir, params)

View File

@ -0,0 +1,34 @@
import pytest
import tensorflow as tf
from common.tflite_layer_test_class import TFLiteLayerTest
test_params = [
{'shape': [96, 1, 512], 'fft_length': [1, 512], 'reshape_to': [96, 257]},
{'shape': [5, 1, 16], 'fft_length': [1, 16], 'reshape_to': [5, 9]},
]
class TestTFLiteRFFT2DLayerTest(TFLiteLayerTest):
inputs = ["Input"]
outputs = ['RFFT2D_1']
allowed_ops = ['COMPLEX_ABS', 'RESHAPE', 'RFFT2D']
def make_model(self, params):
assert len(set(params.keys()).intersection({'shape', 'fft_length', 'reshape_to'})) == 3, \
'Unexpected parameters for test: ' + ','.join(params.keys())
tf.compat.v1.reset_default_graph()
with tf.compat.v1.Session() as sess:
placeholder = tf.compat.v1.placeholder(params.get('dtype', tf.float32), params['shape'],
name=self.inputs[0])
rfft_2d = tf.signal.rfft2d(placeholder, fft_length=params["fft_length"])
reshape = tf.reshape(rfft_2d, params['reshape_to'])
out = tf.raw_ops.ComplexAbs(x=reshape, Tout=tf.float32, name='RFFT2D')
net = sess.graph_def
return net
@pytest.mark.parametrize("params", test_params)
@pytest.mark.nightly
def test_rfft2d(self, params, ie_device, precision, temp_dir):
self._test(ie_device, precision, temp_dir, params)

View File

@ -0,0 +1,52 @@
import numpy as np
import pytest
import tensorflow as tf
from common.tflite_layer_test_class import TFLiteLayerTest
np.random.seed(42)
test_params = [
{'dtype': np.float32, 'negative_delta': False},
{'dtype': np.int32, 'negative_delta': True},
]
class TestTFLiteRangeLayerTest(TFLiteLayerTest):
inputs = ['Start', 'Limit', 'Delta']
outputs = ["Range"]
allowed_ops = ['RANGE']
def _prepare_input(self, inputs_dict, generator=None):
inputs_data = {}
if self.negative_delta:
inputs_data['Start'] = np.random.randint(1, 10, []).astype(self.dtype)
inputs_data['Limit'] = np.random.randint(-10, 0, []).astype(self.dtype)
inputs_data['Delta'] = np.random.randint(-5, -1, []).astype(self.dtype)
else:
inputs_data['Start'] = np.random.randint(1, 10, []).astype(self.dtype)
inputs_data['Limit'] = np.random.randint(10, 30, []).astype(self.dtype)
inputs_data['Delta'] = np.random.randint(1, 5, []).astype(self.dtype)
return inputs_data
def make_model(self, params):
assert len(set(params.keys()).intersection({'dtype', 'negative_delta'})) == 2, \
'Unexpected parameters for test: ' + ','.join(params.keys())
tf.compat.v1.reset_default_graph()
with tf.compat.v1.Session() as sess:
self.dtype = params['dtype']
self.negative_delta = params['negative_delta']
start = tf.compat.v1.placeholder(self.dtype, [], self.inputs[0])
limit = tf.compat.v1.placeholder(self.dtype, [], self.inputs[1])
delta = tf.compat.v1.placeholder(self.dtype, [], self.inputs[2])
tf.range(start, limit, delta, name=self.outputs[0])
net = sess.graph_def
return net
@pytest.mark.parametrize("params", test_params)
@pytest.mark.nightly
def test_range(self, params, ie_device, precision, temp_dir):
self._test(ie_device, precision, temp_dir, params)

View File

@ -1,10 +1,9 @@
import itertools
import pytest import pytest
import tensorflow as tf import tensorflow as tf
from common.tflite_layer_test_class import TFLiteLayerTest from common.tflite_layer_test_class import TFLiteLayerTest
from common.utils.tflite_utils import data_generators, additional_test_params from common.utils.tflite_utils import additional_test_params
from common.utils.tflite_utils import parametrize_tests
test_ops = [ test_ops = [
{'op_name': 'MEAN', 'op_func': tf.math.reduce_mean}, {'op_name': 'MEAN', 'op_func': tf.math.reduce_mean},
@ -21,28 +20,14 @@ test_params = [
{'shape': [2, 10]} {'shape': [2, 10]}
] ]
test_data = parametrize_tests(test_ops, test_params)
test_data = list(itertools.product(test_ops, test_params)) test_data = parametrize_tests(test_data, additional_test_params[0])
for i, (parameters, shapes) in enumerate(test_data):
parameters.update(shapes)
test_data[i] = parameters.copy()
test_data = list(itertools.product(test_data, additional_test_params[0]))
for i, (parameters, additional_test_params[0]) in enumerate(test_data):
parameters.update(additional_test_params[0])
test_data[i] = parameters.copy()
class TestTFLiteReduceLayerTest(TFLiteLayerTest): class TestTFLiteReduceLayerTest(TFLiteLayerTest):
inputs = ["Input"] inputs = ["Input"]
outputs = ["ReduceOperation"] outputs = ["ReduceOperation"]
def _prepare_input(self, inputs_dict, generator=None):
if generator is None:
return super()._prepare_input(inputs_dict)
return data_generators[generator](inputs_dict)
def make_model(self, params): def make_model(self, params):
assert len(set(params.keys()).intersection({'op_name', 'op_func', 'shape', 'axis'})) == 4, \ assert len(set(params.keys()).intersection({'op_name', 'op_func', 'shape', 'axis'})) == 4, \
'Unexpected parameters for test: ' + ','.join(params.keys()) 'Unexpected parameters for test: ' + ','.join(params.keys())
@ -50,8 +35,8 @@ class TestTFLiteReduceLayerTest(TFLiteLayerTest):
tf.compat.v1.reset_default_graph() tf.compat.v1.reset_default_graph()
with tf.compat.v1.Session() as sess: with tf.compat.v1.Session() as sess:
place_holder = tf.compat.v1.placeholder(params.get('dtype', tf.float32), params['shape'], place_holder = tf.compat.v1.placeholder(params.get('dtype', tf.float32), params['shape'],
name=TestTFLiteReduceLayerTest.inputs[0]) name=self.inputs[0])
params['op_func'](place_holder, axis=params['axis'], name=TestTFLiteReduceLayerTest.outputs[0]) params['op_func'](place_holder, axis=params['axis'], name=self.outputs[0])
net = sess.graph_def net = sess.graph_def
return net return net

View File

@ -0,0 +1,34 @@
import pytest
import tensorflow as tf
from common.tflite_layer_test_class import TFLiteLayerTest
test_params = [
{'shape': [2, 6], 'out_shape': [2, 3, 2]},
{'shape': [2, 4, 6], 'out_shape': [2, -1]},
{'shape': [1], 'out_shape': []},
]
class TestTFLiteReshapeLayerTest(TFLiteLayerTest):
inputs = ["Input"]
outputs = ["Reshape"]
allowed_ops = ['RESHAPE']
def make_model(self, params):
assert len(set(params.keys()).intersection({'shape', 'out_shape'})) == 2, \
'Unexpected parameters for test: ' + ','.join(params.keys())
tf.compat.v1.reset_default_graph()
with tf.compat.v1.Session() as sess:
place_holder = tf.compat.v1.placeholder(params.get('dtype', tf.float32), params['shape'],
name=self.inputs[0])
out_shape = tf.constant(params['out_shape'], dtype=tf.int32)
tf.reshape(place_holder, out_shape, name=self.outputs[0])
net = sess.graph_def
return net
@pytest.mark.parametrize("params", test_params)
@pytest.mark.nightly
def test_reshape(self, params, ie_device, precision, temp_dir):
self._test(ie_device, precision, temp_dir, params)

View File

@ -0,0 +1,50 @@
import pytest
import tensorflow as tf
from common.tflite_layer_test_class import TFLiteLayerTest
from common.utils.tflite_utils import parametrize_tests
test_ops = [
{'op_name': ['RESIZE_BILINEAR'], 'op_func': tf.compat.v1.image.resize_bilinear},
{'op_name': ['RESIZE_NEAREST_NEIGHBOR'], 'op_func': tf.compat.v1.image.resize_nearest_neighbor},
]
test_params = [
{'shape': [1, 3, 4, 3], 'size': [1, 1], 'align_corners': True, 'half_pixel_centers': False},
{'shape': [1, 3, 4, 3], 'size': [1, 1], 'align_corners': False, 'half_pixel_centers': False},
{'shape': [1, 3, 4, 3], 'size': [1, 1], 'align_corners': False, 'half_pixel_centers': True}, # accuracy failure
{'shape': [1, 3, 4, 3], 'size': [10, 10], 'align_corners': True, 'half_pixel_centers': False},
{'shape': [1, 3, 4, 3], 'size': [10, 10], 'align_corners': False, 'half_pixel_centers': False},
{'shape': [1, 3, 4, 3], 'size': [10, 10], 'align_corners': False, 'half_pixel_centers': True}, # accuracy failure
]
test_data = parametrize_tests(test_ops, test_params)
class TestTFLiteResizeLayerTest(TFLiteLayerTest):
inputs = ["Input"]
outputs = ["Resize"]
def make_model(self, params):
assert len(set(params.keys()).intersection({'op_name', 'op_func', 'shape', 'size', 'align_corners',
'half_pixel_centers'})) == 6, \
'Unexpected parameters for test: ' + ','.join(params.keys())
self.allowed_ops = params['op_name']
tf.compat.v1.reset_default_graph()
with tf.compat.v1.Session() as sess:
placeholder = tf.compat.v1.placeholder(params.get("dtype", tf.float32), params["shape"],
name=self.inputs[0])
params['op_func'](placeholder, size=params['size'],
align_corners=params['align_corners'],
half_pixel_centers=params['half_pixel_centers'],
name=self.outputs[0])
net = sess.graph_def
return net
@pytest.mark.parametrize("params", test_data)
@pytest.mark.nightly
def test_resize_resize(self, params, ie_device, precision, temp_dir):
if not params['align_corners'] and params['half_pixel_centers'] and params['op_name'] == ['RESIZE_NEAREST_NEIGHBOR']:
pytest.xfail("CVS-110473")
self._test(ie_device, precision, temp_dir, params)

View File

@ -0,0 +1,43 @@
import pytest
import tensorflow as tf
from common.tflite_layer_test_class import TFLiteLayerTest
test_params = [
{'shape': [1], 'axis': [-1]},
{'shape': [1], 'axis': [0]},
{'shape': [2, 6], 'axis': [-1, -2]},
{'shape': [2, 6], 'axis': [1]},
{'shape': [2, 4, 6], 'axis': [0, -2]},
{'shape': [2, 4, 6], 'axis': [2]},
{'shape': [2, 4, 6, 8], 'axis': [0, 3, -3, 2]},
{'shape': [2, 4, 6, 8], 'axis': [-3]},
{'shape': [2, 3, 1, 2, 2], 'axis': [0, 3, -3, 1, -1]},
{'shape': [2, 3, 1, 2, 2], 'axis': [4]},
{'shape': [2, 1, 1, 1, 2, 3, 2, 2], 'axis': [-1]},
{'shape': [2, 1, 1, 1, 2, 3, 2, 2], 'axis': [0, 1, 2, 3, 4, 5, 6, 7]},
]
class TestTFLiteReverseV2LayerTest(TFLiteLayerTest):
inputs = ["Input"]
outputs = ["ReverseV2"]
allowed_ops = ['REVERSE_V2']
def make_model(self, params):
assert len(set(params.keys()).intersection({'shape', 'axis'})) == 2, \
'Unexpected parameters for test: ' + ','.join(params.keys())
tf.compat.v1.reset_default_graph()
with tf.compat.v1.Session() as sess:
place_holder = tf.compat.v1.placeholder(params.get('dtype', tf.float32), params['shape'],
name=self.inputs[0])
tf.reverse(place_holder, params['axis'], name=self.outputs[0])
net = sess.graph_def
return net
@pytest.mark.parametrize("params", test_params)
@pytest.mark.nightly
def test_reverse_v2(self, params, ie_device, precision, temp_dir):
if len(params['axis']) > 1:
pytest.xfail('CVS-109932')
self._test(ie_device, precision, temp_dir, params)

View File

@ -0,0 +1,74 @@
import numpy as np
import pytest
import tensorflow as tf
from common.tflite_layer_test_class import TFLiteLayerTest
np.random.seed(42)
test_params = [
{'indices_shape': [4, 1], 'indices_value': [4, 3, 1, 7], 'updates_dtype': np.int32, 'updates_shape': [4],
'shape_shape': [1], 'shape_value': [8]},
{'indices_shape': [4, 1], 'indices_value': [4, 3, 1, 7], 'updates_dtype': np.int64, 'updates_shape': [4],
'shape_shape': [1], 'shape_value': [8]},
{'indices_shape': [4, 1], 'indices_value': [4, 3, 1, 7], 'updates_dtype': np.float32, 'updates_shape': [4],
'shape_shape': [1], 'shape_value': [8]},
{'indices_shape': [4, 1], 'indices_value': [4, 3, 1, 7], 'updates_dtype': np.bool, 'updates_shape': [4],
'shape_shape': [1], 'shape_value': [8]},
{'indices_shape': [4, 2], 'indices_value': [[0, 0], [1, 0], [0, 2], [1, 2]], 'updates_dtype': np.int32,
'updates_shape': [4, 5], 'shape_shape': [3], 'shape_value': [2, 3, 5]},
{'indices_shape': [4, 2], 'indices_value': [[0, 0], [1, 0], [0, 2], [1, 2]], 'updates_dtype': np.int64,
'updates_shape': [4, 5], 'shape_shape': [3], 'shape_value': [2, 3, 5]},
{'indices_shape': [4, 2], 'indices_value': [[0, 0], [1, 0], [0, 2], [1, 2]], 'updates_dtype': np.float32,
'updates_shape': [4, 5], 'shape_shape': [3], 'shape_value': [2, 3, 5]},
{'indices_shape': [4, 2], 'indices_value': [[0, 0], [1, 0], [0, 2], [1, 2]], 'updates_dtype': np.bool,
'updates_shape': [4, 5], 'shape_shape': [3], 'shape_value': [2, 3, 5]},
]
class TestTFLiteScatterNDLayerTest(TFLiteLayerTest):
inputs = ["Indices", "Updates", "Shape"]
outputs = ["ScatterND"]
allowed_ops = ['SCATTER_ND']
def _prepare_input(self, inputs_dict, generator=None):
inputs_dict['Indices'] = np.array(self.indices_value, dtype=np.int32).reshape(self.indices_shape)
if self.updates_dtype in [tf.int32, tf.int64]:
inputs_dict['Updates'] = np.random.randint(-100, 100 + 1, self.updates_shape)
if self.updates_dtype == tf.float32:
inputs_dict['Updates'] = (100 - (-100) * np.random.random_sample(self.updates_shape) + (-100))
if self.updates_dtype == tf.bool:
inputs_dict['Updates'] = np.random.choice([True, False], size=self.updates_shape)
inputs_dict['Updates'] = inputs_dict['Updates'].astype(self.updates_dtype)
inputs_dict['Shape'] = np.array(self.shape_value, dtype=np.int32)
return inputs_dict
def make_model(self, params):
assert len(set(params.keys()).intersection({'indices_shape', 'indices_value',
'updates_dtype', 'updates_shape', 'shape_shape',
'shape_value'})) == 6, \
'Unexpected parameters for test: ' + ','.join(params.keys())
self.indices_value = params['indices_value']
self.indices_shape = params['indices_shape']
self.updates_dtype = params['updates_dtype']
self.updates_shape = params['updates_shape']
self.shape_value = params['shape_value']
tf.compat.v1.reset_default_graph()
with tf.compat.v1.Session() as sess:
indices = tf.compat.v1.placeholder(tf.int32, self.indices_shape, name=self.inputs[0])
updates = tf.compat.v1.placeholder(self.updates_dtype, self.updates_shape, name=self.inputs[1])
shape = tf.compat.v1.placeholder(tf.int32, params['shape_shape'], name=self.inputs[2])
tf.scatter_nd(indices, updates, shape, name=self.outputs[0])
net = sess.graph_def
return net
@pytest.mark.parametrize("params", test_params)
@pytest.mark.nightly
def test_scatter_nd(self, params, ie_device, precision, temp_dir):
self._test(ie_device, precision, temp_dir, params)

View File

@ -0,0 +1,44 @@
import pytest
import tensorflow as tf
from common.tflite_layer_test_class import TFLiteLayerTest
test_params = [
{'shape': [4], 'segment_ids': [0, 0, 1, 1]},
{'shape': [4], 'segment_ids': [0, 1, 2, 2]},
{'shape': [4], 'segment_ids': [0, 1, 2, 3]},
{'shape': [4], 'segment_ids': [0, 0, 0, 0]},
{'shape': [4, 4], 'segment_ids': [0, 0, 1, 1]},
{'shape': [4, 4], 'segment_ids': [0, 1, 2, 2]},
{'shape': [4, 4], 'segment_ids': [0, 1, 2, 3]},
{'shape': [4, 4], 'segment_ids': [0, 0, 0, 0]},
{'shape': [4, 3, 2], 'segment_ids': [0, 0, 0, 0]},
{'shape': [4, 3, 2], 'segment_ids': [0, 0, 1, 1]},
{'shape': [4, 3, 2], 'segment_ids': [0, 1, 2, 2]},
{'shape': [4, 3, 2], 'segment_ids': [0, 1, 2, 3]},
]
class TestTFLiteSegmentSumLayerTest(TFLiteLayerTest):
inputs = ["Input"]
outputs = ["SegmentSum"]
allowed_ops = ['SEGMENT_SUM']
def make_model(self, params):
assert len(set(params.keys()).intersection({'shape', 'segment_ids'})) == 2, \
'Unexpected parameters for test: ' + ','.join(params.keys())
tf.compat.v1.reset_default_graph()
with tf.compat.v1.Session() as sess:
place_holder = tf.compat.v1.placeholder(params.get('dtype', tf.float32), params['shape'],
name=self.inputs[0])
constant = tf.constant(params['segment_ids'], dtype=tf.int32)
tf.math.segment_sum(place_holder, constant, name=self.outputs[0])
net = sess.graph_def
return net
@pytest.mark.parametrize("params", test_params)
@pytest.mark.nightly
def test_segment_sum(self, params, ie_device, precision, temp_dir):
self._test(ie_device, precision, temp_dir, params)

View File

@ -0,0 +1,35 @@
import pytest
import tensorflow as tf
from common.tflite_layer_test_class import TFLiteLayerTest
test_params = [
{'shape': [2, 3, 1, 2, 2], 'condition': [True, False]},
{'shape': [4, 3, 1, 2], 'condition': [False, False, False, True]},
{'shape': [2, 3], 'condition': [[True, True, True], [False, False, False]]},
{'shape': [2], 'condition': [False, True]},
]
class TestTFLiteSelectLayerTest(TFLiteLayerTest):
inputs = ["X", "Y"]
outputs = ["Select"]
allowed_ops = ['SELECT']
def make_model(self, params):
assert len(set(params.keys()).intersection({'shape', 'condition'})) == 2, \
'Unexpected parameters for test: ' + ','.join(params.keys())
tf.compat.v1.reset_default_graph()
with tf.compat.v1.Session() as sess:
cond = tf.constant(params['condition'], dtype=tf.bool)
x = tf.compat.v1.placeholder(tf.float32, params['shape'], self.inputs[0])
y = tf.compat.v1.placeholder(tf.float32, params['shape'], self.inputs[1])
tf.raw_ops.Select(condition=cond, x=x, y=y, name=self.outputs[0])
net = sess.graph_def
return net
@pytest.mark.parametrize("params", test_params)
@pytest.mark.nightly
def test_select(self, params, ie_device, precision, temp_dir):
self._test(ie_device, precision, temp_dir, params)

View File

@ -0,0 +1,36 @@
import pytest
import tensorflow as tf
from common.tflite_layer_test_class import TFLiteLayerTest
test_params = [
{'shape': [2, 3, 1, 2, 2], 'condition': [True, False]},
{'shape': [4, 3, 1, 2], 'condition': [False, True]},
{'shape': [3, 3, 3, 3], 'condition': [True, True, False]},
{'shape': [3, 3, 3], 'condition': [True, True, False]},
{'shape': [2, 3], 'condition': [True, False, True]},
]
class TestTFLiteSelectLayerTest(TFLiteLayerTest):
inputs = ["X", "Y"]
outputs = ["Select"]
allowed_ops = ['SELECT_V2']
def make_model(self, params):
assert len(set(params.keys()).intersection({'shape', 'condition'})) == 2, \
'Unexpected parameters for test: ' + ','.join(params.keys())
tf.compat.v1.reset_default_graph()
with tf.compat.v1.Session() as sess:
cond = tf.constant(params['condition'], dtype=tf.bool)
x = tf.compat.v1.placeholder(tf.float32, params['shape'], self.inputs[0])
y = tf.compat.v1.placeholder(tf.float32, params['shape'], self.inputs[1])
tf.raw_ops.SelectV2(condition=cond, t=x, e=y, name=self.outputs[0])
net = sess.graph_def
return net
@pytest.mark.parametrize("params", test_params)
@pytest.mark.nightly
def test_select_v2(self, params, ie_device, precision, temp_dir):
self._test(ie_device, precision, temp_dir, params)

View File

@ -0,0 +1,57 @@
import string
import numpy as np
import pytest
import tensorflow as tf
from common.tflite_layer_test_class import TFLiteLayerTest
test_params = [
# OV doesn't support string format
# {'shape': [12, 2, 2, 5], 'begin': [0, 0, 0, 0], 'size': [8, 2, 2, 3], 'dtype': tf.string},
{'shape': [12, 2, 2, 5], 'begin': [1, 0, 1, 0], 'size': [11, 2, 1, 5], 'dtype': np.float32},
{'shape': [1, 4, 4, 4], 'begin': [0, 1, 0, 0], 'size': [1, -1, 1, 1], 'dtype': np.float32},
{'shape': [6, 2, 2, 2, 5], 'begin': [0, 0, 0, 0, 0], 'size': [4, 2, 2, 2, 3], 'dtype': np.int32},
{'shape': [2, 3], 'begin': [1, 0], 'size': [-1, -1], 'dtype': np.int64},
]
class TestTFLiteSliceLayerTest(TFLiteLayerTest):
inputs = ["Input", "Begin", "Size"]
outputs = ["Slice"]
allowed_ops = ['SLICE']
def _prepare_input(self, inputs_dict, generator=None):
if self.input_dtype == tf.string:
letters = list(string.ascii_uppercase)
inputs_dict["Input"] = np.random.choice(letters, size=self.shape).astype(self.input_dtype)
else:
inputs_dict["Input"] = np.random.randint(-1, 2, self.shape).astype(self.input_dtype)
inputs_dict["Begin"] = np.array(self.begin).astype(np.int32)
inputs_dict['Size'] = np.array(self.size).astype(np.int32)
return inputs_dict
def make_model(self, params):
assert len(set(params.keys()).intersection({'shape', 'begin', 'size', 'dtype'})) == 4, \
'Unexpected parameters for test: ' + ','.join(params.keys())
self.input_dtype = params['dtype']
self.shape = params['shape']
self.begin = params['begin']
self.size = params['size']
tf.compat.v1.reset_default_graph()
with tf.compat.v1.Session() as sess:
placeholder = tf.compat.v1.placeholder(params['dtype'], params['shape'], self.inputs[0])
begin = tf.compat.v1.placeholder(tf.int32, len(params['shape']), name=self.inputs[1])
size = tf.compat.v1.placeholder(tf.int32, len(params['shape']), name=self.inputs[2])
tf.slice(placeholder, begin, size, name=self.outputs[0])
net = sess.graph_def
return net
@pytest.mark.parametrize("params", test_params)
@pytest.mark.nightly
def test_slice(self, params, ie_device, precision, temp_dir):
self._test(ie_device, precision, temp_dir, params)

View File

@ -0,0 +1,32 @@
import pytest
import tensorflow as tf
from common.tflite_layer_test_class import TFLiteLayerTest
test_params = [
{'shape': [8, 10, 10, 3], 'block_shape': [2, 2], 'paddings': [[0, 2], [0, 0]]},
{'shape': [24, 10, 10, 1], 'block_shape': [6, 6], 'paddings': [[2, 0], [0, 2]]}
]
class TestTFLiteSpaceToBatchNDLayerTest(TFLiteLayerTest):
inputs = ["Input"]
outputs = ["SpaceToBatchOP"]
allowed_ops = ['SPACE_TO_BATCH_ND']
def make_model(self, params):
assert len(set(params.keys()).intersection({'shape', 'block_shape', 'paddings'})) == 3, \
'Unexpected parameters for test: ' + ','.join(params.keys())
tf.compat.v1.reset_default_graph()
with tf.compat.v1.Session() as sess:
place_holder = tf.compat.v1.placeholder(params.get('dtype', tf.float32), params['shape'],
name=self.inputs[0])
tf.space_to_batch(place_holder, params['block_shape'], params['paddings'],
name=self.outputs[0])
net = sess.graph_def
return net
@pytest.mark.parametrize("params", test_params)
@pytest.mark.nightly
def test_space_to_batch_nd(self, params, ie_device, precision, temp_dir):
self._test(ie_device, precision, temp_dir, params)

View File

@ -0,0 +1,31 @@
import pytest
import tensorflow as tf
from common.tflite_layer_test_class import TFLiteLayerTest
test_params = [
{'shape': [8, 10, 10, 16], 'block_size': 2, 'data_format': 'NHWC'},
{'shape': [24, 10, 10, 50], 'block_size': 5, 'data_format': 'NHWC'},
]
class TestTFLiteSpaceToDepthLayerTest(TFLiteLayerTest):
inputs = ["Input"]
outputs = ["SpaceToDepth"]
allowed_ops = ['SPACE_TO_DEPTH']
def make_model(self, params):
assert len(set(params.keys()).intersection({'shape', 'block_size', 'data_format'})) == 3, \
'Unexpected parameters for test: ' + ','.join(params.keys())
tf.compat.v1.reset_default_graph()
with tf.compat.v1.Session() as sess:
place_holder = tf.compat.v1.placeholder(params.get('dtype', tf.float32), params['shape'],
name=self.inputs[0])
tf.nn.space_to_depth(place_holder, params['block_size'], params['data_format'], name=self.outputs[0])
net = sess.graph_def
return net
@pytest.mark.parametrize("params", test_params)
@pytest.mark.nightly
def test_space_to_depth(self, params, ie_device, precision, temp_dir):
self._test(ie_device, precision, temp_dir, params)

View File

@ -0,0 +1,32 @@
import pytest
import tensorflow as tf
from common.tflite_layer_test_class import TFLiteLayerTest
test_params = [
{'shape': [6], 'num_or_size_splits': 2, 'axis': 0},
{'shape': [2, 1, 6], 'num_or_size_splits': 3, 'axis': 2},
{'shape': [4, 3, 2, 7], 'num_or_size_splits': 4, 'axis': -4},
]
class TestTFLiteSplitLayerTest(TFLiteLayerTest):
inputs = ["Input"]
outputs = ["Split"]
allowed_ops = ['SPLIT']
def make_model(self, params):
assert len(set(params.keys()).intersection({'shape', 'num_or_size_splits',
'axis'})) == 3, \
'Unexpected parameters for test: ' + ','.join(params.keys())
tf.compat.v1.reset_default_graph()
with tf.compat.v1.Session() as sess:
placeholder = tf.compat.v1.placeholder(tf.float32, params['shape'], self.inputs[0])
tf.split(placeholder, params["num_or_size_splits"], params["axis"], name=self.outputs[0])
net = sess.graph_def
return net
@pytest.mark.parametrize("params", test_params)
@pytest.mark.nightly
def test_split(self, params, ie_device, precision, temp_dir):
self._test(ie_device, precision, temp_dir, params)

View File

@ -0,0 +1,39 @@
import pytest
import tensorflow as tf
from common.tflite_layer_test_class import TFLiteLayerTest
test_params = [
{'shape': [3], 'num_or_size_splits': [0, 2, 0, 1], 'axis': 0},
{'shape': [2, 3, 9], 'num_or_size_splits': [1, 2, 3, -1, 1], 'axis': 2},
{'shape': [3, 9, 5, 4], 'num_or_size_splits': [1, 2, 0, -1, 2, 0], 'axis': -3},
]
class TestTFLiteSplitLayerTest(TFLiteLayerTest):
inputs = ["Input"]
outputs = ["SplitV"]
allowed_ops = ['SPLIT_V']
def make_model(self, params):
assert len(set(params.keys()).intersection({'shape', 'num_or_size_splits',
'axis'})) == 3, \
'Unexpected parameters for test: ' + ','.join(params.keys())
tf.compat.v1.reset_default_graph()
with tf.compat.v1.Session() as sess:
placeholder = tf.compat.v1.placeholder(tf.float32, params['shape'], self.inputs[0])
size_splits = tf.constant(params['num_or_size_splits'], dtype=tf.int32)
axis = tf.constant(params['axis'], dtype=tf.int32)
num_split = len(params['num_or_size_splits'])
tf.raw_ops.SplitV(value=placeholder, size_splits=size_splits, axis=axis,
num_split=num_split, name=self.outputs[0])
net = sess.graph_def
return net
@pytest.mark.parametrize("params", test_params)
@pytest.mark.nightly
def test_split_v(self, params, ie_device, precision, temp_dir):
if 0 in params['num_or_size_splits']:
pytest.skip("CVS-110040")
self._test(ie_device, precision, temp_dir, params)

View File

@ -0,0 +1,69 @@
import numpy as np
import pytest
import tensorflow as tf
from common.tflite_layer_test_class import TFLiteLayerTest
test_params = [
{'shape': [12, 2, 2, 5], 'dtype': np.int32, 'strides': [2, 1, 3, 1], 'begin': [0, 0, 0, 0], 'end': [12, 2, 2, 5],
'begin_mask': None, 'end_mask': None, 'shrink_axis_mask': 4},
{'shape': [12, 2, 2, 5], 'dtype': np.float32, 'strides': None, 'begin': [0, 0, 0, 0], 'end': [12, 2, 2, 5],
'begin_mask': None, 'end_mask': None, 'shrink_axis_mask': None},
{'shape': [12, 2, 2, 5], 'dtype': np.float32, 'strides': None, 'begin': [1, 0, 1, 0], 'end': [8, 2, 2, 3],
'begin_mask': 8, 'end_mask': 3, 'shrink_axis_mask': 4},
{'shape': [12, 2, 2, 5], 'dtype': np.int64, 'strides': [1], 'begin': [0], 'end': [1],
'begin_mask': 8, 'end_mask': 3, 'shrink_axis_mask': None},
{'shape': [12, 2, 2, 5], 'dtype': np.bool, 'strides': [1], 'begin': [0], 'end': [1],
'begin_mask': 8, 'end_mask': 3, 'shrink_axis_mask': None},
]
class TestTFLiteStridedSliceLayerTest(TFLiteLayerTest):
inputs = ["Input", "Begin", "End"]
outputs = ["StridedSlice"]
allowed_ops = ['STRIDED_SLICE']
def _prepare_input(self, inputs_dict, generator=None):
if self.input_dtype == np.bool:
inputs_dict['Input'] = np.random.choice([True, False], size=inputs_dict['Input'])
else:
inputs_dict['Input'] = np.random.randint(-255, 255, inputs_dict['Input']).astype(self.input_dtype)
inputs_dict['Begin'] = np.array(self.begin).astype(np.int32)
inputs_dict['End'] = np.array(self.end).astype(np.int32)
if self.strides:
inputs_dict["Strides"] = np.array(self.strides).astype(np.int32)
return inputs_dict
def make_model(self, params):
assert len(set(params.keys()).intersection({'shape', 'dtype', 'strides', 'begin',
'end', 'begin_mask', 'end_mask', 'shrink_axis_mask'})) == 8, \
'Unexpected parameters for test: ' + ','.join(params.keys())
self.input_dtype = params['dtype']
self.begin = params['begin']
self.end = params['end']
self.strides = params['strides']
if "Strides" in self.inputs:
self.inputs.pop(-1)
tf.compat.v1.reset_default_graph()
with tf.compat.v1.Session() as sess:
placeholder = tf.compat.v1.placeholder(params['dtype'], params['shape'], self.inputs[0])
begin = tf.compat.v1.placeholder(tf.int32, [len(params['begin'])], self.inputs[1])
end = tf.compat.v1.placeholder(tf.int32, [len(params['end'])], self.inputs[2])
strides = None
if params['strides']:
name = "Strides"
self.inputs.append(name)
strides = tf.compat.v1.placeholder(tf.int32, [len(params['end'])], name)
tf.strided_slice(placeholder, begin, end, strides,
begin_mask=params['begin_mask'], end_mask=params['end_mask'],
shrink_axis_mask=params['shrink_axis_mask'], name=self.outputs[0])
net = sess.graph_def
return net
@pytest.mark.parametrize("params", test_params)
@pytest.mark.nightly
def test_strided_slice(self, params, ie_device, precision, temp_dir):
self._test(ie_device, precision, temp_dir, params)

View File

@ -0,0 +1,32 @@
import pytest
import tensorflow as tf
from common.tflite_layer_test_class import TFLiteLayerTest
test_params = [
{'shape': [2], 'multiples': [2]},
{'shape': [2, 3], 'multiples': [1, 2]},
{'shape': [2, 3, 1], 'multiples': [5, 1, 3]},
]
class TestTFLiteTileLayerTest(TFLiteLayerTest):
inputs = ["Input"]
outputs = ["Tile"]
allowed_ops = ['TILE']
def make_model(self, params):
assert len(set(params.keys()).intersection({'shape', 'multiples'})) == 2, \
'Unexpected parameters for test: ' + ','.join(params.keys())
tf.compat.v1.reset_default_graph()
with tf.compat.v1.Session() as sess:
placeholder = tf.compat.v1.placeholder(tf.float32, params['shape'], self.inputs[0])
tf.tile(placeholder, params['multiples'], name=self.outputs[0])
net = sess.graph_def
return net
@pytest.mark.parametrize("params", test_params)
@pytest.mark.nightly
def test_tile(self, params, ie_device, precision, temp_dir):
self._test(ie_device, precision, temp_dir, params)

View File

@ -0,0 +1,33 @@
import pytest
import tensorflow as tf
from common.tflite_layer_test_class import TFLiteLayerTest
test_params = [
{'shape': [2], 'k': 2, 'sorted': True},
{'shape': [2, 3], 'k': 1, 'sorted': False},
{'shape': [2, 3, 5], 'k': 2, 'sorted': True},
{'shape': [2, 3, 5, 10], 'k': 9, 'sorted': False},
]
class TestTFLiteTopKV2LayerTest(TFLiteLayerTest):
inputs = ["Input"]
outputs = ["TopKV2"]
allowed_ops = ['TOPK_V2']
def make_model(self, params):
assert len(set(params.keys()).intersection({'shape', 'k', 'sorted'})) == 3, \
'Unexpected parameters for test: ' + ','.join(params.keys())
tf.compat.v1.reset_default_graph()
with tf.compat.v1.Session() as sess:
placeholder = tf.compat.v1.placeholder(tf.float32, params['shape'], self.inputs[0])
tf.raw_ops.TopKV2(input=placeholder, k=params['k'], sorted=params['sorted'], name=self.outputs[0])
net = sess.graph_def
return net
@pytest.mark.parametrize("params", test_params)
@pytest.mark.nightly
def test_topk_v2(self, params, ie_device, precision, temp_dir):
self._test(ie_device, precision, temp_dir, params)

View File

@ -0,0 +1,32 @@
import pytest
import tensorflow as tf
from common.tflite_layer_test_class import TFLiteLayerTest
test_params = [
{'shape': [2, 3], 'perm': [1, 0], 'conjugate': False},
{'shape': [2, 3, 5], 'perm': [2, 0, 1], 'conjugate': True},
{'shape': [2, 3, 5, 10], 'perm': [1, 2, 3, 0], 'conjugate': False},
]
class TestTFLiteTransposeLayerTest(TFLiteLayerTest):
inputs = ["Input"]
outputs = ["Transpose"]
allowed_ops = ['TRANSPOSE']
def make_model(self, params):
assert len(set(params.keys()).intersection({'shape', 'perm', 'conjugate'})) == 3, \
'Unexpected parameters for test: ' + ','.join(params.keys())
tf.compat.v1.reset_default_graph()
with tf.compat.v1.Session() as sess:
placeholder = tf.compat.v1.placeholder(tf.float32, params['shape'], self.inputs[0])
tf.transpose(placeholder, params['perm'], params['conjugate'], name=self.outputs[0])
net = sess.graph_def
return net
@pytest.mark.parametrize("params", test_params)
@pytest.mark.nightly
def test_transpose(self, params, ie_device, precision, temp_dir):
self._test(ie_device, precision, temp_dir, params)

View File

@ -0,0 +1,45 @@
import numpy as np
import pytest
import tensorflow as tf
from common.tflite_layer_test_class import TFLiteLayerTest
np.random.seed(42)
test_params = [
{'shape': [1, 3, 4, 1], 'ksize': [1, 1, 1, 1], 'output_shape': [1, 3, 4, 1], 'strides': [1, 1, 1, 1],
'padding': 'SAME', 'data_format': 'NHWC', 'dilations': [1, 1, 1, 1]},
{'shape': [1, 4, 4, 1], 'ksize': [1, 1, 1, 1], 'output_shape': [1, 4, 4, 1], 'strides': [1, 1], 'padding': 'SAME',
'data_format': 'NHWC', 'dilations': [1, 2, 2, 1]},
#
{'shape': [1, 22, 22, 3], 'ksize': [1, 1, 6, 3], 'output_shape': [1, 22, 22, 6], 'strides': [1, 1],
'padding': 'VALID', 'data_format': 'NHWC', 'dilations': [1, 1, 1, 1]},
{'shape': [1, 22, 22, 3], 'ksize': [3, 3, 3, 3], 'output_shape': [1, 24, 24, 3], 'strides': [1, 1],
'padding': 'VALID', 'data_format': 'NHWC', 'dilations': [1, 1, 1, 1]},
]
class TestTFLiteTransposeConvLayerTest(TFLiteLayerTest):
inputs = ["Input"]
outputs = ["TransposeConv"]
allowed_ops = ['TRANSPOSE_CONV']
def make_model(self, params):
assert len(set(params.keys()).intersection({'shape', 'ksize', 'strides',
'padding', 'data_format', 'dilations', 'output_shape'})) == 7, \
'Unexpected parameters for test: ' + ','.join(params.keys())
tf.compat.v1.reset_default_graph()
with tf.compat.v1.Session() as sess:
placeholder = tf.compat.v1.placeholder(params.get('dtype', tf.float32), params['shape'],
name=self.inputs[0])
filter_input = tf.constant(np.random.randint(-1, 1, size=(params['ksize'])), dtype=tf.float32)
tf.nn.conv2d_transpose(placeholder, filter_input, params['output_shape'], params["strides"],
params["padding"],
params["data_format"], name=self.outputs[0])
net = sess.graph_def
return net
@pytest.mark.parametrize("params", test_params)
@pytest.mark.nightly
def test_transpose_conv(self, params, ie_device, precision, temp_dir):
self._test(ie_device, precision, temp_dir, params)

View File

@ -1,17 +1,16 @@
# Copyright (C) 2018-2023 Intel Corporation # Copyright (C) 2018-2023 Intel Corporation
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
import itertools
from functools import partial from functools import partial
import numpy as np import numpy as np
import pytest import pytest
import tensorflow as tf import tensorflow as tf
from common.tflite_layer_test_class import TFLiteLayerTest from common.tflite_layer_test_class import TFLiteLayerTest
from common.utils.tflite_utils import data_generators from common.utils.tflite_utils import parametrize_tests
np.random.seed(42) np.random.seed(42)
test_ops = [ test_ops = [
{'op_name': 'ABS', 'op_func': tf.math.abs}, {'op_name': 'ABS', 'op_func': tf.math.abs},
{'op_name': 'CAST', 'op_func': partial(tf.cast, dtype=tf.int32)}, {'op_name': 'CAST', 'op_func': partial(tf.cast, dtype=tf.int32)},
@ -27,6 +26,7 @@ test_ops = [
{'op_name': 'LOGISTIC', 'op_func': tf.math.sigmoid}, {'op_name': 'LOGISTIC', 'op_func': tf.math.sigmoid},
{'op_name': 'NEG', 'op_func': tf.math.negative}, {'op_name': 'NEG', 'op_func': tf.math.negative},
{'op_name': 'RELU6', 'op_func': tf.nn.relu6}, {'op_name': 'RELU6', 'op_func': tf.nn.relu6},
{'op_name': 'RELU', 'op_func': tf.nn.relu},
{'op_name': 'ROUND', 'op_func': tf.math.round}, {'op_name': 'ROUND', 'op_func': tf.math.round},
{'op_name': 'RSQRT', 'op_func': tf.math.rsqrt, 'kwargs_to_prepare_input': 'positive'}, {'op_name': 'RSQRT', 'op_func': tf.math.rsqrt, 'kwargs_to_prepare_input': 'positive'},
{'op_name': 'SIN', 'op_func': tf.math.sin}, {'op_name': 'SIN', 'op_func': tf.math.sin},
@ -51,21 +51,13 @@ test_params = [
{'shape': [2, 10]} {'shape': [2, 10]}
] ]
test_data = list(itertools.product(test_ops, test_params)) test_data = parametrize_tests(test_ops, test_params)
for i, (parameters, shapes) in enumerate(test_data):
parameters.update(shapes)
test_data[i] = parameters.copy()
class TestTFLiteUnaryLayerTest(TFLiteLayerTest): class TestTFLiteUnaryLayerTest(TFLiteLayerTest):
inputs = ["Input"] inputs = ["Input"]
outputs = ["UnaryOperation"] outputs = ["UnaryOperation"]
def _prepare_input(self, inputs_dict, generator=None):
if generator is None:
return super()._prepare_input(inputs_dict)
return data_generators[generator](inputs_dict)
def make_model(self, params): def make_model(self, params):
assert len(set(params.keys()).intersection({'op_name', 'op_func', 'shape'})) == 3, \ assert len(set(params.keys()).intersection({'op_name', 'op_func', 'shape'})) == 3, \
'Unexpected parameters for test: ' + ','.join(params.keys()) 'Unexpected parameters for test: ' + ','.join(params.keys())
@ -73,8 +65,8 @@ class TestTFLiteUnaryLayerTest(TFLiteLayerTest):
tf.compat.v1.reset_default_graph() tf.compat.v1.reset_default_graph()
with tf.compat.v1.Session() as sess: with tf.compat.v1.Session() as sess:
place_holder = tf.compat.v1.placeholder(params.get('dtype', tf.float32), params['shape'], place_holder = tf.compat.v1.placeholder(params.get('dtype', tf.float32), params['shape'],
name=TestTFLiteUnaryLayerTest.inputs[0]) name=self.inputs[0])
params['op_func'](place_holder, name=TestTFLiteUnaryLayerTest.outputs[0]) params['op_func'](place_holder, name=self.outputs[0])
net = sess.graph_def net = sess.graph_def
return net return net

View File

@ -0,0 +1,37 @@
# Copyright (C) 2018-2023 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
import numpy as np
import pytest
import tensorflow as tf
from common.tflite_layer_test_class import TFLiteLayerTest
np.random.seed(42)
test_params = [
{'shape': [15]},
{'shape': [1]}
]
class TestTFLiteUniqueLayerTest(TFLiteLayerTest):
inputs = ["Input"]
outputs = ["Unqiue"]
allowed_ops = ['UNIQUE']
def make_model(self, params):
assert len(set(params.keys()).intersection({'shape'})) == 1, \
'Unexpected parameters for test: ' + ','.join(params.keys())
tf.compat.v1.reset_default_graph()
with tf.compat.v1.Session() as sess:
placeholder = tf.compat.v1.placeholder(params.get('dtype', tf.float32), params['shape'],
name=self.inputs[0])
tf.unique(placeholder, name=self.outputs[0])
net = sess.graph_def
return net
@pytest.mark.parametrize("params", test_params)
@pytest.mark.nightly
def test_unique(self, params, ie_device, precision, temp_dir):
self._test(ie_device, precision, temp_dir, params)

View File

@ -0,0 +1,41 @@
# Copyright (C) 2018-2023 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
import numpy as np
import pytest
import tensorflow as tf
from common.tflite_layer_test_class import TFLiteLayerTest
np.random.seed(42)
test_params = [
{'shape': [3, 4, 3], 'axis': 0},
{'shape': [3, 4, 3], 'axis': -1},
{'shape': [3, 4, 3, 5], 'axis': -2},
{'shape': [3, 4, 3, 5], 'axis': 2},
{'shape': [1], 'axis': -1},
{'shape': [1], 'axis': 0}
]
class TestTFLiteUnpackLayerTest(TFLiteLayerTest):
inputs = ["Input"]
outputs = ["Unpack"]
allowed_ops = ['UNPACK']
def make_model(self, params):
assert len(set(params.keys()).intersection({'shape', 'axis'})) == 2, \
'Unexpected parameters for test: ' + ','.join(params.keys())
tf.compat.v1.reset_default_graph()
with tf.compat.v1.Session() as sess:
place_holder = tf.compat.v1.placeholder(params.get('dtype', tf.float32), params['shape'],
name=self.inputs[0])
tf.unstack(place_holder, axis=params['axis'], name=self.outputs[0])
net = sess.graph_def
return net
@pytest.mark.parametrize("params", test_params)
@pytest.mark.nightly
def test_unpack(self, params, ie_device, precision, temp_dir):
self._test(ie_device, precision, temp_dir, params)