0

我正在尝试使用 imageai 库中的图像预测工具,但出现以下两个错误...作为初学者,老实说,我无法理解这些错误,也找不到任何答案在线有效。如果有人可以帮我解决它,我将不胜感激。

1.

ImportError: load_weights requires h5py when loading weights from HDF5.

但我确实安装并更新了 h5py。正如其他人在过去的问题中所建议的那样,我还尝试安装 h5py==2.10.0 和 cython,但这对我也不起作用。

2.

ValueError: You have specified an incorrect path to the ResNet model file.

我尝试了几种不同的方法来编写路径,但这仍然行不通。

这是完整的错误文本:

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.

这是我的代码:

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)
4

0 回答 0