Closed haimat closed 3 months ago
Update: It seems to work when creating the OpenVINOInferencer
with device="CPU"
.
Does it not work with Nvidia GPUs?
Hey guys, any news on this? Or can you suggest any other way to run an exported anomlib model in ONNX format on the Nvidia GPU?
Hey @haimat, the team is quite busy at this moment, so we didn't have time to look into it. We will return to is as soon as possible. Meanwhile, you can take a look at the OpenVINO documentation to get an idea of the supported hardware, https://docs.openvino.ai/2024/home.html.
@ashwinvaidya17 Thanks for your response. I can see that Nvidia GPUs are not (fully) supported by OpenVINO, so I guess the best (= fastest) approach would be to convert the ONNX model into a TensorRT model. I guess that should be doable. But how can I read the output of the ONNX model, can I follow 1:1 what happens in the OpenVINOInferencer
?
It seems the problem is related to Nvidia GPUs being not fully supported in OpenVINO. After I exported the model to ONNX / TensorRT format, everything works fine now.
After I exported the model to ONNX / TensorRT format, everything works fine now.
Hello, I also encountered this issue, but even after converting to onnx format, the GPU still doesn't work, I am looking forward to your answer very much output_path = Path("./results") openvino_model_path = output_path / "weights" / "onnx" / "model.onnx" metadata_path = output_path / "weights" / "onnx" / "metadata.json"
inferencer = OpenVINOInferencer(
path=openvino_model_path, # Path to the OpenVINO IR model.
metadata=metadata_path, # Path to the metadata file.
task=TaskType.SEGMENTATION,
device="GPU", # We would like to run it on an Intel CPU.
)
The following error occurred after running:
RuntimeError: Exception from src/inference/src/cpp/infer_request.cpp:223: Check 'TRShape::merge_into(output_shape, in_copy)' failed at src/core/shape_inference/include\concat_shape_inference.hpp:49: While validating node 'opset1::Concat concat:/model/Concat_5 () -> ()' with friendly_name 'concat:/model/Concat_5': Shape inference input shapes {[0,64,64,64],[0,0,0,0],[0,0,0,0]} Argument shapes are inconsistent; they must have the same rank, and must have equal dimension everywhere except on the concatenation axis (axis 1).
BUT,when device="AUTO",Although the above error will not occur, the GPU is not used and the prediction time is very slow
I am not using the OpenVINOInferencer
class for ONNX models.
Instead I created a custom ONNX runner class - GPT & Co. are your friends :)
我没有将“OpenVINOInferencer”类用于 ONNX 模型。 相反,我创建了一个自定义 ONNX 运行器类 - GPT & Co. 是你的朋友 :)
Wow, your method is great. Would it be convenient to share it? I have encountered a big problem on my end
Well, first load the ONNX model:
import onnxruntime as ort
def load_onnx_model(self, path: str | Path) -> ort.InferenceSession:
ort.set_default_logger_severity(3)
providers = ["CUDAExecutionProvider"] if self.device == "CUDA" else ["CPUExecutionProvider"]
sess_options = ort.SessionOptions()
sess_options.graph_optimization_level = ort.GraphOptimizationLevel.ORT_ENABLE_ALL
return ort.InferenceSession(str(path), sess_options, providers=providers)
Then pre-process the image as desired (see OpenVINOInferencer
), then call the model:
def forward_onnx(self, image: np.ndarray) -> np.ndarray:
input_name = self.session.get_inputs()[0].name
return self.session.run(None, {input_name: image})[0]
I have created most of the code via ChatGPT, it's straight forward :)
Well, first load the ONNX model:
import onnxruntime as ort def load_onnx_model(self, path: str | Path) -> ort.InferenceSession: ort.set_default_logger_severity(3) providers = ["CUDAExecutionProvider"] if self.device == "CUDA" else ["CPUExecutionProvider"] sess_options = ort.SessionOptions() sess_options.graph_optimization_level = ort.GraphOptimizationLevel.ORT_ENABLE_ALL return ort.InferenceSession(str(path), sess_options, providers=providers)
Then pre-process the image as desired (see
OpenVINOInferencer
), then call the model:def forward_onnx(self, image: np.ndarray) -> np.ndarray: input_name = self.session.get_inputs()[0].name return self.session.run(None, {input_name: image})[0]
I have created most of the code via ChatGPT, it's straight forward :)
Your method looks great, thank you very much for sharing. I will try to modify the code, and if there are any parts that I don't know, I will ask you again. Thank you again for sharing.
Describe the bug
I have trained a
Fastflow
model withtask=TaskType.CLASSIFICATION
for both theFolder
and theEngine
. After training I have exported the model toExportType.ONNX
. Now I want to load that model and predict images with it. This leads to the following error:The problem lies in
OpenVINOInferencer.post_process()
(line 266ff). For some reason with the output from the ONNX model thatif
section ends up in theelse
part, wheretask = TaskType.SEGMENTATION
. But this is wrong, because it's a classification model, as described above. Note that when I print the predictions after line 257 (predictions = predictions[self.output_blob]
), then the output is an empty list:[]
. So apparently the ONNX model does not output correctly?Dataset
Other (please specify in the text field below)
Model
FastFlow
Steps to reproduce the behavior
task=TaskType.CLASSIFICATION
engine.export(model=model, export_type=ExportType.ONNX, export_root=...)
The last line leads to the aforementioned error.
OS information
OS information:
Expected behavior
I would expect the
OpenVINOInferencer
class works fine with ONNX classification models.Screenshots
No response
Pip/GitHub
pip
What version/branch did you use?
No response
Configuration YAML
Logs
Code of Conduct