opencv dnn tensorflow net.forward shape
import cv2 as cv import numpy as np
net = cv.dnn.readNetFromTensorflow('./model/tf_model.pb', './model/model.pbtxt')
img = cv.imread('./data/frame63.jpg')
(h, w) = img.shape[:2]
#cvNet.setInput(cv.dnn.blobFromImage(img, size=(32, 32), swapRB=True, crop=False))
net.setInput (cv.dnn.blobFromImage (img, 1.0 / 127.5, (32, 32), (127.5, 127.5, 127.5), swapRB = True, crop =
False))
detections = net.forward()
print(detections.shape)
for i in range(0, detections.shape[2]):
box = detections[0, 0, i, 3:7] * np.array([w, h, w, h])
startX, startY, endX, endY) = box.astype("int")
confidence = detections[0, 0, i, 2]
# If confidence > 0.5, show box around face
if (confidence > 0.5):
cv.rectangle(img, (startX, startY), (endX, endY), (255, 255, 255), 2)
cv.imshow('img', img)
cv.waitKey()
Only (1,2) will be called so that the 'IndexError: tuple index out of range' error occurs. Is it a matter of my cnn neural network?
please edit your post and insert your code as text
print(detections.shape) --- and the output is ?
(1, 2) will be output
so, you cannot index it the way you want to.
but the shape looks wrong, maybe you got the wrong output layer(s) ?
(what kind of network is it even, exactly ?)
I used the vgg16 model