Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does cv2.dnn_Net.forward() function return exactly?

Tags:

python

opencv

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]?

like image 767
Backrub32 Avatar asked Feb 13 '26 02:02

Backrub32


1 Answers

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.

like image 154
Prabhat Kumar Sahu Avatar answered Feb 15 '26 14:02

Prabhat Kumar Sahu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!