loadModel method
Loads the mosquito classification model from the specified path.
This method initializes the PyTorch Lite model used for mosquito species classification. The model is loaded with predefined dimensions optimized for the training dataset and includes species labels for result mapping.
Model Configuration
- Model Path:
assets/models/mosquito_classifier.pt - Input Dimensions: 224x224 pixels (standard ImageNet size)
- Labels Path:
assets/labels/mosquito_species.txt - Normalization: ImageNet mean and standard deviation
Performance Considerations
Model loading is a one-time operation that should be performed during app initialization or when the classification feature is first accessed. The loaded model remains in memory for subsequent classifications.
Error Conditions
- Throws Exception if the platform is not supported (Android/iOS only)
- Throws Exception if the model file is not found in assets
- Throws Exception if the model format is invalid or corrupted
- Throws Exception if insufficient memory is available
Example:
try {
await classificationService.loadModel();
print('Model loaded successfully');
} catch (e) {
print('Failed to load model: $e');
}
Implementation
Future<void> loadModel() async {
String pathImageModel = "assets/models/mosquito_classifier.pt";
try {
_model = await _pytorchWrapper.loadClassificationModel(
pathImageModel, 224, 224,
labelPath: "assets/labels/mosquito_species.txt");
} on PlatformException {
throw Exception("Model loading failed - only supported for Android/iOS");
}
}