Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

opencv dnn tensorflow net.forward shape

image description

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?

click to hide/show revision 2
retagged

updated 2019-08-01 06:32:59 -0600

berak gravatar image

opencv dnn tensorflow net.forward shape

image description

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?

opencv dnn tensorflow net.forward shape

image descriptionimport 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?