Fix MO IR Reader for Eye op (#15996)
* Fix MO IR Reader for Eye op * Fix eye value infer * Remove debug output * Add test for eye value infer * Fix bom tests * Fix alphabetical order
This commit is contained in:
@@ -1054,6 +1054,7 @@ openvino/tools/mo/utils/ir_reader/extenders/deformable_convolution_extender.py
|
||||
openvino/tools/mo/utils/ir_reader/extenders/einsum_extender.py
|
||||
openvino/tools/mo/utils/ir_reader/extenders/experimental_extender.py
|
||||
openvino/tools/mo/utils/ir_reader/extenders/ExtractImagePatches_extender.py
|
||||
openvino/tools/mo/utils/ir_reader/extenders/eye_extender.py
|
||||
openvino/tools/mo/utils/ir_reader/extenders/fakequantize_extender.py
|
||||
openvino/tools/mo/utils/ir_reader/extenders/GRUCell_extender.py
|
||||
openvino/tools/mo/utils/ir_reader/extenders/GRUSequence_extender.py
|
||||
|
||||
@@ -89,7 +89,7 @@ class Eye(Op):
|
||||
|
||||
if is_fully_defined(output_shape) and diagonal_index is not None:
|
||||
tile_shape = [*batch_shape, 1, 1]
|
||||
one_matrix = np.eye(num_rows, M=num_columns, k=diagonal_index, dtype=node.output_type)
|
||||
one_matrix = np.eye(num_rows, M=num_columns, k=np.array(diagonal_index).item(), dtype=node.output_type)
|
||||
output_value = np.tile(one_matrix, tile_shape)
|
||||
node.out_port(0).data.set_value(shape_array(output_value))
|
||||
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
# Copyright (C) 2018-2023 Intel Corporation
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
from openvino.tools.mo.middle.passes.convert_data_type import destination_type_to_np_data_type
|
||||
|
||||
from openvino.tools.mo.utils.graph import Node
|
||||
from openvino.tools.mo.utils.ir_reader.extender import Extender
|
||||
|
||||
|
||||
class EyeExtender(Extender):
|
||||
op = 'Eye'
|
||||
|
||||
@staticmethod
|
||||
def extend(op: Node):
|
||||
if op.has_valid('output_type'):
|
||||
op['output_type'] = destination_type_to_np_data_type(op.output_type)
|
||||
@@ -9,8 +9,9 @@ from generator import generator, generate
|
||||
from openvino.tools.mo.ops.eye import Eye
|
||||
from openvino.tools.mo.front.common.partial_infer.utils import int64_array
|
||||
from openvino.tools.mo.graph.graph import Node
|
||||
from unit_tests.utils.graph import build_graph_with_attrs
|
||||
from openvino.tools.mo.front.common.partial_infer.utils import int64_array, shape_array, dynamic_dimension_value
|
||||
from unit_tests.utils.graph import build_graph_with_attrs, build_graph
|
||||
from openvino.tools.mo.front.common.partial_infer.utils import int64_array, dynamic_dimension_value
|
||||
from unit_tests.utils.graph import valued_const_with_data, result, regular_op_with_empty_data, connect
|
||||
|
||||
|
||||
graph_node_attrs_sizes = [
|
||||
@@ -48,6 +49,7 @@ graph_edges_sizes = [
|
||||
('eye_op_data', 'op_output'),
|
||||
]
|
||||
|
||||
|
||||
@generator
|
||||
class TestComplexOp(unittest.TestCase):
|
||||
@generate(*[
|
||||
@@ -62,11 +64,11 @@ class TestComplexOp(unittest.TestCase):
|
||||
graph = build_graph_with_attrs(nodes_with_attrs=graph_node_attrs_sizes,
|
||||
edges_with_attrs=graph_edges_sizes,
|
||||
update_nodes_attributes=[
|
||||
('num_rows_data', {'shape': int64_array(input_shape), 'value': num_rows}),
|
||||
('num_columns_data', {'shape': int64_array(input_shape), 'value': num_cols}),
|
||||
('diagonal_index_data', {'shape': int64_array(input_shape)}),
|
||||
('batch_shape_data', {'shape': int64_array([len(batch_shape)]), 'value': batch_shape}),
|
||||
('eye_op', {'output_type': np.float32}),
|
||||
('num_rows_data', {'shape': int64_array(input_shape), 'value': num_rows}),
|
||||
('num_columns_data', {'shape': int64_array(input_shape), 'value': num_cols}),
|
||||
('diagonal_index_data', {'shape': int64_array(input_shape)}),
|
||||
('batch_shape_data', {'shape': int64_array([len(batch_shape)]), 'value': batch_shape}),
|
||||
('eye_op', {'output_type': np.float32}),
|
||||
])
|
||||
node = Node(graph, 'eye_op')
|
||||
Eye.infer(node)
|
||||
@@ -75,3 +77,31 @@ class TestComplexOp(unittest.TestCase):
|
||||
|
||||
self.assertTrue(np.array_equal(graph.node['eye_op_data']['shape'], output_shape),
|
||||
msg.format(output_shape, graph.node['eye_op_data']['shape']))
|
||||
|
||||
def test_value_inference(self):
|
||||
graph_node_attrs_sizes = {
|
||||
**valued_const_with_data('num_rows', int64_array([128])),
|
||||
**valued_const_with_data('num_columns', int64_array([128])),
|
||||
**valued_const_with_data('diagonal_index', int64_array([0])),
|
||||
**valued_const_with_data('batch_shape', int64_array([])),
|
||||
**regular_op_with_empty_data('eye_op', {'op': 'Eye', 'output_type': np.float32}),
|
||||
**result('res'),
|
||||
}
|
||||
graph_edges_sizes = [
|
||||
*connect('num_rows', '0:eye_op'),
|
||||
*connect('num_columns', '1:eye_op'),
|
||||
*connect('diagonal_index', '2:eye_op'),
|
||||
*connect('batch_shape', '3:eye_op'),
|
||||
*connect('eye_op', 'res'),
|
||||
]
|
||||
graph = build_graph(
|
||||
graph_node_attrs_sizes, graph_edges_sizes)
|
||||
node = Node(graph, 'eye_op')
|
||||
Eye.infer(node)
|
||||
output_value = np.eye(int64_array(128), M=int64_array(
|
||||
128), k=int64_array(0), dtype=np.float32)
|
||||
|
||||
msg = "Eye operation infer failed for case: expected_value={}, actual_value={}"
|
||||
|
||||
self.assertTrue(np.array_equal(graph.node['eye_op_d']['value'], output_value),
|
||||
msg.format(output_value, graph.node['eye_op_d']['value']))
|
||||
|
||||
Reference in New Issue
Block a user