* Specification for the NMS-4 operation (updated shape infer function) * Enabled NMS-4 in the Model Optimizer * Changed opset version for NMS with dynamic outputs and namespace to be "dynamic" * Added NMS-4 * Added opset4 to the nGraph * Added unit tests for NMS-4 type infer * Renamed UpgradeNMS3ToNMS4 to UpgradeNMS3ToNMSDynamic. Added stub for ConvertNMS4ToLegacy * Make IE aware of opset4 ops * Updated NMSIE to have different shape infer function based on the NMS it was converted from. Implemented NMS4->NMSIE conversion * Apply code style * Updated StaticShapeNonMaximumSuppression op in the VPU * Introduced new version of NMSIE operation with shape infer function from v4::NMS * Fixed dynamicToStaticNonMaxSuppression transformation * Added new version of NMSIE op with updated shape infer function * Fixed NMS4 to NMSIE2 transformation * Fixed constructors for nGraph ops v4::NM and dynamic::NMS * Updated text in the opset4 specification document * Code style fixes * Fixed constructors for StaticShapeNMS + fixed test * Minor change to the NMS op in the MO * Fixed typo in the dynamic_to_static_shape_non_max_suppression transformation * Removed redundant checks * Refactored NMS infer and validate functions * Added more checks to the validate_and_infer_types functions for NMS-3 and NMS-4 * Fixed compilation issue on Windows for op NMS * Code style fixes * Fixed typos in the NMSIE and NMSIE2 to CNNLayer op conversion * Fixed typo in the ie_cnn_layer_builder_ngraph.cpp * Fixed the NMSToLegacyNMS transformation. Added unit tests * Apply code review comments * Refactored NMSIE to use visitors * Removed calling ConvertNMS4ToLegacy in the common optimizations * Moved NMS4ToNMSLegacy to convert1_to_legacy group of transformations * Removed useless include statement * Removed copy-paste issue Co-authored-by: Evgeny Lazarev <elazarev.nnov@gmail.com>
93 lines
3.7 KiB
Python
93 lines
3.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 unittest
|
|
|
|
import numpy as np
|
|
|
|
from extensions.ops.non_max_suppression import NonMaxSuppression
|
|
from mo.front.common.partial_infer.utils import int64_array
|
|
from mo.graph.graph import Node
|
|
from mo.utils.unittest.graph import build_graph, regular_op_with_shaped_data, valued_const_with_data, result, connect
|
|
|
|
|
|
class TestNonMaxSuppressionInfer(unittest.TestCase):
|
|
def setUp(self):
|
|
nodes = {
|
|
**regular_op_with_shaped_data('boxes', [10, 100, 4], {'type': 'Parameter'}),
|
|
**regular_op_with_shaped_data('scores', [10, 5, 100], {'type': 'Parameter'}),
|
|
**valued_const_with_data('max_output_per_class', int64_array(7)),
|
|
**regular_op_with_shaped_data('nms', None, {'op': 'NonMaxSuppression', 'type': 'NonMaxSuppression',
|
|
'name': 'nms'}),
|
|
**result('output'),
|
|
}
|
|
|
|
self.graph = build_graph(nodes, [
|
|
*connect('boxes', '0:nms'),
|
|
*connect('scores', '1:nms'),
|
|
*connect('max_output_per_class', '2:nms'),
|
|
*connect('nms', 'output'),
|
|
], nodes_with_edges_only=True)
|
|
|
|
def test_nms_infer_opset1(self):
|
|
nms_node = Node(self.graph, 'nms')
|
|
nms_node['version'] = 'opset1'
|
|
NonMaxSuppression.infer(nms_node)
|
|
NonMaxSuppression.type_infer(nms_node)
|
|
|
|
self.assertTrue(np.array_equal(nms_node.out_port(0).data.get_shape(), [100, 3]))
|
|
self.assertTrue(nms_node.out_port(0).get_data_type() == np.int64)
|
|
|
|
def test_nms_infer_i64_opset3(self):
|
|
nms_node = Node(self.graph, 'nms')
|
|
nms_node['version'] = 'opset3'
|
|
nms_node['output_type'] = np.int64
|
|
NonMaxSuppression.infer(nms_node)
|
|
NonMaxSuppression.type_infer(nms_node)
|
|
|
|
self.assertTrue(np.array_equal(nms_node.out_port(0).data.get_shape(), [100, 3]))
|
|
self.assertTrue(nms_node.out_port(0).get_data_type() == np.int64)
|
|
|
|
def test_nms_infer_i32_opset3(self):
|
|
nms_node = Node(self.graph, 'nms')
|
|
nms_node['version'] = 'opset3'
|
|
nms_node['output_type'] = np.int32
|
|
NonMaxSuppression.infer(nms_node)
|
|
NonMaxSuppression.type_infer(nms_node)
|
|
|
|
self.assertTrue(np.array_equal(nms_node.out_port(0).data.get_shape(), [100, 3]))
|
|
self.assertTrue(nms_node.out_port(0).get_data_type() == np.int32)
|
|
|
|
def test_nms_infer_i32_opset4(self):
|
|
nms_node = Node(self.graph, 'nms')
|
|
nms_node['version'] = 'opset4'
|
|
nms_node['output_type'] = np.int32
|
|
NonMaxSuppression.infer(nms_node)
|
|
NonMaxSuppression.type_infer(nms_node)
|
|
|
|
self.assertTrue(np.array_equal(nms_node.out_port(0).data.get_shape(), [10 * 5 * 7, 3]))
|
|
self.assertTrue(nms_node.out_port(0).get_data_type() == np.int32)
|
|
|
|
def test_nms_infer_i64_opset4(self):
|
|
nms_node = Node(self.graph, 'nms')
|
|
nms_node['version'] = 'opset4'
|
|
nms_node['output_type'] = np.int64
|
|
NonMaxSuppression.infer(nms_node)
|
|
NonMaxSuppression.type_infer(nms_node)
|
|
|
|
self.assertTrue(np.array_equal(nms_node.out_port(0).data.get_shape(), [10 * 5 * 7, 3]))
|
|
self.assertTrue(nms_node.out_port(0).get_data_type() == np.int64)
|