Skip to content

Commit f6c321a

Browse files
authored
Bump inference dependencies (#4243)
* Bump deps * Update classification OV model * Update detection OV model * Update iseg OV model * Fix unit tests * Don't use OMZ model in unit tests * Fix corner cases of one-sized scores in det output * Don't check if mlc model always produces top labels, as it can be flacky * Bump MAPI * Update readme * Update codeowners * Update changelog * Fix formatting * Bump MAPI
1 parent 14b1474 commit f6c321a

File tree

14 files changed

+114
-95
lines changed

14 files changed

+114
-95
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# See help here: https://help.github.com/en/github/creating-cloning-and-archiving-repositories/about-code-owners
22

33
# These owners will be the default owners for everything in the repo.
4-
* @samet-akcay @eugene123tw @kprokofi @sovrasov @negvet @daankrol @djdameln @ashwinvaidya17 @rajeshgangireddy @atwinand
4+
* @samet-akcay @eugene123tw @kprokofi @sovrasov @daankrol @djdameln @ashwinvaidya17 @rajeshgangireddy @atwinand

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@ All notable changes to this project will be documented in this file.
88

99
### Enhancements
1010

11+
- Bump inference dependencies
12+
(<https://github.com/openvinotoolkit/training_extensions/pull/4243>)
1113
- Bump ModelAPI to 0.2.5.2
1214
(<https://github.com/openvinotoolkit/training_extensions/pull/4275>)
1315

1416
### Bug fixes
1517

16-
1718
- Fix auto batch size with tiling
1819
(<https://github.com/openvinotoolkit/training_extensions/pull/4233>)
1920
- Fix exportable code for tiling

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
<!-- markdownlint-disable MD042 -->
1515

1616
[![python](https://img.shields.io/badge/python-3.10%2B-green)]()
17-
[![pytorch](https://img.shields.io/badge/pytorch-2.1.1%2B-orange)]()
18-
[![openvino](https://img.shields.io/badge/openvino-2024.0-purple)]()
17+
[![pytorch](https://img.shields.io/badge/pytorch-2.5%2B-orange)]()
18+
[![openvino](https://img.shields.io/badge/openvino-2025.0-purple)]()
1919

2020
<!-- markdownlint-enable MD042 -->
2121

pyproject.toml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,11 @@ base = [
7979
"lightning==2.4.0",
8080
"pytorchcv==0.0.67",
8181
"timm==1.0.3",
82-
"openvino==2024.6",
83-
"openvino-dev==2024.6",
84-
"openvino-model-api==0.2.5.2",
82+
"openvino==2025.0",
83+
"openvino-model-api==0.3.0.2",
8584
"onnx==1.17.0",
8685
"onnxconverter-common==1.14.0",
87-
"nncf==2.14.1",
86+
"nncf==2.15.0",
8887
"anomalib[core]==1.1.3",
8988
]
9089

src/otx/core/exporter/exportable_code/demo/demo_package/visualizers/visualizer.py

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -273,21 +273,24 @@ def draw(
273273
Returns:
274274
Output image with annotations.
275275
"""
276-
for detection in predictions.objects:
277-
class_id = int(detection.id)
278-
color = self.color_palette[class_id]
279-
det_label = self.color_palette[class_id] if self.labels and len(self.labels) >= class_id else f"#{class_id}"
280-
xmin, ymin, xmax, ymax = detection.xmin, detection.ymin, detection.xmax, detection.ymax
281-
cv2.rectangle(frame, (xmin, ymin), (xmax, ymax), color, 2)
282-
cv2.putText(
283-
frame,
284-
f"{det_label} {detection.score:.1%}",
285-
(xmin, ymin - 7),
286-
cv2.FONT_HERSHEY_COMPLEX,
287-
0.6,
288-
color,
289-
1,
290-
)
276+
if len(predictions.bboxes.shape):
277+
for i, box in enumerate(predictions.bboxes):
278+
class_id = int(predictions.labels[i])
279+
color = self.color_palette[class_id]
280+
det_label = (
281+
self.color_palette[class_id] if self.labels and len(self.labels) >= class_id else f"#{class_id}"
282+
)
283+
xmin, ymin, xmax, ymax = box
284+
cv2.rectangle(frame, (xmin, ymin), (xmax, ymax), color, 2)
285+
cv2.putText(
286+
frame,
287+
f"{det_label} {predictions.scores[i]:.1%}",
288+
(xmin, ymin - 7),
289+
cv2.FONT_HERSHEY_COMPLEX,
290+
0.6,
291+
color,
292+
1,
293+
)
291294

292295
return frame
293296

@@ -339,16 +342,10 @@ def draw(
339342
np.ndarray - The input frame with the instance segmentation results drawn on it.
340343
"""
341344
result = frame.copy()
342-
output_objects = predictions.segmentedObjects
343-
bboxes = [[output.xmin, output.ymin, output.xmax, output.ymax] for output in output_objects]
344-
scores = [output.score for output in output_objects]
345-
masks = [output.mask for output in output_objects]
346-
label_names = [output.str_label for output in output_objects]
347-
348-
result = self._overlay_masks(result, masks)
349-
return self._overlay_labels(result, bboxes, label_names, scores)
345+
result = self._overlay_masks(result, predictions.masks)
346+
return self._overlay_labels(result, predictions.bboxes, predictions.label_names, predictions.scores)
350347

351-
def _overlay_masks(self, image: np.ndarray, masks: list[np.ndarray]) -> np.ndarray:
348+
def _overlay_masks(self, image: np.ndarray, masks: np.ndarray) -> np.ndarray:
352349
segments_image = image.copy()
353350
aggregated_mask = np.zeros(image.shape[:2], dtype=np.uint8)
354351
aggregated_colored_mask = np.zeros(image.shape, dtype=np.uint8)
@@ -381,9 +378,9 @@ def _overlay_boxes(self, image: np.ndarray, boxes: list[np.ndarray], classes: li
381378
def _overlay_labels(
382379
self,
383380
image: np.ndarray,
384-
boxes: list[np.ndarray],
381+
boxes: np.ndarray,
385382
classes: list[str],
386-
scores: list[float],
383+
scores: np.ndarray,
387384
) -> np.ndarray:
388385
template = "{}: {:.2f}" if self.show_scores else "{}"
389386

src/otx/core/model/classification.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -529,8 +529,8 @@ def _customize_outputs(
529529
outputs: list[ClassificationResult],
530530
inputs: MulticlassClsBatchDataEntity,
531531
) -> MulticlassClsBatchPredEntity:
532-
pred_labels = [torch.tensor(out.top_labels[0][0], dtype=torch.long, device=self.device) for out in outputs]
533-
pred_scores = [torch.tensor(out.top_labels[0][2], device=self.device) for out in outputs]
532+
pred_labels = [torch.tensor(out.top_labels[0].id, dtype=torch.long, device=self.device) for out in outputs]
533+
pred_scores = [torch.tensor(out.top_labels[0].confidence, device=self.device) for out in outputs]
534534

535535
if outputs and outputs[0].saliency_map.size != 0:
536536
# Squeeze dim 4D => 3D, (1, num_classes, H, W) => (num_classes, H, W)
@@ -605,7 +605,7 @@ def _customize_outputs(
605605
inputs: MultilabelClsBatchDataEntity,
606606
) -> MultilabelClsBatchPredEntity:
607607
pred_scores = [
608-
torch.tensor([top_label[2] for top_label in out.top_labels], device=self.device) for out in outputs
608+
torch.tensor([top_label.confidence for top_label in out.top_labels], device=self.device) for out in outputs
609609
]
610610

611611
if outputs and outputs[0].saliency_map.size != 0:

src/otx/core/model/detection.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -622,21 +622,16 @@ def _customize_outputs(
622622
log.warning(f"label_shift: {label_shift}")
623623

624624
for i, output in enumerate(outputs):
625-
output_objects = output.objects
626-
if len(output_objects):
627-
bbox = [[output.xmin, output.ymin, output.xmax, output.ymax] for output in output_objects]
628-
else:
629-
bbox = torch.empty(size=(0, 0))
630625
bboxes.append(
631626
tv_tensors.BoundingBoxes(
632-
bbox,
627+
data=output.bboxes,
633628
format="XYXY",
634629
canvas_size=inputs.imgs_info[i].img_shape,
635630
device=self.device,
636631
),
637632
)
638-
scores.append(torch.tensor([output.score for output in output_objects], device=self.device))
639-
labels.append(torch.tensor([output.id - label_shift for output in output_objects], device=self.device))
633+
scores.append(torch.tensor(output.scores.reshape(-1), device=self.device))
634+
labels.append(torch.tensor(output.labels.reshape(-1) - label_shift, device=self.device))
640635

641636
if outputs and outputs[0].saliency_map.size > 1:
642637
# Squeeze dim 4D => 3D, (1, num_classes, H, W) => (num_classes, H, W)

src/otx/core/model/instance_segmentation.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -654,26 +654,19 @@ def _customize_outputs(
654654
labels = []
655655
masks = []
656656
for output in outputs:
657-
output_objects = output.segmentedObjects
658-
if len(output_objects):
659-
bbox = [[output.xmin, output.ymin, output.xmax, output.ymax] for output in output_objects]
660-
else:
661-
bbox = torch.empty(size=(0, 0))
662657
bboxes.append(
663658
tv_tensors.BoundingBoxes(
664-
bbox,
659+
data=output.bboxes,
665660
format="XYXY",
666661
canvas_size=inputs.imgs_info[-1].img_shape,
667662
device=self.device,
668663
),
669664
)
670665
# NOTE: OTX 1.5 filter predictions with result_based_confidence_threshold,
671666
# but OTX 2.0 doesn't have it in configuration.
672-
_masks = [output.mask for output in output_objects]
673-
_masks = np.stack(_masks) if len(_masks) else []
674-
scores.append(torch.tensor([output.score for output in output_objects], device=self.device))
675-
masks.append(torch.tensor(_masks, device=self.device))
676-
labels.append(torch.tensor([output.id - 1 for output in output_objects], device=self.device))
667+
scores.append(torch.tensor(output.scores.reshape(-1), device=self.device))
668+
masks.append(torch.tensor(output.masks, device=self.device))
669+
labels.append(torch.tensor(output.labels.reshape(-1) - 1, device=self.device))
677670

678671
if outputs and outputs[0].saliency_map:
679672
predicted_s_maps = []

tests/integration/api/test_geti_interaction.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ def test_export_and_infer_onnx(self):
118118

119119
predictions = mapi_model(self.image)
120120
assert predictions is not None
121-
assert len(predictions.top_labels) > 0
122121

123122
exported_path.unlink(missing_ok=True)
124123

@@ -148,7 +147,6 @@ def test_export_and_infer_openvino(self):
148147

149148
predictions = mapi_model(self.image)
150149
assert predictions is not None
151-
assert len(predictions.top_labels) > 0
152150

153151
exported_path.unlink(missing_ok=True)
154152

@@ -187,7 +185,6 @@ def test_optimize_and_infer_openvino_fp32(self):
187185

188186
predictions = mapi_model(self.image)
189187
assert predictions is not None
190-
assert len(predictions.top_labels) > 0
191188

192189

193190
@pytest.mark.parametrize("task", pytest.TASK_LIST)

tests/unit/core/data/test_tiling.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from datumaro import Dataset as DmDataset
1515
from datumaro import Polygon
1616
from model_api.models import Model
17-
from model_api.models.utils import ImageResultWithSoftPrediction
17+
from model_api.models.result import ImageResultWithSoftPrediction
1818
from model_api.tilers import SemanticSegmentationTiler
1919
from omegaconf import OmegaConf
2020
from torchvision import tv_tensors

0 commit comments

Comments
 (0)