简体   繁体   中英

Iam getting this error how to solve AttributeError: 'tuple' object has no attribute 'setInput'?

I have imported a picture and everything is fine but I am getting an AttributeError when running net.setInput(blob) .

import numpy as np
import cv2

#load the image
img=cv2.imread(r"E:\Face recognition\3_FaceDetection_FeatureExtraction\images\faces.jpg")

cv2.imshow('faces',img)
cv2.waitKey(0)
cv2.destroyAllWindows()
print(img)
net = cv2.dnn.readNetFromCaffe("E:/Face recognition/Models/deploy.prototxt.txt"),("E:/Face recognition/Models/res10_300x300_ssd_iter_140000_fp16.caffemodel")

#extract blob
blob = cv2.dnn.blobFromImage(img, 1, (300,300), (104,177,123), swapRB=False)
net.setInput(blob)
AttributeError                            Traceback (most recent call last)
Input In [6], in <cell line: 1>()
----> 1 net.setInput(blob)

AttributeError: 'tuple' object has no attribute 'setInput'

As @ Dan Mašek mentioned in his comment, the critical line is

net = cv2.dnn.readNetFromCaffe("E:/Face recognition/Models/deploy.prototxt.txt"),("E:/Face recognition/Models/res10_300x300_ssd_iter_140000_fp16.caffemodel")

The comma makes net a tuple containing the return value of the function calll cv2.dnn.readNetFromCaffe("E:/Face recognition/Models/deploy.prototxt.txt") and the string "E:/Face recognition/Models/res10_300x300_ssd_iter_140000_fp16.caffemodel" . This is equivalent to

>>> a = 4, "abc"
>>> a
(4, 'abc')
>>> type(a)
tuple

In the last line you call net.setInput(blob) but a tuple has not attribute or method setInput , which is why you get the error.

Probably, you wanted to write net = cv2.dnn.readNetFromCaffe("E:/Face recognition/Models/deploy.prototxt.txt", "E:/Face recognition/Models/res10_300x300_ssd_iter_140000_fp16.caffemodel") or simply net = cv2.dnn.readNetFromCaffe("E:/Face recognition/Models/deploy.prototxt.txt") (I do not know the method readNetFromCaffe , so I do not know what it requires as input).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM