Reputation: 61
I am working on a project on Python that detects disease on leaves and sprays fertilizer on the leaf.
After many hours of troubleshooting other errors, I came down to the following final error that always happens and I can't seem to fix.
Following are the versions I have used for the dependencies so far:
Error that I am facing:
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'
Code file 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()
Upvotes: 6
Views: 7302