OpenVINO API 2.0 无法使用 YOLOv4 读取动态输入批处理

OpenVINO API 2.0 cannot read dynamic input batch with YOLOv4

我开发了一个Qt应用程序让用户选择一个DICOM文件,然后它会显示推理结果。

我使用 dcmread 来读取 DICOM 图像的许多切片。

例如,单个 DICOM 图片可以转换为 60 张 JPG 图片。

下面是我输入DICOM文件的方法

dcm_file = "1037973"
ds = dcmread(dcm_file, force=True)
ds.PixelRepresentation = 0
ds_arr = ds.pixel_array
        
core = ov.Core()
model = core.read_model(model="frozen_darknet_yolov4_model.xml")
model.reshape([ds_arr.shape[0], ds_arr.shape[1], ds_arr.shape[2], 3])
compiled_model = core.compile_model(model, "CPU")
infer_request = compiled_model.create_infer_request()
input_tensor = ov.Tensor(array=ds_arr, shared_memory=True)
#infer_request.set_input_tensor(input_tensor)
infer_request.start_async()
infer_request.wait()
output = infer_request.get_output_tensor()
print(output)

我使用 model.reshape 使我的 YOLOv4 模型适合我的输入文件的批次、高度、宽度。

但是下面的错误似乎是我不能让我的批次超过 1 个。

Traceback (most recent call last):
  File "C:\Users\john0\Desktop\hf_inference_tool\controller.py", line 90, in show_inference_result
    yolov4_inference_engine(gv.gInImgPath)
  File "C:\Users\john0\Desktop\hf_inference_tool\inference.py", line 117, in yolov4_inference_engine
    output = infer_request.get_output_tensor()
RuntimeError: get_output_tensor() must be called on a function with exactly one parameter.

如何在 API 2.0 中正确使用动态输入?

我的环境是Windows11,版本openvino_2022.1.0.643。

需要的可以下载我的推理文件here

(ZIP 文件包含 3 个 IR 文件和 1 个输入文件。)

没有参数的ov::InferRequest::get_output_tensor方法可以用于只有一个输出的模型。

使用带有参数 (index: int) 的 ov::InferRequest::get_output_tensor 方法,因为您的模型有三个输出。

output_tensor1 = infer_request.get_output_tensor(0)
output_tensor2 = infer_request.get_output_tensor(1)
output_tensor3 = infer_request.get_output_tensor(2)
print(output_tensor1)
print(output_tensor2)
print(output_tensor3)