Skip to content

Commit 1fb39bc

Browse files
committed
Update python implementation
1 parent f4c7525 commit 1fb39bc

File tree

2 files changed

+23
-22
lines changed

2 files changed

+23
-22
lines changed

model_api/python/model_api/models/detection_model.py

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -104,34 +104,34 @@ def _resize_detections(self, detections, meta):
104104
pad_left = (self.w - round(input_img_widht / inverted_scale_x)) // 2
105105
pad_top = (self.h - round(input_img_height / inverted_scale_y)) // 2
106106

107+
def _clamp_and_round(val, min_value, max_value):
108+
return round(max(min_value, min(max_value, val)))
109+
107110
for detection in detections:
108-
detection.xmin = round(
109-
min(
110-
max((detection.xmin * self.w - pad_left) * inverted_scale_x, 0),
111-
input_img_widht,
112-
)
111+
detection.xmin = _clamp_and_round(
112+
(detection.xmin * self.w - pad_left) * inverted_scale_x,
113+
0,
114+
input_img_widht,
113115
)
114-
detection.ymin = round(
115-
min(
116-
max((detection.ymin * self.h - pad_top) * inverted_scale_y, 0),
117-
input_img_height,
118-
)
116+
detection.ymin = _clamp_and_round(
117+
(detection.ymin * self.h - pad_top) * inverted_scale_y,
118+
0,
119+
input_img_height,
119120
)
120-
detection.xmax = round(
121-
min(
122-
max((detection.xmax * self.w - pad_left) * inverted_scale_x, 0),
123-
input_img_widht,
124-
)
121+
detection.xmax = _clamp_and_round(
122+
(detection.xmax * self.w - pad_left) * inverted_scale_x,
123+
0,
124+
input_img_widht,
125125
)
126-
detection.ymax = round(
127-
min(
128-
max((detection.ymax * self.h - pad_top) * inverted_scale_y, 0),
129-
input_img_height,
130-
)
126+
detection.ymax = _clamp_and_round(
127+
(detection.ymax * self.h - pad_top) * inverted_scale_y,
128+
0,
129+
input_img_height,
131130
)
131+
132132
return detections
133133

134-
def _filter_detections(self, detections, box_area_threshold=0):
134+
def _filter_detections(self, detections, box_area_threshold=0.0):
135135
"""Filters detections by confidence threshold and box size threshold
136136
137137
Args:

model_api/python/model_api/models/ssd.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def preprocess(self, inputs):
4141
def postprocess(self, outputs, meta):
4242
detections = self._parse_outputs(outputs)
4343
detections = self._resize_detections(detections, meta)
44-
detections = self._filter_detections(detections, 1)
44+
detections = self._filter_detections(detections, _bbox_area_threshold)
4545
detections = self._add_label_names(detections)
4646
return DetectionResult(
4747
detections,
@@ -177,5 +177,6 @@ def __call__(self, outputs):
177177
return detections
178178

179179

180+
_bbox_area_threshold = 1.0
180181
_saliency_map_name = "saliency_map"
181182
_feature_vector_name = "feature_vector"

0 commit comments

Comments
 (0)