### This is my code:
from imageai.Prediction.Custom import CustomImagePrediction
import os
execution_path = os.getcwd()
prediction = CustomImagePrediction()
prediction.setModelTypeAsResNet()
prediction.setModelPath("idenprof_061-0.7933.h5")
prediction.setJsonPath("model_class.json")
prediction.loadModel(num_objects=5)
predictions, probabilities = prediction.predictImage("image.jpg", result_count=3)
for eachPrediction, eachProbability in zip(predictions, probabilities):
print(eachPrediction , " : " , eachProbability)
This is the response i get from command prompt
C:\Python36\CustomTraining>newcustomtraining.py
WARNING: Logging before flag parsing goes to stderr.
W0718 16:08:34.773948 9944 deprecation.py:506] From C:\Python36\lib\site-packages\tensorflow\python\ops\init_ops.py:1251: calling VarianceScaling.__init__ (from tensorflow.python.ops.init_ops) with dtype is deprecated and will be removed in a future version.
Instructions for updating:
Call initializer instance with the dtype argument instead of passing it to the constructor
Traceback (most recent call last):
File "C:\Python36\lib\site-packages\imageai\Prediction\Custom__init__.py", line 385, in loadModel
model = ResNet50(model_path=self.modelPath, weights="trained", model_input=image_input, num_classes=self.numObjects)
File "C:\Python36\lib\site-packages\imageai\Prediction\ResNet\resnet50.py", line 111, in ResNet50
model.load_weights(weights_path)
File "C:\Python36\lib\site-packages\tensorflow\python\keras\engine\training.py", line 162, in load_weights
return super(Model, self).load_weights(filepath, by_name)
File "C:\Python36\lib\site-packages\tensorflow\python\keras\engine\network.py", line 1412, in load_weights
with h5py.File(filepath, 'r') as f:
File "C:\Python36\lib\site-packages\h5py_hl\files.py", line 394, in __init__
swmr=swmr)
File "C:\Python36\lib\site-packages\h5py_hl\files.py", line 170, in make_fid
fid = h5f.open(name, flags, fapl=fapl)
File "h5py_objects.pyx", line 54, in h5py._objects.with_phil.wrapper
File "h5py_objects.pyx", line 55, in h5py._objects.with_phil.wrapper
File "h5py\h5f.pyx", line 85, in h5py.h5f.open
OSError: Unable to open file (unable to open file: name = 'C:\Python36\CustomTraining\idenprof_resnet.h5', errno = 2, error message = 'No such file or directory', flags = 0, o_flags = 0)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Python36\CustomTraining\newcustomtraining.py", line 11, in
predictor.loadModel(num_objects=5)
File "C:\Python36\lib\site-packages\imageai\Prediction\Custom__init__.py", line 389, 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.
maybe the model file path is incorrect
'No such file or directory' in the error code shows your model file is not in the path specified in your code.
im having a similar issue. i haven't found a solution yet but if you have can you let me know
Same here
2019-10-09 14:43:44.102841: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
2019-10-09 14:43:44.114607: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x7f88fbc8a1d0 executing computations on platform Host. Devices:
2019-10-09 14:43:44.114637: I tensorflow/compiler/xla/service/service.cc:175] StreamExecutor device (0): Host, Default Version
Traceback (most recent call last):
File "/Users/Ron/Desktop/ImageRecognition/venv/lib/python3.7/site-packages/imageai/Prediction/__init__.py", line 125, in loadModel
model = ResNet50(model_path=self.modelPath, model_input=image_input)
File "/Users/Ron/Desktop/ImageRecognition/venv/lib/python3.7/site-packages/imageai/Prediction/ResNet/resnet50.py", line 108, in ResNet50
model.load_weights(weights_path)
File "/Users/Ron/Desktop/ImageRecognition/venv/lib/python3.7/site-packages/tensorflow_core/python/keras/engine/training.py", line 181, in load_weights
return super(Model, self).load_weights(filepath, by_name)
File "/Users/Ron/Desktop/ImageRecognition/venv/lib/python3.7/site-packages/tensorflow_core/python/keras/engine/network.py", line 1171, in load_weights
with h5py.File(filepath, 'r') as f:
File "/Users/Ron/Desktop/ImageRecognition/venv/lib/python3.7/site-packages/h5py/_hl/files.py", line 408, in __init__
swmr=swmr)
File "/Users/Ron/Desktop/ImageRecognition/venv/lib/python3.7/site-packages/h5py/_hl/files.py", line 173, in make_fid
fid = h5f.open(name, flags, fapl=fapl)
File "h5py/_objects.pyx", line 54, in h5py._objects.with_phil.wrapper
File "h5py/_objects.pyx", line 55, in h5py._objects.with_phil.wrapper
File "h5py/h5f.pyx", line 88, in h5py.h5f.open
esnet50_weights_tf_dim_ordering_tf_kernels.h5', errno = 2, error message = 'No such file or directory', flags = 0, o_flags = 0)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "main.py", line 8, in <module>
prediction.loadModel()
File "/Users/Ron/Desktop/ImageRecognition/venv/lib/python3.7/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.
I'm using venv btw.
@RonZhang724 i think you have to change the '\' to '/' before resnet50_weights_tf_dim_ordering_tf_kernels.h5 in your code
https://medium.com/@guymodscientist/image-prediction-with-10-lines-of-code-3266f4039c7a