forked from openvinotoolkit/openvino
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_tf_Mul.py
249 lines (211 loc) · 12.3 KB
/
test_tf_Mul.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
# Copyright (C) 2018-2023 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
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, use_new_frontend):
"""
Tensorflow net IR net
Placeholder->Mul => Placeholder->Multiply
/ /
Const-------/ Const-------/
"""
import tensorflow as tf
tf.compat.v1.reset_default_graph()
# Create the graph and model
with tf.compat.v1.Session() as sess:
tf_x_shape = x_shape.copy()
tf_y_shape = y_shape.copy()
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)
if (constant_value == 1).all():
# Avoid elimination of the layer from IR
constant_value = constant_value + 1
y = tf.constant(constant_value)
mul = tf.multiply(x, y, name="Operation")
tf.compat.v1.global_variables_initializer()
tf_net = sess.graph_def
#
# Create reference IR net
# Please, specify 'type': 'Input' for input node
# Moreover, do not forget to validate ALL layer attributes!!!
#
ref_net = None
return tf_net, ref_net
# TODO: implement tests for 2 Consts + Mul
test_data_1D = [
dict(x_shape=[1], y_shape=[1]),
pytest.param(dict(x_shape=[3], y_shape=[3]), marks=pytest.mark.xfail(reason="*-19180"))
]
@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,
use_new_frontend, use_old_api):
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, use_old_api=use_old_api)
test_data_2D = [
dict(x_shape=[1, 1], y_shape=[1, 1]),
dict(x_shape=[1, 3], y_shape=[1, 3]),
pytest.param(dict(x_shape=[3, 1], y_shape=[3, 1]),
marks=pytest.mark.xfail(reason="*-19180")),
dict(x_shape=[2, 3], y_shape=[2, 3])
]
@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,
use_new_frontend, use_old_api):
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, use_old_api=use_old_api)
test_data_3D = [
dict(x_shape=[1, 1, 1], y_shape=[1, 1, 1]),
pytest.param(dict(x_shape=[1, 3, 1], y_shape=[1, 3, 1]),
marks=pytest.mark.xfail(reason="*-19053")),
pytest.param(dict(x_shape=[1, 1, 3], y_shape=[1, 1, 3]),
marks=[pytest.mark.xfail(reason="*-19053"),
pytest.mark.xfail(reason="*-18830")]),
pytest.param(dict(x_shape=[1, 3, 224], y_shape=[1, 3, 224]),
marks=pytest.mark.xfail(reason="*-19053"))
]
@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,
use_new_frontend, use_old_api):
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, use_old_api=use_old_api)
test_data_4D = [
dict(x_shape=[1, 1, 1, 1], y_shape=[1, 1, 1, 1]),
dict(x_shape=[1, 3, 1, 1], y_shape=[1, 3, 1, 1]),
pytest.param(dict(x_shape=[1, 1, 1, 3], y_shape=[1, 1, 1, 3]),
marks=pytest.mark.xfail(reason="*-19180")),
dict(x_shape=[1, 3, 222, 224], y_shape=[1, 3, 222, 224])
]
@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,
use_new_frontend, use_old_api):
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, use_old_api=use_old_api)
test_data_5D = [
dict(x_shape=[1, 1, 1, 1, 1], y_shape=[1, 1, 1, 1, 1]),
dict(x_shape=[1, 3, 1, 1, 1], y_shape=[1, 3, 1, 1, 1]),
pytest.param(dict(x_shape=[1, 1, 1, 1, 3], y_shape=[1, 1, 1, 1, 3]),
marks=pytest.mark.xfail(reason="*-19180")),
dict(x_shape=[1, 3, 50, 100, 224], y_shape=[1, 3, 50, 100, 224])
]
# 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,
use_new_frontend, use_old_api):
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, use_old_api=use_old_api)
###############################################################################################
# #
# Broadcast cases #
# #
###############################################################################################
test_data_broadcast_1D = [ # Power
dict(x_shape=[3], y_shape=[1])
]
@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, use_new_frontend, use_old_api):
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, use_old_api=use_old_api)
test_data_broadcast_2D = [
dict(x_shape=[1, 1], y_shape=[1]),
dict(x_shape=[1, 3], y_shape=[1]),
dict(x_shape=[1, 3], y_shape=[3]),
dict(x_shape=[3, 1], y_shape=[3]),
pytest.param(dict(x_shape=[3, 1], y_shape=[1, 3, 1, 1]),
marks=pytest.mark.xfail(reason="*-19051"))
]
@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, use_new_frontend, use_old_api):
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, use_old_api=use_old_api)
test_data_broadcast_3D = [
dict(x_shape=[1, 1, 1], y_shape=[1]),
pytest.param(dict(x_shape=[1, 3, 1], y_shape=[1]),
marks=pytest.mark.xfail(reason="*-19053")),
pytest.param(dict(x_shape=[1, 3, 1], y_shape=[3]),
marks=pytest.mark.xfail(reason="*-19053")),
pytest.param(dict(x_shape=[1, 3, 1], y_shape=[3, 1]),
marks=pytest.mark.xfail(reason="*-19053")),
pytest.param(dict(x_shape=[1, 1, 1], y_shape=[3, 1]),
marks=pytest.mark.xfail(reason="*-19053")),
pytest.param(dict(x_shape=[3, 1, 224], y_shape=[1, 3, 224]),
marks=pytest.mark.xfail(reason="*-19053")),
pytest.param(dict(x_shape=[2, 3, 1], y_shape=[1, 3, 2]),
marks=pytest.mark.xfail(reason="*-19053")),
]
# 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, use_new_frontend, use_old_api):
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, use_old_api=use_old_api)
test_data_broadcast_4D = [
dict(x_shape=[1, 1, 1, 1], y_shape=[1]),
dict(x_shape=[1, 3, 1, 1], y_shape=[1]),
dict(x_shape=[1, 3, 1, 1], y_shape=[3]),
dict(x_shape=[1, 3, 100, 224], y_shape=[3]),
dict(x_shape=[1, 1, 1, 3], y_shape=[3]),
dict(x_shape=[1, 3, 1, 1], y_shape=[3, 1]),
dict(x_shape=[1, 2, 1, 3], y_shape=[3, 1, 2]),
dict(x_shape=[1, 2, 1, 3], y_shape=[1, 3, 2]),
dict(x_shape=[1, 3, 100, 224], y_shape=[1, 1, 1, 224]),
dict(x_shape=[2, 3, 1, 2], y_shape=[1, 3, 2, 1])
]
@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, use_new_frontend, use_old_api):
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, use_old_api=use_old_api)
test_data_broadcast_5D = [
dict(x_shape=[1, 1, 1, 1, 1], y_shape=[1]),
dict(x_shape=[1, 3, 1, 1, 1], y_shape=[1, 1]),
pytest.param(dict(x_shape=[1, 3, 1, 1, 1], y_shape=[3]), marks=pytest.mark.precommit_tf_fe),
dict(x_shape=[1, 1, 1, 1, 3], y_shape=[3]),
dict(x_shape=[1, 3, 1, 1, 1], y_shape=[3, 1]),
dict(x_shape=[1, 3, 1, 1, 2], y_shape=[1, 3, 2]),
dict(x_shape=[1, 3, 5, 1, 2], y_shape=[5, 3, 2, 1]),
dict(x_shape=[1, 3, 50, 100, 224], y_shape=[1, 1, 1, 1, 224]),
dict(x_shape=[2, 3, 1, 2, 1], y_shape=[1, 3, 2, 1, 1])
]
@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, use_new_frontend, use_old_api):
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, use_old_api=use_old_api)