I'm trying to use the Image Prediction tool in the imageai library, and I'm getting the following two errors... As a beginner, I honestly can't make sense of the errors, and I couldn't find any answers online that worked. If anyone could please help me solve it I would greatly appreciate it.
1.
ImportError: load_weights requires h5py when loading weights from HDF5.
But I do have h5py installed and updated. I also tried installing h5py==2.10.0 and cython, as others suggested in past questions, but that hasn't worked for me either.
2.
ValueError: You have specified an incorrect path to the ResNet model file.
I have tried several different ways of writing the path but this still won't work.
This is the full error text:
Traceback (most recent call last):
File "C:\Users\MYUSER\Miniconda3\envs\tensorflow\lib\site-packages\imageai\Prediction\__init__.py", line 125, in loadModel
model = ResNet50(model_path=self.modelPath, model_input=image_input)
File "C:\Users\MYUSER\Miniconda3\envs\tensorflow\lib\site-packages\imageai\Prediction\ResNet\resnet50.py", line 115, in ResNet50
model.load_weights(weights_path)
File "C:\Users\MYUSER\Miniconda3\envs\tensorflow\lib\site-packages\tensorflow\python\keras\engine\training.py", line 2341, in load_weights
raise ImportError(
ImportError: `load_weights` requires h5py when loading weights from HDF5.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\MYUSER\Current_Working_Directory\brain.py", line 10, in <module>
prediction.loadModel()
File "C:\Users\MYUSER\Miniconda3\envs\tensorflow\lib\site-packages\imageai\Prediction\__init__.py", line 129, in loadModel
raise ValueError("You have specified an incorrect path to the ResNet model file.")
ValueError: You have specified an incorrect path to the ResNet model file.
This is my code:
from imageai.Prediction import ImagePrediction
import os
execution_path=os.getcwd()
prediction = ImagePrediction()
prediction.setModelTypeAsResNet()
prediction.setModelPath(os.path.join(execution_path, "resnet50_imagenet_tf.2.0.h5"))
prediction.loadModel()
predictions, probabilities = prediction.predictImage(os.path.join(execution_path, "giraffe.jpg"), result_count=5 )
for eachPrediction, eachProbability in zip(predictions, probabilities):
print(eachPrediction , " : " , eachProbability)