Skip to content

Commit b573d69

Browse files
committed
Reflect changes from openvinotoolkit#1976
1 parent ca4d060 commit b573d69

File tree

3 files changed

+13
-13
lines changed

3 files changed

+13
-13
lines changed

otx/algorithms/action/adapters/mmaction/task.py

+2
Original file line numberDiff line numberDiff line change
@@ -421,10 +421,12 @@ def _export_model(self, precision: ModelPrecision, dump_features: bool = True):
421421
exporter.export()
422422
bin_file = [f for f in os.listdir(self._output_path) if f.endswith(".bin")][0]
423423
xml_file = [f for f in os.listdir(self._output_path) if f.endswith(".xml")][0]
424+
onnx_file = [f for f in os.listdir(self._output_path) if f.endswith(".onnx")][0]
424425
results = {
425426
"outputs": {
426427
"bin": os.path.join(self._output_path, bin_file),
427428
"xml": os.path.join(self._output_path, xml_file),
429+
"onnx": os.path.join(self._output_path, onnx_file),
428430
}
429431
}
430432
return results

otx/algorithms/action/task.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -255,13 +255,16 @@ def export(
255255

256256
bin_file = outputs.get("bin")
257257
xml_file = outputs.get("xml")
258+
onnx_file = outputs.get("onnx")
258259

259-
if xml_file is None or bin_file is None:
260+
if xml_file is None or bin_file is None or onnx_file is None:
260261
raise RuntimeError("invalid status of exporting. bin and xml should not be None")
261262
with open(bin_file, "rb") as f:
262263
output_model.set_data("openvino.bin", f.read())
263264
with open(xml_file, "rb") as f:
264265
output_model.set_data("openvino.xml", f.read())
266+
with open(onnx_file, "rb") as f:
267+
output_model.set_data("model.onnx", f.read())
265268
output_model.set_data(
266269
"confidence_threshold",
267270
np.array([self.confidence_threshold], dtype=np.float32).tobytes(),

tests/unit/algorithms/action/adapters/mmaction/test_task.py

+7-12
Original file line numberDiff line numberDiff line change
@@ -116,14 +116,16 @@ def __iter__(self):
116116
class MockExporter:
117117
"""Mock class for Exporter."""
118118

119-
def __init__(self, recipe_cfg, weights, deploy_cfg, work_dir, half_precision):
120-
self.work_dir = work_dir
119+
def __init__(self, task):
120+
self.work_dir = task._output_path
121121

122122
def export(self):
123123
dummy_data = np.ndarray((1, 1, 1))
124-
with open(self.work_dir + ".bin", "wb") as f:
124+
with open(os.path.join(self.work_dir, "openvino.bin"), "wb") as f:
125125
f.write(dummy_data)
126-
with open(self.work_dir + ".xml", "wb") as f:
126+
with open(os.path.join(self.work_dir, "openvino.xml"), "wb") as f:
127+
f.write(dummy_data)
128+
with open(os.path.join(self.work_dir, "model.onnx"), "wb") as f:
127129
f.write(dummy_data)
128130

129131

@@ -331,17 +333,10 @@ def test_export(self, mocker, precision: ModelPrecision) -> None:
331333
"""
332334
_config = ModelConfiguration(ActionConfig(), self.cls_label_schema)
333335
_model = ModelEntity(self.cls_dataset, _config)
334-
mocker.patch("otx.algorithms.action.adapters.mmaction.utils.Exporter", side_effect=MockExporter)
335-
mocker.patch("otx.algorithms.action.adapters.mmaction.utils.export_utils.export", return_value=True)
336-
mocker.patch("otx.algorithms.action.adapters.mmaction.utils.export_utils.from_onnx", return_value=True)
336+
mocker.patch("otx.algorithms.action.adapters.mmaction.task.Exporter", return_value=MockExporter(self.cls_task))
337337
mocker.patch("torch.load", return_value={})
338338
mocker.patch("torch.nn.Module.load_state_dict", return_value=True)
339-
mocker.patch("os.listdir", return_value=["openvino.xml", "openvino.bin"])
340339

341-
with open(os.path.join(self.cls_task._output_path, "openvino.xml"), "wb") as f:
342-
f.write(np.ndarray([0]))
343-
with open(os.path.join(self.cls_task._output_path, "openvino.bin"), "wb") as f:
344-
f.write(np.ndarray([0]))
345340
self.cls_task.export(ExportType.OPENVINO, _model, precision, False)
346341

347342
assert _model.model_format == ModelFormat.OPENVINO

0 commit comments

Comments
 (0)