forked from openvinotoolkit/openvino
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_tf_GRUBlockCell.py
62 lines (50 loc) · 2.52 KB
/
test_tf_GRUBlockCell.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
# 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
rng = np.random.default_rng(2024)
class TestGRUBlockCell(CommonTFLayerTest):
def _prepare_input(self, inputs_info):
assert 'x:0' in inputs_info, "Test error: inputs_info must contain `x`"
x_shape = inputs_info['x:0']
inputs_data = {}
inputs_data['x:0'] = rng.uniform(0, 1, x_shape).astype(np.float32)
return inputs_data
def create_gru_block_cell(self, batch_size, input_size, hidden_size):
tf.compat.v1.reset_default_graph()
# Create the graph and model
with tf.compat.v1.Session() as sess:
x_shape = [batch_size, input_size]
h_prev_shape = [batch_size, hidden_size]
w_ru_shape = [input_size + hidden_size, hidden_size * 2]
w_c_shape = [input_size + hidden_size, hidden_size]
b_ru_shape = [hidden_size * 2]
b_c_shape = [hidden_size]
x = tf.compat.v1.placeholder(np.float32, x_shape, 'x')
# generate weights
h_prev = rng.uniform(0, 1, h_prev_shape).astype(np.float32)
w_ru = rng.uniform(0, 1, w_ru_shape).astype(np.float32)
w_c = rng.uniform(0, 1, w_c_shape).astype(np.float32)
b_ru = rng.uniform(0, 1, b_ru_shape).astype(np.float32)
b_c = rng.uniform(0, 1, b_c_shape).astype(np.float32)
_, _, _, h = tf.raw_ops.GRUBlockCell(x=x, h_prev=h_prev, w_ru=w_ru, w_c=w_c, b_ru=b_ru, b_c=b_c)
tf.identity(h, name='gru_block_cell')
tf.compat.v1.global_variables_initializer()
tf_net = sess.graph_def
ref_net = None
return tf_net, ref_net
@pytest.mark.parametrize('batch_size', [1, 2])
@pytest.mark.parametrize('input_size', [1, 5, 6, 12])
@pytest.mark.parametrize('hidden_size', [1, 6, 10, 12])
@pytest.mark.nightly
@pytest.mark.precommit
def test_gru_block_cell(self, batch_size, input_size, hidden_size,
ie_device, precision, ir_version, temp_dir,
use_legacy_frontend):
if ie_device == 'GPU':
pytest.skip("Skip TF GRUBlockCell test on GPU")
self._test(*self.create_gru_block_cell(batch_size, input_size, hidden_size),
ie_device, precision, temp_dir=temp_dir, ir_version=ir_version,
use_legacy_frontend=use_legacy_frontend, custom_eps=1e-3)