Files
openvino/model-optimizer/extensions/front/onnx/pad_ext_test.py
Maxim Vafin d40a607ca0 Support Pad-2 in opset-11 ONNX model (#4886)
* Support Pad-2 in opset-11 ONNX model

* Add unit test for pad

* Apply review feedback
2021-03-25 12:05:28 +03:00

99 lines
2.5 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.
"""
from argparse import Namespace
import onnx
from extensions.front.onnx.pad_ext import PadFrontExtractor
from mo.graph.graph import Graph
from mo.utils.unittest.extractors import PB, BaseExtractorsTestingClass
class TestPad(BaseExtractorsTestingClass):
@staticmethod
def _create_node(pads=None, value=None, mode=None):
if pads is None:
pads = [1, 2, 3, 4]
if value is None:
value = 0.0
if mode is None:
mode = 'constant'
pb = onnx.helper.make_node(
'Pad',
pads=pads,
mode=mode,
value=value,
inputs=['a'],
outputs=['b']
)
graph = Graph()
node = PB({'pb': pb, 'graph': graph})
return node
def test_ok(self):
node = self._create_node()
PadFrontExtractor.extract(node)
self.res = node
self.expected = {
'pads': [[1, 3], [2, 4]],
'mode': 'constant',
'fill_value': 0
}
self.compare()
def test_older_pad_opset_11(self):
node = self._create_node()
node.graph.graph['fw_opset_version'] = 11
PadFrontExtractor.extract(node)
self.res = node
self.expected = {
'pads': [[1, 3], [2, 4]],
'mode': 'constant',
'fill_value': 0
}
self.compare()
def test_reflect(self):
node = self._create_node(mode='reflect')
PadFrontExtractor.extract(node)
self.res = node
self.expected = {
'pads': [[1, 3], [2, 4]],
'mode': 'reflect',
'fill_value': 0
}
self.compare()
def test_non_zero_fill_value(self):
node = self._create_node(value=1.0)
PadFrontExtractor.extract(node)
self.res = node
self.expected = {
'pads': [[1, 3], [2, 4]],
'mode': 'constant',
'fill_value': 1.0
}
self.compare()