I develop a Qt app to let user choose a DICOM file, then it will show the inference result.
I use dcmread
to read a DICOM image as many slices of images.
For example, single DICOM image can convert to 60 JPG images.
The following is how I input a DICOM file.
JavaScript
x
17
17
1
dcm_file = "1037973"
2
ds = dcmread(dcm_file, force=True)
3
ds.PixelRepresentation = 0
4
ds_arr = ds.pixel_array
5
6
core = ov.Core()
7
model = core.read_model(model="frozen_darknet_yolov4_model.xml")
8
model.reshape([ds_arr.shape[0], ds_arr.shape[1], ds_arr.shape[2], 3])
9
compiled_model = core.compile_model(model, "CPU")
10
infer_request = compiled_model.create_infer_request()
11
input_tensor = ov.Tensor(array=ds_arr, shared_memory=True)
12
#infer_request.set_input_tensor(input_tensor)
13
infer_request.start_async()
14
infer_request.wait()
15
output = infer_request.get_output_tensor()
16
print(output)
17
I use model.reshape
to make my YOLOv4 model fit with the batch, heigh, width of my input file.
But the below error seems like I can’t let my batch more than 1.
JavaScript
1
7
1
Traceback (most recent call last):
2
File "C:Usersjohn0Desktophf_inference_toolcontroller.py", line 90, in show_inference_result
3
yolov4_inference_engine(gv.gInImgPath)
4
File "C:Usersjohn0Desktophf_inference_toolinference.py", line 117, in yolov4_inference_engine
5
output = infer_request.get_output_tensor()
6
RuntimeError: get_output_tensor() must be called on a function with exactly one parameter.
7
How can I use dynamic input in API 2.0 correctly?
My environment is Windows 11 with openvino_2022.1.0.643 version.
Advertisement
Answer
The ov::InferRequest::get_output_tensor method without arguments can be used for model with only one output.
Use ov::InferRequest::get_output_tensor method with argument (index: int) as your model has three outputs.
JavaScript
1
7
1
output_tensor1 = infer_request.get_output_tensor(0)
2
output_tensor2 = infer_request.get_output_tensor(1)
3
output_tensor3 = infer_request.get_output_tensor(2)
4
print(output_tensor1)
5
print(output_tensor2)
6
print(output_tensor3)
7