Skip to content

Commit 603efca

Browse files
authored
Update ModelAPI in 1.4 release (#2347)
* Upgrade model API * Update otx in exportable code * Fix unit tests * Fix black * Fix detection inference * Fix det tiling * Fix mypy * Fix demo * Fix visualizer in demo * Fix black
1 parent 225ddf1 commit 603efca

File tree

9 files changed

+18
-13
lines changed

9 files changed

+18
-13
lines changed

requirements/openvino.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# OpenVINO Requirements. #
33
nncf==2.5.0
44
onnx==1.13.0
5-
openvino-model-api==0.1.2
5+
openvino-model-api==0.1.3
66
openvino==2023.0
77
openvino-dev==2023.0
88
openvino-telemetry>=2022.1.0

src/otx/algorithms/detection/adapters/openvino/task.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ def __init__(
235235
def post_process(self, prediction: Dict[str, np.ndarray], metadata: Dict[str, Any]) -> AnnotationSceneEntity:
236236
"""Detection specific post-process."""
237237
detections = self.model.postprocess(prediction, metadata)
238-
detections = detection2array(detections)
238+
detections = detection2array(detections.objects)
239239
return self.converter.convert_to_annotation(detections, metadata)
240240

241241

src/otx/api/usecases/exportable_code/demo/demo_package/executors/asynchronous.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,9 @@ def render_result(self, results: Tuple[Any, dict]) -> np.ndarray:
7878
predictions, frame_meta = results
7979
if isinstance(self.converter, DetectionToAnnotationConverter):
8080
# Predictions for the detection task
81-
predictions = np.array([[pred.id, pred.score, *pred.get_coords()] for pred in predictions])
81+
predictions = np.array(
82+
[[pred.id, pred.score, *[pred.xmin, pred.ymin, pred.xmax, pred.ymax]] for pred in predictions.objects]
83+
)
8284
predictions.shape = len(predictions), 6
8385
annotation_scene = self.converter.convert_to_annotation(predictions, frame_meta)
8486
current_frame = frame_meta["frame"]

src/otx/api/usecases/exportable_code/demo/demo_package/model_container.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def infer(self, frame):
121121

122122
# MaskRCNN returns tuple so no need to process
123123
if self._task_type == TaskType.DETECTION:
124-
predictions = detection2array(predictions)
124+
predictions = detection2array(predictions.objects)
125125
return predictions, frame_meta
126126

127127
def infer_tile(self, frame):
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
openvino==2023.0
2-
openvino-model-api==0.1.2
3-
otx==1.4.0rc2
2+
openvino-model-api==0.1.3
3+
otx @ git+https://github.com/openvinotoolkit/training_extensions/@e4269e035bcaa3903c6b99044f46c42fcbf98f25#egg=otx
44
numpy>=1.21.0,<=1.23.5 # np.bool was removed in 1.24.0 which was used in openvino runtime

src/otx/api/usecases/exportable_code/prediction_to_annotation_converter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ def convert_to_annotation(
214214
image_size = metadata["original_shape"][1::-1]
215215
for box in predictions:
216216
scored_label = ScoredLabel(self.labels[int(box.id)], float(box.score))
217-
coords = np.array(box.get_coords(), dtype=float)
217+
coords = np.array([box.xmin, box.ymin, box.xmax, box.ymax], dtype=float)
218218
if (coords[2] - coords[0]) * (coords[3] - coords[1]) < 1.0:
219219
continue
220220
coords /= np.tile(image_size, 2)

src/otx/api/utils/tiler.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@
44
# SPDX-License-Identifier: Apache-2.0
55
#
66

7-
import copy
87
import cv2
98
from itertools import product
109
from typing import Dict, List, Optional, Tuple, Union
1110

1211
import numpy as np
1312
from openvino.model_api.models import Model, ImageModel
1413

14+
from openvino.model_api.models.utils import DetectionResult
15+
1516
from otx.algorithms.common.utils.logger import get_logger
1617
from otx.api.utils.async_pipeline import OTXDetectionAsyncPipeline
1718
from otx.api.utils.detection_utils import detection2array
@@ -196,7 +197,7 @@ def predict_async(self, image: np.ndarray, tile_coords: List[List[int]]):
196197
merged_features = self.merge_features(features, merged_results)
197198
return merged_results, merged_features
198199

199-
def postprocess_tile(self, predictions: Union[List, Tuple], offset_x: int, offset_y: int) -> Dict[str, List]:
200+
def postprocess_tile(self, predictions: DetectionResult, offset_x: int, offset_y: int) -> Dict[str, List]:
200201
"""Postprocess single tile prediction.
201202
202203
Args:
@@ -221,8 +222,8 @@ def postprocess_tile(self, predictions: Union[List, Tuple], offset_x: int, offse
221222
)
222223
output_dict["masks"] = tile_masks
223224
else:
224-
assert isinstance(predictions, list)
225-
out = detection2array(predictions)
225+
assert isinstance(predictions.objects, list)
226+
out = detection2array(predictions.objects)
226227
out[:, 2:] += np.tile([offset_x, offset_y], 2)
227228
output_dict["bboxes"] = out
228229
return output_dict

tests/unit/algorithms/action/adapters/openvino/test_action_openvino_models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,4 +221,4 @@ def test_postprocess(self) -> None:
221221
# argmax index is 2 because first index is for background
222222
assert out[0].id == 2
223223
assert out[0].score == 0.7
224-
assert out[0].get_coords() == (0, 0, 256, 256)
224+
assert (out[0].xmin, out[0].ymin, out[0].xmax, out[0].ymax) == (0, 0, 256, 256)

tests/unit/algorithms/detection/adapters/openvino/model_wrappers/test_detection_openvino_models.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ def __init__(self, *args):
7878
self.resize_type = "standard"
7979
self.output_parser = MockBatchBoxesLabelsParser()
8080
self.labels = []
81+
self.w = 10
82+
self.h = 10
8183
super().__init__(MockOpenvinoAdapter)
8284

8385

@@ -142,7 +144,7 @@ def test_postprocess(self) -> None:
142144
}
143145
sample_meta = {"original_shape": (10, 10, 3), "resized_shape": (5, 5, 3)}
144146
out = self.model.postprocess(sample_output, meta=sample_meta)
145-
assert len(out) <= 1
147+
assert len(out.objects) <= 1
146148

147149

148150
class TestBatchBoxesLabelsParser:

0 commit comments

Comments
 (0)