Skip to content

Commit

Permalink
Reflect changes from openvinotoolkit#1976
Browse files Browse the repository at this point in the history
  • Loading branch information
jaegukhyun committed Apr 12, 2023
1 parent 115ca1c commit 7385752
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
7 changes: 5 additions & 2 deletions otx/algorithms/detection/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,18 +274,21 @@ def export(

bin_file = outputs.get("bin")
xml_file = outputs.get("xml")
onnx_file = outputs.get("onnx")

ir_extra_data = get_det_model_api_configuration(
self._task_environment.label_schema, self._task_type, self.confidence_threshold
)
embed_ir_model_data(xml_file, ir_extra_data)

if xml_file is None or bin_file is None:
raise RuntimeError("invalid status of exporting. bin and xml should not be None")
if xml_file is None or bin_file is None or onnx_file is None:
raise RuntimeError("invalid status of exporting. bin and xml or onnx should not be None")
with open(bin_file, "rb") as f:
output_model.set_data("openvino.bin", f.read())
with open(xml_file, "rb") as f:
output_model.set_data("openvino.xml", f.read())
with open(onnx_file, "rb") as f:
output_model.set_data("model.onnx", f.read())
output_model.set_data(
"confidence_threshold",
np.array([self.confidence_threshold], dtype=np.float32).tobytes(),
Expand Down
26 changes: 13 additions & 13 deletions tests/unit/algorithms/detection/adapters/mmdet/test_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,14 @@ def run(self, *args, **kwargs):
f.write(np.ndarray([0]))
with open(os.path.join(self._output_path, "openvino.xml"), "wb") as f:
f.write(np.ndarray([0]))
with open(os.path.join(self._output_path, "model.onnx"), "wb") as f:
f.write(np.ndarray([0]))

return {
"outputs": {
"bin": os.path.join(self._output_path, "openvino.bin"),
"xml": os.path.join(self._output_path, "openvino.xml"),
"onnx": os.path.join(self._output_path, "model.onnx"),
}
}

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

@e2e_pytest_unit
def test_evaluate(self) -> None:
"""Test evaluate function.
def test_det_evaluate(self) -> None:
"""Test evaluate function for detection."""

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

@e2e_pytest_unit
def test_det_evaluate_with_empty_annotations(self) -> None:
"""Test evaluate function for detection with empty predictions."""

resultset = ResultSetEntity(_model, self.det_dataset, self.det_dataset.with_empty_annotations())
self.det_task.evaluate(resultset)
assert resultset.performance.score.value == 0.0

@e2e_pytest_unit
def test_iseg_evaluate(self) -> None:
"""Test evaluate function for instance segmentation."""

_config = ModelConfiguration(DetectionConfig(), self.iseg_label_schema)
_model = ModelEntity(self.iseg_dataset, _config)
resultset = ResultSetEntity(_model, self.iseg_dataset, self.iseg_dataset)
Expand Down Expand Up @@ -315,10 +319,6 @@ def test_export(self, mocker, precision: ModelPrecision) -> None:
return_value=True,
)

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

assert _model.model_format == ModelFormat.OPENVINO
Expand Down

0 comments on commit 7385752

Please sign in to comment.