如何提高cv2.dnn.readNetFromCaffe()的net.forward()性能,net.forward花费更多时间(7到10秒/帧)来给出结果

问题描述 投票:0回答:1

我使用了net = cv2.dnn.readNetFromCaffe(protoFile, weightsFile)然后循环实时视频帧以使用net.forward()获得每帧的输出。

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

意思是:从步骤1到步骤2,每帧需要7到10秒。

(以下代码中提到了步骤1和步骤2)。

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))
opencv machine-learning computer-vision caffe openpose
1个回答
1
投票

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 Neural Compute Stick。

© www.soinside.com 2019 - 2024. All rights reserved.