我正在研究Python的一个项目,它可以检测叶子上的疾病,并在叶子上喷洒肥料。
在对其他错误进行了许多小时的故障排除之后,我开始讨论以下总是发生的最终错误,并且似乎无法修复。
以下是到目前为止用于依赖项的版本:
我面临的错误:
Traceback (most recent call last):
File "leaf_cnn.py", line 12, in <module>
model = load_model('Leaf_CNN.h5')
File "/home/pi/.local/lib/python3.7/site-packages/tensorflow/python/keras/saving/save.py", line 207, in load_model
compile)
File "/home/pi/.local/lib/python3.7/site-packages/tensorflow/python/keras/saving/hdf5_format.py", line 182, in load_model_from_hdf5
model_config = json_utils.decode(model_config.decode('utf-8'))
AttributeError: 'str' object has no attribute 'decode'代码文件leaf_cnn.py
# importing files/dependencies
from tensorflow.keras.models import load_model
import cv2
import numpy as np
#import Categories
import time
import RPi.GPIO as GPIO
#loading model/ML algorithm
model = load_model('Leaf_CNN.h5')
cap = cv2.VideoCapture(0) # capture frame
ret, img = cap.read()
channel = 21
GPIO.setmode(GPIO.BCM)
GPIO.setup(channel,GPIO.OUT)
#cv2.imshow('aaa',img) 'display image with title'
img = cv2.resize(img,(224,224))
img = np.reshape(img,[1,224,224,3])
classes = model.predict(img)
y_pred = np.argmax(classes, axis=1)
y_pred = Categories.categories[int(y_pred)]
if "healthy" not in y_pred:
GPIO.output(21, GPIO.HIGH) #turn-on relay
time.sleep(1)
else:
GPIO.output(21, GPIO.LOW) #turn-off relay
time.sleep(1)
#cv2.waitKey(0)
#cv2.destroyAllWindows()发布于 2021-03-26 19:56:13
似乎有一个问题与h5py,它必须安装在一个特定的版本,以确保与tensorflow兼容。这就是对我来说的诀窍:
pip uninstall h5py
pip install h5py==2.10.0https://stackoverflow.com/questions/66508872
复制相似问题