Files
openvino/model-optimizer/extensions/front/onnx/const_ext.py
T
Alexey Suhov 6478f1742a Align copyright notice in python scripts (CVS-51320) (#4974)
* Align copyright notice in python scripts (CVS-51320)
2021-03-26 17:54:28 +03:00

42 lines
1005 B
Python

# Copyright (C) 2018-2021 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
from onnx import numpy_helper
from onnx.numpy_helper import to_array
from mo.front.extractor import FrontExtractorOp
from mo.front.onnx.extractors.utils import onnx_attr
from mo.ops.const import Const
class ConstExtractor(FrontExtractorOp):
op = 'Const'
enabled = True
@classmethod
def extract(cls, node):
value = to_array(node.pb_init)
attrs = {
'data_type': value.dtype,
'value': value
}
Const.update_node_stat(node, attrs)
return cls.enabled
class ConstantExtractor(FrontExtractorOp):
op = 'Constant'
enabled = True
@classmethod
def extract(cls, node):
pb_value = onnx_attr(node, 'value', 't')
value = numpy_helper.to_array(pb_value)
attrs = {
'data_type': value.dtype,
'value': value,
}
Const.update_node_stat(node, attrs)
return cls.enabled