我正在試驗這種用于人員檢測的openVINO Zoo 模型。我堅持的是,如果我正確處理模型架構。這是模型輸入和模型輸出的資訊。(所有 3 個鏈接都指向同一頁面,但位置不同)
import cv2
import numpy as np
import matplotlib.pyplot as plt
from openvino.runtime import Core
MODEL = "person-detection-asl-0001"
PRECISION = "FP16"
MODEL_PATH = "./person-detection-asl-0001/"
CHAR = "/"
FILE_TYPE = ".xml"
FULL_MODEL_STR = MODEL_PATH CHAR PRECISION CHAR MODEL FILE_TYPE
print("testing model")
print(FULL_MODEL_STR)
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(FULL_MODEL_STR)
print("COMPILED MODEL: ", compiled_model)
# Get input size - Recognition.
height, width = list(input_key.shape)[2:]
print("MODEL DIMENSIONS: ", (height, width))
image = cv2.imread("./ben_sarah.JPG")
# cv2.imshow("image",image)
image_mod = cv2.resize(image, (width, height))
image_mod = image_mod.transpose((2, 0, 1))
image_mod = image_mod.reshape(1, 3, height, width)
# Run inference.
boxes = compiled_model([image_mod])[compiled_model.output('boxes')]
print(f"{MODEL} BOXES.SHAPE: {boxes.shape}")
def postprocess(result, image):
aligns = image.shape
detections = result.reshape(-1, 5)
for i, detection in enumerate(detections):
xmin, ymin, xmax, ymax, confidence = detection
if confidence > 0.2:
xmin = int(max((xmin * image.shape[1]), 10))
ymin = int(max((ymin * image.shape[0]), 10))
xmax = int(min((xmax * image.shape[1]), image.shape[1] - 10))
ymax = int(min((ymax * image.shape[0]), image.shape[0] - 10))
conf = round(confidence, 2)
print(f"conf: {conf:.2f}")
print((xmin, ymin),(xmax, ymax))
# For bounding box
cv2.rectangle(image, (xmin, ymin),
(xmax, ymax), (255, 255, 255), 5)
# For the text background
# Finds space required
(w, h), _ = cv2.getTextSize(
f"{conf:.2f}", cv2.FONT_HERSHEY_SIMPLEX, 1.7, 1)
# Prints the text.
cv2.rectangle(image, (xmin, ymin h 5),
(xmin w 5, ymin), (255, 255, 255), -1)
cv2.putText(image, f"{conf:.2f}", (xmin, ymin h),
cv2.FONT_HERSHEY_SIMPLEX, 1.7, (0, 0, 0), 3)
return image
final = postprocess(boxes, image)
cv2.imwrite(f"./outputs/{PRECISION}-{MODEL}.png", final)
cv2.imshow("final", final)
代碼運行......但是用于在檢測到的人周圍創建框的模型輸出,坐標不正確。
例如在postprocess函式中,我認為我做錯了:
print(f"conf: {conf:.2f}")
print((xmin, ymin),(xmax, ymax))
回傳:
conf: 0.50
(29012, 127753) (1270, 950)
如果(29012, 127753)要表示的數字 (xmin, ymin) 不正確,我認為這超出了整個影像的坐標。原文image.shape是(960, 1280, 3)。
uj5u.com熱心網友回復:
我猜你想要從影像邊緣至少有十個像素的邊距來繪制邊界框,所以你需要:
xmin = int(max(xmin, 10))
ymin = int(max(ymin, 10))
xmax = int(min(xmax, image.shape[1] - 10))
ymax = int(min(ymax, image.shape[0] - 10))
如果 xmin、ymin、xmax、ymax 已經是整數,則不需要 int() 包裝器。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/517751.html
標籤:Intel Collective Pythonopencv机器学习计算机视觉开维诺
上一篇:Tomcat 調優之從 Linux 內核原始碼層面看 Tcp backlog
下一篇:異步行程不切換布爾觸發器
