2 Copyright (c) 2019 Intel Corporation
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
8 http://www.apache.org/licenses/LICENSE-2.0
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
17 from mo.front.extractor import FrontExtractorOp
18 from mo.front.onnx.extractors.utils import onnx_attr
19 from mo.ops.op import Op
20 from mo.utils.error import Error
23 class DetectionOutputFrontExtractor(FrontExtractorOp):
24 op = 'DetectionOutput'
29 nms_threshold = onnx_attr(node, 'nms_threshold', 'f', default=0.0)
30 eta = onnx_attr(node, 'eta', 'f', default=0.0)
31 top_k = onnx_attr(node, 'top_k', 'i', default=-1)
34 b"CORNER": "caffe.PriorBoxParameter.CORNER",
35 b"CENTER_SIZE": "caffe.PriorBoxParameter.CENTER_SIZE",
38 code_type = onnx_attr(node, 'code_type', 's', default=code_type_values[b"CORNER"])
40 code_type = code_type_values[code_type]
42 raise Error("Incorrect value of code_type parameter {}".format(code_type))
44 resize_mode_values = {
46 b"WARP": "caffe.ResizeParameter.WARP",
47 b"FIT_SMALL_SIZE": "caffe.ResizeParameter.FIT_SMALL_SIZE",
48 b"FIT_LARGE_SIZE_AND_PAD": "caffe.ResizeParameter.FIT_LARGE_SIZE_AND_PAD",
50 resize_mode = onnx_attr(node, 'resize_mode', 's', default=b"")
52 resize_mode = resize_mode_values[resize_mode]
54 raise Error("Incorrect value of resize_mode parameter {}".format(resize_mode))
58 b"CONSTANT": "caffe.ResizeParameter.CONSTANT",
59 b"MIRRORED": "caffe.ResizeParameter.MIRRORED",
60 b"REPEAT_NEAREST": "caffe.ResizeParameter.REPEAT_NEAREST"
62 pad_mode = onnx_attr(node, 'pad_mode', 's', default=b"")
64 pad_mode = pad_mode_values[pad_mode]
66 raise Error("Incorrect value of pad_mode parameter {}".format(pad_mode))
68 interp_mode_values = {
70 b"LINEAR": "caffe.ResizeParameter.LINEAR",
71 b"AREA": "caffe.ResizeParameter.AREA",
72 b"NEAREST": "caffe.ResizeParameter.NEAREST",
73 b"CUBIC": "caffe.ResizeParameter.CUBIC",
74 b"LANCZOS4": "caffe.ResizeParameter.LANCZOS4"
76 interp_mode = onnx_attr(node, 'interp_mode', 's', default=b"")
78 interp_mode = interp_mode_values[interp_mode]
80 raise Error("Incorrect value of interp_mode parameter {}".format(interp_mode))
83 'num_classes': onnx_attr(node, 'num_classes', 'i', default=0),
84 'share_location': onnx_attr(node, 'share_location', 'i', default=0),
85 'background_label_id': onnx_attr(node, 'background_label_id', 'i', default=0),
86 'code_type': code_type,
87 'variance_encoded_in_target': onnx_attr(node, 'variance_encoded_in_target', 'i', default=0),
88 'keep_top_k': onnx_attr(node, 'keep_top_k', 'i', default=0),
89 'confidence_threshold': onnx_attr(node, 'confidence_threshold', 'f', default=0),
90 'visualize_threshold': onnx_attr(node, 'visualize_threshold', 'f', default=0.6),
92 'nms_threshold': nms_threshold,
95 # save_output_param.resize_param
96 'prob': onnx_attr(node, 'prob', 'f', default=0),
97 'resize_mode': resize_mode,
98 'height': onnx_attr(node, 'height', 'i', default=0),
99 'width': onnx_attr(node, 'width', 'i', default=0),
100 'height_scale': onnx_attr(node, 'height_scale', 'i', default=0),
101 'width_scale': onnx_attr(node, 'width_scale', 'i', default=0),
102 'pad_mode': pad_mode,
103 'pad_value': onnx_attr(node, 'pad_value', 's', default=""),
104 'interp_mode': interp_mode,
105 'input_width': onnx_attr(node, 'input_width', 'i', default=1),
106 'input_height': onnx_attr(node, 'input_height', 'i', default=1),
107 'normalized': onnx_attr(node, 'normalized', 'i', default=1),
110 # update the attributes of the node
111 Op.get_op_class_by_name(__class__.op).update_node_stat(node, attrs)
112 return __class__.enabled