簡體   English   中英

我收到此錯誤如何解決 AttributeError: 'tuple' object has no attribute 'setInput'?

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

我導入了一張圖片,一切正常,但在運行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'

正如@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")

逗號使net成為一個元組,其中包含 function 調用cv2.dnn.readNetFromCaffe("E:/Face recognition/Models/deploy.prototxt.txt")和字符串"E:/Face recognition/Models/res10_300x300_ssd_iter_140000_fp16.caffemodel" 這相當於

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

在最后一行中,您調用net.setInput(blob)但元組沒有屬性或方法setInput ,這就是您收到錯誤的原因。

可能,您想編寫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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM