【问题标题】:How to improve performance net.forward() of cv2.dnn.readNetFromCaffe() , net.forward taking more time(7 to 10 seconds/frame) to give the result如何提高 cv2.dnn.readNetFromCaffe() 的性能 net.forward() , net.forward 需要更多时间(7 到 10 秒/帧)来给出结果
【发布时间】:2019-06-26 14:10:36
【问题描述】:

我使用了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))

【问题讨论】:

  • 使用哪种SSD型号?是基于 VGG 还是 MobileNet?
  • @DmitryKurtaev ,我使用了 openpose 预训练模型,这个模型名称是“pose_deploy.prototxt”,openpose 将它们的权重文件存储为“pose_iter_102000.caffemodel”。肯定这个模型是“VGG”类型的。请找到他们的 github 链接:github.com/CMU-Perceptual-Computing-Lab/openpose/tree/master/…

标签: opencv machine-learning computer-vision caffe openpose


【解决方案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 神经计算棒。

【讨论】:

  • 你能给我一些链接,我可以如何压缩或中继 .caffemodel 和 .prototxt 文件。我还没有在 OpenVINO 中看到任何可用于手关键点识别的模型。 (到目前为止,我可以看到只有 openpose 可以拥有这个经过训练的模型和权重文件)。
【解决方案2】:

我在通过网络之前缩小图像尺寸。

# convert the input frame from BGR to RGB then resize it to have
# a width of 750px (to speed up processing)
rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
rgb = imutils.resize(frame, width=750)
imageBlob = cv2.dnn.blobFromImage(cv2.resize(rgb, (300, 300)), 1.0, (300, 300), (104.0, 177.0, 123.0))

# apply OpenCV's deep learning-based face detector to localize
# faces in the input image
detector.setInput(imageBlob)
detections = detector.forward()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-05-01
    • 1970-01-01
    • 2020-04-12
    • 1970-01-01
    • 2020-09-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多