Skip to content

Commit 4436842

Browse files
add typing + fix str
Signed-off-by: Ashwin Vaidya <[email protected]>
1 parent 014d710 commit 4436842

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

model_api/python/model_api/models/detection_model.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#
55

66
from .image_model import ImageModel
7+
from .result_types import Detection
78
from .types import ListValue, NumericalValue, StringValue
89
from .utils import load_labels
910

@@ -37,6 +38,7 @@ def __init__(self, inference_adapter, configuration: dict = {}, preload=False):
3738
"""
3839
super().__init__(inference_adapter, configuration, preload)
3940
self.path_to_labels: str
41+
self.confidence_threshold: float
4042
if not self.image_blob_name:
4143
self.raise_error(
4244
f"The Wrapper supports only one image input, but {len(self.image_blob_names)} found",
@@ -63,7 +65,7 @@ def parameters(cls):
6365

6466
return parameters
6567

66-
def _resize_detections(self, detections, meta):
68+
def _resize_detections(self, detections: list[Detection], meta):
6769
"""Resizes detection bounding boxes according to initial image shape.
6870
6971
It implements image resizing depending on the set `resize_type`(see `ImageModel` for details).
@@ -117,7 +119,7 @@ def _clamp_and_round(val, min_value, max_value):
117119

118120
return detections
119121

120-
def _filter_detections(self, detections, box_area_threshold=0.0):
122+
def _filter_detections(self, detections: list[Detection], box_area_threshold=0.0):
121123
"""Filters detections by confidence threshold and box size threshold
122124
123125
Args:
@@ -138,7 +140,7 @@ def _filter_detections(self, detections, box_area_threshold=0.0):
138140

139141
return filtered_detections
140142

141-
def _add_label_names(self, detections):
143+
def _add_label_names(self, detections: list[Detection]):
142144
"""Adds labels names to detections if they are available
143145
144146
Args:

model_api/python/model_api/models/result_types/segmentation.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ def __init__(
3838
self.mask = mask
3939

4040
def __str__(self):
41-
return f"{super().__str__()}, {(self.mask > 0.5).sum()}"
41+
return (
42+
f"{self.xmin}, {self.ymin}, {self.xmax}, {self.ymax}, {self.id} ({self.str_label}): {self.score:.3f}"
43+
f", {(self.mask > 0.5).sum()}"
44+
)
4245

4346

4447
class SegmentedObjectWithRects(SegmentedObject):

0 commit comments

Comments
 (0)