Skip to content

Commit ed0d5bc

Browse files
bug-fix + add classification
Signed-off-by: Ashwin Vaidya <[email protected]>
1 parent 7f20029 commit ed0d5bc

File tree

3 files changed

+18
-12
lines changed

3 files changed

+18
-12
lines changed

model_api/python/model_api/models/result_types.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ def __init__(
3030
pred_mask: np.ndarray | None = None,
3131
pred_score: float | None = None,
3232
) -> None:
33+
super().__init__()
3334
self.anomaly_map = anomaly_map
3435
self.pred_boxes = pred_boxes
3536
self.pred_label = pred_label
@@ -73,6 +74,7 @@ def __init__(
7374
feature_vector: np.ndarray | None = None,
7475
raw_scores: np.ndarray | None = None,
7576
) -> None:
77+
super().__init__()
7678
self.top_labels = top_labels
7779
self.saliency_map = saliency_map
7880
self.feature_vector = feature_vector
@@ -87,7 +89,9 @@ def __str__(self) -> str:
8789
)
8890

8991
def _register_primitives(self) -> None:
90-
pass
92+
# TODO add saliency map
93+
for idx, label, confidence in self.top_labels:
94+
self._add_primitive(Label(f"Rank: {idx}, {label}: {confidence:.3f}"))
9195

9296

9397
class Detection:

model_api/python/model_api/visualizer/visualize_mixin.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@
1111
class VisualizeMixin(ABC):
1212
"""Mixin for visualization."""
1313

14-
_labels: list[Label] = []
15-
_polygons: list[Polygon] = []
16-
_overlays: list[Overlay] = []
17-
_bounding_boxes: list[BoundingBoxes] = []
18-
_registered_primitives: bool = False
14+
def __init__(self) -> None:
15+
self._labels = []
16+
self._polygons = []
17+
self._overlays = []
18+
self._bounding_boxes = []
19+
self._registered_primitives = False
1920

2021
@abstractmethod
2122
def _register_primitives(self) -> None:

model_api/python/model_api/visualizer/visualizer.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,30 +57,31 @@ def _generate(self, image: Image, result: VisualizeMixin, visualization_type: Vi
5757
def _generate_simple(self, image: Image, result: VisualizeMixin) -> Image:
5858
"""Return a single image with stacked visualizations."""
5959
# 1. Use Overlay
60+
_image = image.copy()
6061
if result.has_overlays:
6162
overlays = result.get_overlays()
6263
for overlay in overlays:
63-
image = overlay.compute(image)
64+
image = overlay.compute(_image)
6465

6566
elif result.has_polygons: # 2. else use polygons
6667
polygons = result.get_polygons()
6768
for polygon in polygons:
68-
image = polygon.compute(image)
69+
image = polygon.compute(_image)
6970

7071
elif result.has_bounding_boxes: # 3. else use bounding boxes
7172
bounding_boxes = result.get_bounding_boxes()
7273
for bounding_box in bounding_boxes:
73-
image = bounding_box.compute(image)
74+
image = bounding_box.compute(_image)
7475

7576
# Finally add labels
7677
if result.has_labels:
7778
labels = result.get_labels()
7879
label_images = []
7980
for label in labels:
80-
label_images.append(label.compute(image, overlay_on_image=False))
81-
image = Label.overlay_labels(image, label_images)
81+
label_images.append(label.compute(_image, overlay_on_image=False))
82+
_image = Label.overlay_labels(_image, label_images)
8283

83-
return image
84+
return _image
8485

8586
def _generate_full(self, image: Image, result: VisualizeMixin) -> Image:
8687
"""Return a single image with visualizations side by side."""

0 commit comments

Comments
 (0)