I am using cv2.dnn_Net.forward() (forward propagation) for the face detecting pre-trained model. However, I couldn't grasp the idea of utilizing the returned variable from cv2.dnn_Net.forward() function (which is detections variable from below).
face_net = cv2.dnn.readNet(face_prototxt_path, face_weights_path)
image = cv2.imread(args["image_path"])
(h, w) = image.shape[:2]
blob = cv2.dnn.blobFromImage(image, 1.0, (300, 300),
(104.0, 177.0, 123.0))
face_net.setInput(blob)
detections = face_net.forward() # cv2.dnn_Net.forward() function
# Utilizing 'detections' variable
confidence = detections[0, 0, i, 2]
box = detections[0, 0, i, 3:7] * np.array([w, h, w, h])
What does cv2.dnn_Net.forward() return exactly and how can they be utilized as detections[0, 0, i, 2] and detections[0, 0, i, 3:7]?
cv2.dnn.readNet takes your weight file and configuaration file of your model to load your saved model.
net.forward() - Runs a forward pass to compute the net output.
your detection i.e net.forward() will give Numpy ndarray as output which you can use to plot the box on the given input image.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With