forked from openvinotoolkit/openvino
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_tf_CTCGreedyDecoder.py
70 lines (53 loc) · 2.63 KB
/
test_tf_CTCGreedyDecoder.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
# Copyright (C) 2023 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
import pytest
from common.tf_layer_test_class import CommonTFLayerTest
import numpy as np
import tensorflow as tf
# Testing operation CTCGreedyDecoder
# Documentation: https://www.tensorflow.org/api_docs/python/tf/raw_ops/CTCGreedyDecoder
class TestCTCGreedyDecoder(CommonTFLayerTest):
# input_shape - shape a tensor for a decoder
# merge_repeated - bool, enables/disable merge repeated classes in decoder
# ir_version - common parameter
# use_new_frontend - common parameter
def create_ctcgreedydecoder_placeholder_const_net(self, input_shape, merge_repeated,
ir_version, use_new_frontend):
"""
Tensorflow net IR net
Placeholder->CTCLoss => Placeholder->Transpose->CTCGreedyDecoder->NotEqual->NonZero->Transpose
"""
if use_new_frontend == False:
pytest.skip('Legacy path isn\'t supported by CTCGreedyDecoder')
seq_lens = np.array([input_shape[2]], dtype=np.int32)
tf.compat.v1.reset_default_graph()
# Create the graph and model
with tf.compat.v1.Session() as sess:
tf_inputs = tf.compat.v1.placeholder(tf.float32, input_shape, "inputs")
ctc_gd = tf.raw_ops.CTCGreedyDecoder(inputs = tf_inputs, sequence_length = seq_lens, merge_repeated=merge_repeated)
tf.identity(ctc_gd[0], name='decoded_indices')
tf.compat.v1.global_variables_initializer()
tf_net = sess.graph_def
ref_net = None
return tf_net, ref_net
test_data = [
pytest.param(
dict(
input_shape = [6, 1, 4],
),
marks=pytest.mark.precommit_tf_fe),
dict(
input_shape = [10, 1, 7],
),
]
@pytest.mark.parametrize("params", test_data)
@pytest.mark.parametrize("merge_repeated", [False, True])
@pytest.mark.nightly
def test_ctcgreedydecoder_placeholder_const(self, params, merge_repeated, ie_device, precision, ir_version, temp_dir,
use_new_frontend, use_old_api):
if ie_device == 'GPU':
pytest.xfail('104860')
self._test(*self.create_ctcgreedydecoder_placeholder_const_net(**params, ir_version=ir_version,
use_new_frontend=use_new_frontend, merge_repeated=merge_repeated),
ie_device, precision, ir_version, temp_dir=temp_dir,
use_new_frontend=use_new_frontend, use_old_api=use_old_api, merge_repeated=merge_repeated)