gpt4 book ai didi

opencv - 如何提高 cv2.dnn.readNetFromCaffe() 的 net.forward() 性能,net.forward 需要更多时间(7 到 10 秒/帧)才能给出结果

转载 作者:行者123 更新时间:2023-11-30 09:31:54 30 4
gpt4 key购买 nike

我使用了net = cv2.dnn.readNetFromCaffe(protoFile, WeightsFile),然后循环播放实时视频帧以使用net.forward()<来获取每个帧的输出.

但是 net.forward() 每帧需要 7 到 10 秒才能给出结果。请帮助我如何提高性能(减少 net.forward() 中的处理时间)。

意思是:从Step1到Step2每帧需要7到10秒。

(下面的代码中提到了Step1和Step2)。

import cv2
import time
import numpy as np

protoFile = "deploy.prototxt"
weightsFile = "iter_10.caffemodel"

inWidth = 300
inHeight = 300

# web camera
cap = cv2.VideoCapture(0)
hasFrame, frame = cap.read()

net = cv2.dnn.readNetFromCaffe(protoFile, weightsFile)
k = 0
while 1:
k+=1
t = time.time()
print("Start time = {}".format(t))
hasFrame, frame = cap.read()

if not hasFrame:
cv2.waitKey()
print("Wait====>")
break

inpBlob = cv2.dnn.blobFromImage(frame, 1.0 / 255, (inWidth, inHeight),
(0, 0, 0), swapRB=False, crop=False)


net.setInput(inpBlob)

# Step1
print("before forward = {}".format(time.time() - t))

output = net.forward()

# Step2
#taking close to 7 to 10 seconds for each frame
print("forward = {}".format(time.time() - t))

最佳答案

OpenPose 模型本身就很大。有多种方法可以提高效率。

1) 尝试主干版本( .caffemodel.prototxt )。

2) 较低的输入 Blob 分辨率。请注意,这可能会显着降低准确性。

3) 尝试不同的模型。您可以查看使用英特尔推理引擎 (OpenVINO) 构建 OpenCV 的选项并尝试此模型:https://github.com/opencv/open_model_zoo/blob/2018/intel_models/human-pose-estimation-0001/description/human-pose-estimation-0001.md 。如果您只有 Intel CPU 或 GPU 或 Movidius 神经计算棒,则使用第三个选项。

关于opencv - 如何提高 cv2.dnn.readNetFromCaffe() 的 net.forward() 性能,net.forward 需要更多时间(7 到 10 秒/帧)才能给出结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54488986/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com