Files
openvino/model-optimizer/mo/utils/ir_reader/extender.py
T
Anton ChetverikovandAnastasia Popova 2c4afd8cd4 Tensor names support in MO IR Reader (#4194)
* Added attributes save modes

* Added tensor names to IR

* Reformat code

* Add support for tensor names in MO IR Reader

* Unit tests and code refactoring

* Fixed error

* Code refactoring

* Code refactoring

* Code refactoring

* Error fixed

* Error fixed

* Bug fixed

* Bug fixed

* Additional unit tests and comments

* Small update

* Update fake infer function

* Update names restoring

* optimize imports

* Add support for old-style constants and for commas in reader

* Added dest mode in Fuse Mul

* Update default values

* Fix missed debug info in some specific cases

* Fix a lot of issues with missedand wrong names provoding

* Resolve review comments

* Update test IR's

* Refactor and simplify code

* More simplification

* Remove unneccessary changes

* model-optimizer/mo/utils/ir_reader/layer_to_class_test.py

* Add separate tests for names restoring

* Update copyright year

* Apply review comments

Co-authored-by: Anastasia Popova <anastasia.popova@intel.com>
2021-02-18 10:38:04 +03:00

56 lines
1.8 KiB
Python

"""
Copyright (C) 2018-2021 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""
import logging as log
from mo.front.common.partial_infer.utils import int64_array
from mo.utils import class_registration
from mo.utils.graph import Node
class Extender(object):
registered_ops = {}
registered_cls = []
# Add the derived class to excluded_classes if one should not be registered in registered_ops
excluded_classes = []
@staticmethod
def extend(op: Node):
pass
@staticmethod
def get_extender_class_by_name(name: str):
return __class__.registered_ops[name]
@classmethod
def class_type(cls):
return class_registration.ClassType.IR_READER_EXTENDER
@staticmethod
def attr_to_list(node: Node, attribute: str):
if not node.has_valid(attribute):
log.warning('Attribute {} missed in node {} with type {}!'.format(attribute, node.soft_get('name'),
node.soft_get('type')))
elif not isinstance(node[attribute], list):
node[attribute] = [node[attribute]]
@staticmethod
def const_shape_infer(node: Node):
i = len(node.in_nodes())
for num in node.out_nodes():
node.out_node(num).shape = int64_array(node.ports[i][0])
i += 1