Skip to content

Commit 7385752

Browse files
committed
Reflect changes from openvinotoolkit#1976
1 parent 115ca1c commit 7385752

File tree

2 files changed

+18
-15
lines changed

2 files changed

+18
-15
lines changed

otx/algorithms/detection/task.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -274,18 +274,21 @@ def export(
274274

275275
bin_file = outputs.get("bin")
276276
xml_file = outputs.get("xml")
277+
onnx_file = outputs.get("onnx")
277278

278279
ir_extra_data = get_det_model_api_configuration(
279280
self._task_environment.label_schema, self._task_type, self.confidence_threshold
280281
)
281282
embed_ir_model_data(xml_file, ir_extra_data)
282283

283-
if xml_file is None or bin_file is None:
284-
raise RuntimeError("invalid status of exporting. bin and xml should not be None")
284+
if xml_file is None or bin_file is None or onnx_file is None:
285+
raise RuntimeError("invalid status of exporting. bin and xml or onnx should not be None")
285286
with open(bin_file, "rb") as f:
286287
output_model.set_data("openvino.bin", f.read())
287288
with open(xml_file, "rb") as f:
288289
output_model.set_data("openvino.xml", f.read())
290+
with open(onnx_file, "rb") as f:
291+
output_model.set_data("model.onnx", f.read())
289292
output_model.set_data(
290293
"confidence_threshold",
291294
np.array([self.confidence_threshold], dtype=np.float32).tobytes(),

tests/unit/algorithms/detection/adapters/mmdet/test_task.py

+13-13
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,14 @@ def run(self, *args, **kwargs):
121121
f.write(np.ndarray([0]))
122122
with open(os.path.join(self._output_path, "openvino.xml"), "wb") as f:
123123
f.write(np.ndarray([0]))
124+
with open(os.path.join(self._output_path, "model.onnx"), "wb") as f:
125+
f.write(np.ndarray([0]))
124126

125127
return {
126128
"outputs": {
127129
"bin": os.path.join(self._output_path, "openvino.bin"),
128130
"xml": os.path.join(self._output_path, "openvino.xml"),
131+
"onnx": os.path.join(self._output_path, "model.onnx"),
129132
}
130133
}
131134

@@ -267,26 +270,27 @@ def test_infer(self, mocker) -> None:
267270
assert output.get_annotations()[-1].get_labels()[0].probability == 0.7
268271

269272
@e2e_pytest_unit
270-
def test_evaluate(self) -> None:
271-
"""Test evaluate function.
273+
def test_det_evaluate(self) -> None:
274+
"""Test evaluate function for detection."""
272275

273-
<Steps>
274-
1. Create model entity
275-
2. Create result set entity
276-
3. Run evaluate function with same dataset, this should give 100% accuracy
277-
4. Run evaluate function with empty dataset, this should give 0% accuracy
278-
5. Do 1 - 4 for action detection
279-
"""
280276
_config = ModelConfiguration(DetectionConfig(), self.det_label_schema)
281277
_model = ModelEntity(self.det_dataset, _config)
282278
resultset = ResultSetEntity(_model, self.det_dataset, self.det_dataset)
283279
self.det_task.evaluate(resultset)
284280
assert resultset.performance.score.value == 1.0
285281

282+
@e2e_pytest_unit
283+
def test_det_evaluate_with_empty_annotations(self) -> None:
284+
"""Test evaluate function for detection with empty predictions."""
285+
286286
resultset = ResultSetEntity(_model, self.det_dataset, self.det_dataset.with_empty_annotations())
287287
self.det_task.evaluate(resultset)
288288
assert resultset.performance.score.value == 0.0
289289

290+
@e2e_pytest_unit
291+
def test_iseg_evaluate(self) -> None:
292+
"""Test evaluate function for instance segmentation."""
293+
290294
_config = ModelConfiguration(DetectionConfig(), self.iseg_label_schema)
291295
_model = ModelEntity(self.iseg_dataset, _config)
292296
resultset = ResultSetEntity(_model, self.iseg_dataset, self.iseg_dataset)
@@ -315,10 +319,6 @@ def test_export(self, mocker, precision: ModelPrecision) -> None:
315319
return_value=True,
316320
)
317321

318-
with open(os.path.join(self.det_task._output_path, "openvino.xml"), "wb") as f:
319-
f.write(np.ndarray([0]))
320-
with open(os.path.join(self.det_task._output_path, "openvino.bin"), "wb") as f:
321-
f.write(np.ndarray([0]))
322322
self.det_task.export(ExportType.OPENVINO, _model, precision, False)
323323

324324
assert _model.model_format == ModelFormat.OPENVINO

0 commit comments

Comments
 (0)