net.forward()的返回类型

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

嗨,我正在通过使用带有tensorflow的更快的rcnn模型来检测人。在我引用的代码中提到

net = cv2.dnn.readNetFromTensorflow(args["inferencegraph"],args["graphpbtxt"])

以及此后:

detections = net.forward()

我没有得到确切的检测以及检测的内容?例如,它是列表还是元组,它的元素是什么?

python opencv tensorflow object-detection faster-rcnn
1个回答
0
投票

[cv2.dnn.readNetFromTensorflow”将使用您的Protobuf文件.pb和模型.pbtxt的配置文件来加载保存的模型。

net.forward()-运行前向通过以计算净输出。

您的检测,即net.forward()将给出Numpy ndarray作为输出,您可以用它在给定的输入图像上绘制框。

您可以考虑以下示例。

import cv2

# Load a model imported from Tensorflow
tensorflowNet = cv2.dnn.readNetFromTensorflow('frozen_inference_graph.pb', 'graph.pbtxt')

# Input image
img = cv2.imread('img.jpg')
rows, cols, channels = img.shape

# Use the given image as input, which needs to be blob(s).
tensorflowNet.setInput(cv2.dnn.blobFromImage(img, size=(300, 300), swapRB=True, crop=False))

# Runs a forward pass to compute the net output
networkOutput = tensorflowNet.forward()

# Loop on the outputs
for detection in networkOutput[0,0]:

    score = float(detection[2])
    if score > 0.2:

        left = detection[3] * cols
        top = detection[4] * rows
        right = detection[5] * cols
        bottom = detection[6] * rows

        #draw a red rectangle around detected objects
        cv2.rectangle(img, (int(left), int(top)), (int(right), int(bottom)), (0, 0, 255), thickness=2)

# Show the image with a rectagle surrounding the detected objects 
cv2.imshow('Image', img)
cv2.waitKey()
cv2.destroyAllWindows()  

我考虑过Inception-SSD v2作为重量文件,可以从here下载。和[link的配置文件。

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