当图像作为numpy array传递给openvino Core().compile_model()时,Openvino抛出openvino Core().compile_model()。但是在执行cv2.imread()后传递的相同图像工作得很好。如何将numpy array直接传递给openvino Core().compile_model()
工作代码:
image = cv2.cvtColor(test_img, code=cv2.COLOR_BGR2RGB)
print("image",type(image))
print("model", compiled_model)
image = np.array(image)
# resize to MobileNet image shape
input_image = cv2.resize(src=image, dsize=(224, 224))
# reshape to network input shape
input_data = np.expand_dims(np.transpose(input_image, (0, 1, 2)), 0).astype(np.float32)
print(input_data.shape)
print("type:",type(output_layer))
# Do inference
result = compiled_model([input_data])[output_layer]Buggy代码:
for img in img_batch:
#image = cv2.cvtColor(img, code=cv2.COLOR_BGR2RGB)
resized_image = cv2.resize(src=img, dsize=(
self.node_input.input_resolution.width, self.node_input.input_resolution.height))
input_img = np.expand_dims(np.transpose(resized_image, (0, 1, 2)), 0).astype(np.float32)
res = Core().compile_model([input_img])[output_layer]任何关于我在这里所缺少的线索都是非常感谢的。提前谢谢!!
发布于 2022-08-10 03:36:17
使用张量对象可以保存来自给定数组的数据的副本。
from openvino.runtime import Tensor
data_float32 = np.ones(shape=(1,3,224,224), dtype=np.float32)
tensor = Tensor(data_float32)传递numpy数组,收集在Python或列表中。
infer_request = compiled_model.create_infer_request()
# Passing inputs data in form of a dictionary
infer_request.infer(inputs={0: tensor})
# Passing inputs data in form of a list
infer_request.infer(inputs=[tensor])从推论中得到的结果:
results = infer_request.get_output_tensor().datahttps://stackoverflow.com/questions/73281292
复制相似问题