Closed SMY92 closed 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.
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.
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!
@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.
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
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.
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)