我试图在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)发布于 2022-07-19 14:25:47
试试这个:
from imageai.Detection import ObjectDetection
import os
execution_path = os.getcwd()
detector = ObjectDetection()
detector.setModelTypeAsRetinaNet()
detector.setModelPath( os.path.join(execution_path , "resnet50_coco_best_v2.1.0.h5"))
detector.loadModel()
detections, objects_path = detector.detectObjectsFromImage(input_image=os.path.join(execution_path , "input.jpg"), output_image_path=os.path.join(execution_path , "output.jpg"), minimum_percentage_probability=10, extract_detected_objects=True)
for eachObject, eachObjectPath in zip(detections, objects_path):
print(eachObject["name"] , " : " , eachObject["percentage_probability"], " : ", eachObject["box_points"] )
print("Object's image saved in " + eachObjectPath)
print("--------------------------------")Imagenet算法也不适用于我,但是使用coco算法(在ImageAI的Github上下载)可以节省我大量的时间和精力。
另外,您的代码不适合于windows,因为它需要直接对文件进行平铺,否则您将得到准确的错误。
https://stackoverflow.com/questions/70909867
复制相似问题