forked from openvinotoolkit/openvino
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_tf_OnesLike.py
90 lines (77 loc) · 3.49 KB
/
test_tf_OnesLike.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
# Copyright (C) 2018-2025 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
import numpy as np
import pytest
import tensorflow as tf
from common.tf_layer_test_class import CommonTFLayerTest
class TestOnesLike(CommonTFLayerTest):
def _prepare_input(self, inputs_info):
assert 'x:0' in inputs_info
x_shape = inputs_info['x:0']
inputs_data = {}
rng = np.random.default_rng()
inputs_data['x:0'] = rng.integers(-10, 10, x_shape).astype(self.x_type)
return inputs_data
def create_ones_like_net(self, x_shape, x_type):
self.x_type = x_type
tf.compat.v1.reset_default_graph()
# Create the graph and model
with tf.compat.v1.Session() as sess:
x = tf.compat.v1.placeholder(tf.dtypes.as_dtype(x_type), x_shape, 'x')
tf.raw_ops.OnesLike(x=x)
tf.compat.v1.global_variables_initializer()
tf_net = sess.graph_def
return tf_net, None
test_data_basic = [
dict(x_shape=[], x_type=np.float32),
dict(x_shape=[2], x_type=np.int32),
dict(x_shape=[2, 3, 4], x_type=np.float32),
dict(x_shape=[1, 4, 3, 1], x_type=np.int32),
]
@pytest.mark.parametrize("params", test_data_basic)
@pytest.mark.precommit
@pytest.mark.nightly
def test_ones_like(self, params, ie_device, precision, ir_version, temp_dir,
use_legacy_frontend):
self._test(*self.create_ones_like_net(**params),
ie_device, precision, ir_version, temp_dir=temp_dir,
use_legacy_frontend=use_legacy_frontend)
class TestComplexOnesLike(CommonTFLayerTest):
def _prepare_input(self, inputs_info):
rng = np.random.default_rng()
assert 'x_real:0' in inputs_info
assert 'x_imag:0' in inputs_info
x_real_shape = inputs_info['x_real:0']
x_imag_shape = inputs_info['x_imag:0']
inputs_data = {}
inputs_data['x_real:0'] = 4 * rng.random(x_real_shape).astype(self.x_type) - 2
inputs_data['x_imag:0'] = 4 * rng.random(x_imag_shape).astype(self.x_type) - 2
return inputs_data
def create_complex_ones_like_net(self, x_shape, x_type):
self.x_type = x_type
tf.compat.v1.reset_default_graph()
# Create the graph and model
with tf.compat.v1.Session() as sess:
x_real = tf.compat.v1.placeholder(tf.dtypes.as_dtype(x_type), x_shape, 'x_real')
x_imag = tf.compat.v1.placeholder(tf.dtypes.as_dtype(x_type), x_shape, 'x_imag')
x_complex = tf.raw_ops.Complex(real=x_real, imag=x_imag)
ones_like = tf.raw_ops.OnesLike(x=x_complex)
real = tf.raw_ops.Real(input=ones_like)
img = tf.raw_ops.Imag(input=ones_like)
tf.compat.v1.global_variables_initializer()
tf_net = sess.graph_def
return tf_net, None
test_data_basic = [
dict(x_shape=[], x_type=np.float32),
dict(x_shape=[2], x_type=np.float32),
dict(x_shape=[2, 3, 4], x_type=np.float32),
dict(x_shape=[1, 4, 3, 1], x_type=np.float32),
]
@pytest.mark.parametrize("params", test_data_basic)
@pytest.mark.precommit
@pytest.mark.nightly
def test_complex_ones_like(self, params, ie_device, precision, ir_version, temp_dir,
use_legacy_frontend):
self._test(*self.create_complex_ones_like_net(**params),
ie_device, precision, ir_version, temp_dir=temp_dir,
use_legacy_frontend=use_legacy_frontend)