![](/img/trans.png)
[英]The error that I get is AttributeError: 'NoneType' object has no attribute 'date'
[英]I get this error --> AttributeError: 'NoneType' object has no attribute 'predict'
我多次收到此錯誤。
Traceback (most recent call last):
File "E:\AI and ML-pr\day14\test.py", line 38, in <module>
result = loaded_model.predict(test_image)
AttributeError: 'NoneType' object has no attribute 'predict'
我想找出植物葉子的病害。
我的代碼::
# importing libraries
import numpy as np
from keras.preprocessing import image
from keras.models import Sequential
from keras.layers.core import Dense
from keras.models import model_from_json
import os
import cv2
#loading tha model
json_file=open('modell.json','r')
loaded_model_json=json_file.read()
json_file.close()
loaded_model=model_from_json(loaded_model_json)
# load weights into new model
loaded_model = loaded_model.load_weights("modell.h5")
print("Loaded model succesfully**")
label = ['Apple___Apple_scab','Apple___Black_rot','Apple___Cedar_apple_rust','Apple___healthy',
'Blueberry___healthy','Cherry_(including_sour)___healthy','Cherry_(including_sour)___Powdery_mildew','Corn_(maize)___Cercospora_leaf_spot Gray_leaf_spot','Corn_(maize)___Common_rust_', 'Corn_(maize)___healthy','Corn_(maize)___Northern_Leaf_Blight','Grape___Black_rot','Grape___Esca_(Black_Measles)','Grape___healthy','Grape___Leaf_blight_(Isariopsis_Leaf_Spot)','Orange___Haunglongbing_(Citrus_greening)','Peach___Bacterial_spot','Peach___healthy','Pepper,_bell___Bacterial_spot','Pepper,_bell___healthy','Potato___Early_blight','Potato___healthy','Potato___Late_blight','Raspberry___healthy','Soybean___healthy','Squash___Powdery_mildew','Strawberry___healthy','Strawberry___Leaf_scorch','Tomato___Bacterial_spot','Tomato___Early_blight','Tomato___healthy','Tomato___Late_blight','Tomato___Leaf_Mold','Tomato___Septoria_leaf_spot','Tomato___Spider_mites Two-spotted_spider_mite','Tomato___Target_Spot','Tomato___Tomato_mosaic_virus','Tomato___Tomato_Yellow_Leaf_Curl_Virus']
path="E:\AI and ML-pr\day14\images_for_test\AppleCedarRust1.jpg"
test_image=image.load_img(path,target_size=(128,128))
#print(test_image)
test_image=image.img_to_array(test_image)
test_image=np.expand_dims(test_image,axis=1)
result = loaded_model.predict(test_image)
print(result)
fresult=np.max(result)
label2=label[result.argmax()]
print(label2)
請解決我的問題
問題似乎是這一行: loaded_model = loaded_model.load_weights("modell.h5")
加載 TensorFlow 格式的權重文件時,返回與 tf.train.Checkpoint.restore 相同的狀態對象。 在構建圖形時,一旦網絡構建完成,恢復操作就會自動運行(在第一次調用從模型繼承的用戶定義類時,如果它已經構建,則立即運行)。
以 HDF5 格式加載權重時,返回 None。
因此,看起來就像將行更改為: loaded_model.load_weights("modell.h5")
可以解決您的問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.