Files
openvino/model-optimizer/extensions/front/onnx/clip_ext.py
2020-07-06 18:10:14 +03:00

44 lines
1.7 KiB
Python

"""
Copyright (C) 2018-2020 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
import numpy as np
from mo.front.extractor import FrontExtractorOp
from mo.front.onnx.extractors.utils import onnx_attr, get_onnx_opset_version, onnx_node_has_attr
from mo.ops.clamp import Clamp, AttributedClamp
class ClipFrontExtractor(FrontExtractorOp):
op = 'Clip'
enabled = True
@classmethod
def extract(cls, node):
if get_onnx_opset_version(node) < 11:
attrs = {
'min': onnx_attr(node, 'min', 'f', np.finfo(np.float32).min),
'max': onnx_attr(node, 'max', 'f', np.finfo(np.float32).max),
}
AttributedClamp.update_node_stat(node, attrs)
else:
if onnx_node_has_attr(node, 'min') or onnx_node_has_attr(node, 'max'):
log.error("ONNX Clip-11 operation '{}' shouldn't have attributes 'min' and 'max', this may mean that "
"this operation created with older opset version.".format(
node.soft_get('name', node.id)), extra={'is_warning': True})
Clamp.update_node_stat(node)
return cls.enabled