forked from openvinotoolkit/openvino
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_tf_Placeholder.py
55 lines (48 loc) · 2.52 KB
/
test_tf_Placeholder.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
# Copyright (C) 2018-2023 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
rng = np.random.default_rng()
class TestPlaceholder(CommonTFLayerTest):
def _prepare_input(self, inputs_info):
tensor_name = list(inputs_info.keys())[0]
x_shape = inputs_info[tensor_name]
inputs_data = {}
if self.input_type == str or self.input_type == np.str_:
strings_dictionary = ['first', 'second sentence', ' sentence 3 three', '34ferf466 23435* ', '汉语句子',
'Oferta polska',
'предложение по-русски']
inputs_data[tensor_name] = rng.choice(strings_dictionary, x_shape)
elif np.issubdtype(self.input_type, np.floating):
inputs_data[tensor_name] = rng.uniform(-5.0, 5.0, x_shape).astype(self.input_type)
elif np.issubdtype(self.input_type, np.signedinteger):
inputs_data[tensor_name] = rng.integers(-8, 8, x_shape).astype(self.input_type)
else:
inputs_data[tensor_name] = rng.integers(0, 8, x_shape).astype(self.input_type)
return inputs_data
def create_placeholder_net(self, input_shape, input_type):
dtype = input_type
if input_type == str or input_type == np.str_:
dtype = tf.string
self.input_type = input_type
tf.compat.v1.reset_default_graph()
# Create the graph and model
with tf.compat.v1.Session() as sess:
x = tf.raw_ops.Placeholder(dtype=dtype, shape=input_shape, name='x')
tf.raw_ops.Identity(input=x, name='Identityrfefef')
tf.compat.v1.global_variables_initializer()
tf_net = sess.graph_def
return tf_net, None
@pytest.mark.parametrize("input_shape", [[], [2], [3, 4], [3, 2, 1, 4]])
@pytest.mark.parametrize("input_type", [np.int8, np.uint8, np.int16,
np.int32, np.int64,
np.float16, np.float32, np.float64, str, np.str_])
@pytest.mark.precommit_tf_fe
@pytest.mark.nightly
def test_placeholder(self, input_shape, input_type, ie_device, precision, ir_version, temp_dir,
use_new_frontend):
self._test(*self.create_placeholder_net(input_shape, input_type),
ie_device, precision, ir_version, temp_dir=temp_dir,
use_new_frontend=use_new_frontend)