Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed scalar creating in tf.Graph decoder #19735

Merged
merged 5 commits into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@ def get_attribute(self, name):
if self.m_parsed_content.size == 1:
if isinstance(self.m_parsed_content, np.ndarray):
return OVAny(Tensor(self.m_parsed_content))
return OVAny(Tensor(np.array([self.m_parsed_content]), shape=[1]))
self.m_parsed_content = np.array(self.m_parsed_content)
return OVAny(Tensor(self.m_parsed_content))
ov_tensor = Tensor(self.m_parsed_content, shared_memory=self.m_shared_memory)
popovaan marked this conversation as resolved.
Show resolved Hide resolved
ov_tensor = OVAny(ov_tensor)
return ov_tensor
popovaan marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
41 changes: 41 additions & 0 deletions tests/layer_tests/ovc_python_api_tests/test_tf.py
Original file line number Diff line number Diff line change
Expand Up @@ -819,6 +819,47 @@ def test_memory_loss(self, ie_device, precision, ir_version, temp_dir):
assert CommonLayerTest().compare_ie_results_with_framework(ov_infer2, {"add:0": fw_infer2}, eps)
assert CommonLayerTest().compare_ie_results_with_framework(ov_infer1, {"add:0": [2.6, 9.6, 12.4]}, eps)

def test_scalar(self, ie_device, precision, ir_version, temp_dir):
import tensorflow as tf
tf.compat.v1.reset_default_graph()

from openvino.tools.ovc import convert_model
from openvino.runtime import compile_model

class LayerModel(tf.Module):
def __init__(self):
super(LayerModel, self).__init__()
self.var1 = tf.Variable(-0.5, name='var1')
self.var2 = tf.Variable(1.7, name='var2')


@tf.function
def sub_function(self, input):
return input + self.var1 + self.var2

@tf.function(input_signature=[tf.TensorSpec([], tf.float32)])
def __call__(self, input):
return self.sub_function(input)

if precision == 'FP32':
eps = 1e-4
else:
eps = 5e-2

test_input = np.array(2.0).astype(np.float32)

# Convert model to OV
fw_model = LayerModel()
ov_model = convert_model(fw_model)
cmp_model = compile_model(ov_model)

# Check model inference
ov_infer = cmp_model(test_input, ie_device)
fw_infer = fw_model(test_input).numpy()

assert CommonLayerTest().compare_ie_results_with_framework(ov_infer, {"Identity:0": fw_infer}, eps)
assert CommonLayerTest().compare_ie_results_with_framework(ov_infer, {"Identity:0": 3.2}, eps)


class TFConvertTest(unittest.TestCase):
@pytest.mark.nightly
Expand Down