Files
openvino/model-optimizer/extensions/front/non_max_suppression_normalize.py
Vladimir Gavrilov da47cb05be Extend MO for the operation NonMaxSuppression-5 (#2356)
* Commit.

* Written draft of NonMaxSuppression-5 class.

* Written conversion of the value of the second output  of MO NonMaxSuppression-5 into TF format.

* Fixed type infer for the port 1 of NonMaxSuppression-5.

* Added Reshape to [1] for 0D inputs of NMS-5.

* Small fix.

* Corrected assert for number of inputs.

* Fixed docstrings for transformations TFNonMaxSuppressionNormalize and NonMaxSuppressionNormalize.

* Now the transformation TFNonMaxSuppressionNormalize uses find_and_replace_pattern().

* Moved model-optimizer/extensions/front/onnx/non_max_suppression_normalize.py to model-optimizer/extensions/front/non_max_suppression_normalize.py, to delete duplicate code.

* Deleted commented code.

* Fixed BOM-file.

* Deleted out_ports_count from NMS.

* Fixes in type_infer of NMS-5.

* Small changes.

* Added some comment.

* Small fix.

* Some fixes.
2020-11-06 21:00:55 +03:00

40 lines
1.8 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.
"""
from mo.front.common.partial_infer.utils import int64_array
from mo.front.common.replacement import FrontReplacementSubgraph
from mo.front.tf.graph_utils import create_op_node_with_second_input
from mo.graph.graph import Graph
from mo.ops.reshape import Reshape
class NonMaxSuppressionNormalize(FrontReplacementSubgraph):
"""
The transformation converts several inputs of the NonMaxSuppression layer to be 1D instead of 0D with shape [1] to
comply with the layer specification.
"""
enabled = True
def find_and_replace_pattern(self, graph: Graph):
for nms in graph.get_op_nodes(op='NonMaxSuppression'):
# make inputs 2 to 5 to have shape [1] instead of [0] (convert 0D to 1D)
nms_name = nms.soft_get('name', nms.id)
for port_id in range(2, 6):
if port_id in nms.in_ports() and not nms.in_port(port_id).disconnected():
reshape_1d = create_op_node_with_second_input(graph, Reshape, int64_array([1]),
{'name': nms_name + '/Reshape_1D_{}'.format(port_id)})
nms.in_port(port_id).get_connection().insert_node(reshape_1d)