ImageClassification fails to load custom ResNet50 model with ".pt" file
Author: KaleBats123Created Nov 30, 2024Updated Jun 5, 2025
Environment Details;
- OS: Windows 11
- Python Version: 3.12
- ImageAI Version: 3.0.3
- PyTorch Version: 2.5.1+cu118
Problem Description;
When attempting to load a custom-trained ResNet50 model using ImageAI's ImageClassification, the model fails to load with the error:
"Classification failed: Model not yet loaded. You need to call '.loadModel()' before performing image classification"
Reproduction Steps;
- Initialize ImageClassification
- Set model path using
setModelPath() - Set model type using
setModelTypeAsResNet50() - Call
loadModel()
Code Snippet;
from imageai.Classification import ImageClassification
classifier = ImageClassification()
classifier.setModelPath("path/to/model.pt")
classifier.setModelTypeAsResNet50()
classifier.loadModel() # Fails hereAdditional Context; Model trained using custom dataset Model saved as '.pt' file Attempting to use for image classification
Questions; Does ImageAI support loading custom-trained models? Are there specific model export requirements?
Source: OlafenwaMoses/ImageAI