[英]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)
.我导入了一张图片,一切正常,但在运行
net.setInput(blob)
时出现AttributeError
。
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正如@Dan Mašek在他的评论中提到的,关键是
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"
.逗号使
net
成为一个元组,其中包含 function 调用cv2.dnn.readNetFromCaffe("E:/Face recognition/Models/deploy.prototxt.txt")
和字符串"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.在最后一行中,您调用
net.setInput(blob)
但元组没有属性或方法setInput
,这就是您收到错误的原因。
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).可能,您想编写
net = cv2.dnn.readNetFromCaffe("E:/Face recognition/Models/deploy.prototxt.txt", "E:/Face recognition/Models/res10_300x300_ssd_iter_140000_fp16.caffemodel")
或简单地net = cv2.dnn.readNetFromCaffe("E:/Face recognition/Models/deploy.prototxt.txt")
(我不知道方法readNetFromCaffe
,所以我不知道它需要什么作为输入)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.