我將此計算機視覺模型7.x 轉換為可與開放式 VINO 工具包一起使用的 ONNX 型別模型。該模型具有我所追求的良好特性,即它在我讀過的其他應用程式中的使用方式。
我認為我的問題是超級基本的,與對計算機視覺的理解不夠充分有關,只是好奇是否有人可以給我一些關于計算機視覺基礎知識的提示,關于如何遍歷模型輸出以使用 opencv 繪制“邊界框”。
在安裝了 pip 打開 VINO 的 CPU 上使用它:
import cv2
import numpy as np
import matplotlib.pyplot as plt
from openvino.runtime import Core
model_path = (
f"./yolov7.xml"
)
ie_core = Core()
def model_init(model_path):
model = ie_core.read_model(model=model_path)
compiled_model = ie_core.compile_model(model=model, device_name="CPU")
input_keys = compiled_model.input(0)
output_keys = compiled_model.output(0)
return input_keys, output_keys, compiled_model
input_key, output_keys, compiled_model = model_init(model_path)
# resize the image so it works with the model dimensions
image = cv2.resize(image, (width, height))
image = image.transpose((2,0,1))
image = image.reshape(1,3, height,width)
# Run inference on image, trying .output(1) first
boxes = compiled_model([image])[compiled_model.output(1)]
代碼有效....輸出一個陣列,但是這個資料包含什么?出于某種原因,我認為我可以有信心過濾掉錯誤的預測以及邊界框坐標?
如果我print(compiled_model)這個輸出我認為模型架構:
<CompiledModel:
inputs[
<ConstOutput: names[input.1] shape{1,3,640,640} type: f32>
]
outputs[
<ConstOutput: names[812] shape{1,25200,85} type: f32>,
<ConstOutput: names[588] shape{1,3,80,80,85} type: f32>,
<ConstOutput: names[669] shape{1,3,40,40,85} type: f32>,
<ConstOutput: names[750] shape{1,3,20,20,85} type: f32>
]>
這是否告訴我有關模型輸出的任何資訊,例如資料將包含什么?或boxes.shape:
回傳:
(1, 3, 80, 80, 85)
for box in boxes:
print(box)
這只是 numpy 陣列很多浮點資料,只是好奇是否有人可以幫助我從高層次上理解我需要學習什么來圍繞影像內的特征繪制邊界框。
uj5u.com熱心網友回復:
從我的復制中,您的代碼無法使用“NameError:name 'image' is not defined”錯誤。在您的輸出中, ConstOutput 僅代表模型的埠/節點。為確保您的模型正常作業,請使用OpenVINO Benchmark Python Tool運行您的 yolov7.xml 檔案。您不應該收到任何錯誤。
在 OpenVINO 示例中,您可以參考Object Detection Python Demo源代碼來了解 OpenVINO 推理引擎 API 用于創建邊界框以及如何處理模型的用法。這是創建邊界框的另一個示例:
For box in boxes:
#Pick a confidence factor from the last place in an array.
conf=box[-1]
If conf > threshold:
#Convert float to int and multiply corner position of each box by x and y ration.
#If the bounding box is found that the top of the image
#Position the upper box bar little lower to make it visible on the image
(x_min, y_min, x_max, y_max) = [
int (max(corner_position*ratio_y, 10)) if idx%2
else int (corner_position*ratio_x)
for idx, corner_position in enumerate(box[:-1])
#Draw a box base on the position, parameters in rectangle function are: image,start_point, end_point, color, thickness.
rgb_image = cv2.rectangle(rgb_image, (x_min,y_min), (x_max,y_max),
colors["green"], 3)
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/516940.html
標籤:Intel Collective Python机器学习计算机视觉约洛开维诺
