OlafenwaMoses / ImageAI

A python library built to empower developers to build applications and systems with self-contained Computer Vision capabilities
https://www.genxr.co/#products
MIT License
8.55k stars 2.19k forks source link

2 errores in Custom Prediction #80

Closed SMY92 closed 5 years ago

SMY92 commented 5 years ago

Recently, I'm trying to train my own custom prediction model using ImageAI. The training process seems good. However, when I tried to run prediction with them, none of them could work. For the model SqueezeNet, there is only one problem which is "ValueError: Shapes (1, 1, 512, 3) and (2, 512, 1, 1) are incompatible". For the other three models, there is one more problem which is "ValueError: You have specified an incorrect path to the DenseNet model file.". The code I used is quit simple. En the case of SqueezeNet: Here is the code for training:

import os

os.environ["CUDA_VISIBLE_DEVICES"]="-1"

from imageai.Prediction.Custom import ModelTraining model_trainer = ModelTraining() model_trainer.setModelTypeAsSqueezeNet() model_trainer.setDataDirectory("Samples") model_trainer.trainModel(num_objects=2, num_experiments=30, enhance_data=True, batch_size=64, show_network_summary=True)

Here is the code for prediction:

from imageai.Prediction.Custom import CustomImagePrediction import os

execution_path = os.getcwd()

prediction = CustomImagePrediction() prediction.setModelTypeAsResNet() prediction.setModelPath(os.path.join(execution_path, "model_ex-030_acc-0.500000.h5")) prediction.setJsonPath(os.path.join(execution_path, "model_class.json")) prediction.loadModel()

predictions, probabilities = prediction.predictImage(os.path.join(execution_path, "image1.jpg"))

for eachPrediction, eachProbability in zip(predictions, probabilities): print(eachPrediction , " : " , eachProbability)

OlafenwaMoses commented 5 years ago

If you you trained your network with SqueezeNet, you must set the model type as SqueezeNet too in your CustomImagePrediction.

You training and prediction network must be the same.

SMY92 commented 5 years ago

Sorry. I posted the wrong code. Do you means to write 'prediction.setModelTypeAsSqueezesNet()' instead of 'prediction.setModelTypeAsResNet()'? If you do, unfortunately, I've already done that.

pytesnim commented 5 years ago

My confusion is I don't know when 'model_ex-030_acc-0.500000.h5' is created? Do we download it from somewhere? Or is it the output of custom training? Thanks very much!

OlafenwaMoses commented 5 years ago

@pytesnim In the folder where your dataset is contained, check for the folder with the name models . You will find all the generated model in there.

tryinggo commented 5 years ago

Why Report an error "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." ,For custom image prediction

OlafenwaMoses commented 5 years ago

Hello @SMY92 @pytesnim @tryinggo , thank you all for your patience. This issue has been resolved in the latest version (v2.0.3). See the link below for details on this.

https://github.com/OlafenwaMoses/ImageAI/blob/master/imageai/Prediction/CUSTOMPREDICTION.md#custompredictionmultiple