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:
parent
371eaba7cd
commit
aecbd549f8
@ -75,7 +75,10 @@ Framework-agnostic parameters:
|
|||||||
shape to the layout required by Inference Engine
|
shape to the layout required by Inference Engine
|
||||||
(N,C,H,W). The shape should not contain undefined
|
(N,C,H,W). The shape should not contain undefined
|
||||||
dimensions (? or -1) and should fit the dimensions
|
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
|
are multiple inputs in the model, --input_shape should
|
||||||
contain definition of shape for each input separated
|
contain definition of shape for each input separated
|
||||||
by a comma, for example: [1,3,227,227],[2,4] for a
|
by a comma, for example: [1,3,227,227],[2,4] for a
|
||||||
|
@ -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.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.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.graph import Node
|
||||||
from openvino.tools.mo.utils.ir_reader.extender import Extender
|
from openvino.tools.mo.utils.ir_reader.extender import Extender
|
||||||
|
|
||||||
@ -18,7 +19,29 @@ class Parameter_extender(Extender):
|
|||||||
op.shape = int64_array([])
|
op.shape = int64_array([])
|
||||||
else:
|
else:
|
||||||
Extender.attr_to_list(op, 'shape')
|
Extender.attr_to_list(op, 'shape')
|
||||||
|
shape = op.shape.copy()
|
||||||
|
has_shapes_with_boundaries = False
|
||||||
for i, dim in enumerate(op.shape):
|
for i, dim in enumerate(op.shape):
|
||||||
if dim == -1 or (isinstance(dim, str) and ".." in dim):
|
if dim == -1 or (isinstance(dim, str) and ".." in dim):
|
||||||
op.shape[i] = -1
|
shape[i] = -1
|
||||||
op.shape = shape_array([d if d != -1 else dynamic_dimension_value for d in op.shape])
|
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
|
||||||
|
Loading…
Reference in New Issue
Block a user