简体   繁体   English

我收到此错误如何解决 AttributeError: 'tuple' object has no attribute 'setInput'?

[英]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.

相关问题 获取Python错误:AttributeError:&#39;tuple&#39;对象没有属性&#39;Text&#39; - Getting Python error: AttributeError: 'tuple' object has no attribute 'Text' AttributeError: 'tuple' object has no attribute 'write' 错误 - AttributeError: 'tuple' object has no attribute 'write' Error 如何解决元组 object has no attribute 'split error - how to solve tuple object has no attribute 'split error AttributeError: 'tuple' object 没有属性 - AttributeError: 'tuple' object has no attribute AttributeError: 'tuple' object 没有属性 'values' 在使用单个 function 连接多个嵌套字典时出现错误 - AttributeError: 'tuple' object has no attribute 'values' getting error while concatenate multiple nested dictionaries using single function 为什么会出现“ AttributeError:&#39;tuple&#39;对象没有属性&#39;savefig&#39;”的问题? - Why am I getting “AttributeError: 'tuple' object has no attribute 'savefig'”? 获取“AttributeError:'tuple'对象没有属性”并且无法理解原因 - Getting “AttributeError: 'tuple' object has no attribute” and fail to see why 出现任何错误 AttributeError: 'tuple' object has no attribute 'strip on user registration - Getting any error AttributeError: 'tuple' object has no attribute 'strip on user registration Python / MySQL IN列表错误:AttributeError:&#39;tuple&#39;对象没有属性&#39;keys&#39; - Python/MySQL IN List Error: AttributeError: 'tuple' object has no attribute 'keys' Python 错误:AttributeError: 'tuple' object 没有属性 'write' - Python error: AttributeError: 'tuple' object has no attribute 'write'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM