[英]FaceAlign AttributeError: 'str' object has no attribute 'shape'
[英]AttributeError: 'str' object has no attribute 'shape' error
您好,當我嘗試測試 CNN model 時,我目前遇到此錯誤。
import cv2
import tensorflow as tf
CATEGORIES = ["cats","dogs"]
def prepare(file):
IMG_SIZE = 50
img_array = cv2.imread(file, cv2.IMREAD_GRAYSCALE)
new_array = cv2.resize(img_array, (IMG_SIZE, IMG_SIZE))
return new_array.reshape(-1, IMG_SIZE, IMG_SIZE, 1)
model = tf.keras.models.load_model("CNN.model")
image = "datasets/test_set/dogs/dog.4001.jpg"
prediction = model.predict([image])
prediction = list(prediction[0])
print(CATEGORIES[prediction.index(max(prediction))])
當我運行代碼時,我收到錯誤:
File "C:\Anaconda\lib\site-packages\tensorflow\python\keras\engine\training_utils.py", line 265, in standardize_single_array
if (x.shape is not None and len(x.shape) == 1 and
AttributeError: 'str' object has no attribute 'shape'
誰能告訴我我的錯誤?
你忘了打電話prepare
……所以,你的image
變量應該是這樣的:
image = prepare("datasets/test_set/dogs/dog.4001.jpg")
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.