Support of partial shapes with boundaries in MO IR reader. (#9223)

* Added support of partial shapes boundaries in MO IR reader.

* Added comments.
This commit is contained in:
Anastasia Popova 2022-01-10 14:36:36 +03:00 committed by GitHub
parent 371eaba7cd
commit aecbd549f8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 3 deletions

View File

@ -75,7 +75,10 @@ Framework-agnostic parameters:
shape to the layout required by Inference Engine
(N,C,H,W). The shape should not contain undefined
dimensions (? or -1) and should fit the dimensions
defined in the input operation of the graph. If there
defined in the input operation of the graph. Boundaries
of undefined dimension can be specified with ellipsis,
for example [1,1..10,128,128]. One boundary can be undefined,
for example [1,..100] or [1,3,1..,1..]. If there
are multiple inputs in the model, --input_shape should
contain definition of shape for each input separated
by a comma, for example: [1,3,227,227],[2,4] for a

View File

@ -3,6 +3,7 @@
from openvino.tools.mo.front.common.partial_infer.utils import int64_array, shape_array, dynamic_dimension_value
from openvino.tools.mo.middle.passes.convert_data_type import destination_type_to_np_data_type
from openvino.tools.mo.utils.cli_parser import parse_dimension
from openvino.tools.mo.utils.graph import Node
from openvino.tools.mo.utils.ir_reader.extender import Extender
@ -18,7 +19,29 @@ class Parameter_extender(Extender):
op.shape = int64_array([])
else:
Extender.attr_to_list(op, 'shape')
shape = op.shape.copy()
has_shapes_with_boundaries = False
for i, dim in enumerate(op.shape):
if dim == -1 or (isinstance(dim, str) and ".." in dim):
op.shape[i] = -1
op.shape = shape_array([d if d != -1 else dynamic_dimension_value for d in op.shape])
shape[i] = -1
if ".." in dim:
has_shapes_with_boundaries = True
shape = shape_array([d if d != -1 else dynamic_dimension_value for d in shape])
if has_shapes_with_boundaries:
shape_list = []
for i, dim in enumerate(op.shape):
if not isinstance(dim, str):
shape_list.append(dim)
else:
shape_list.append(parse_dimension(dim))
# This value is used only for serialization of partial shapes with boundaries
# for Parameter node.
# 'user_shape' is not used in shape inference, as propagation of partial shapes with boundaries
# is not implemented in MO.
op['user_shape'] = tuple(shape_list)
# If 'user_shape' is not set, 'shape' attribute is used for serialization.
# 'shape' is also used for shape inference.
op.shape = shape