![](/img/trans.png)
[英]ImageAI/Keras can't read ResNet model on Raspberry Pi but works on Windows
[英]ImageAI/Keras can't load ResNet model
我正在嘗試使用 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)
嘗試這個:
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,因為它需要文件的直接路徑,否則您將得到確切的錯誤。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.