loadModel method
Loads the local mosquito classification model.
This method initializes the PyTorch Lite model used for local image classification. It must be called before using classifyImage for local classification operations.
Model Loading Process
- Asset Extraction: Copies model file from assets to device storage
- Model Initialization: Loads the PyTorch Lite model into memory
- Label Loading: Loads species labels for result mapping
- Validation: Verifies model is ready for inference
Performance Considerations
- Loading Time: Typically 1-5 seconds depending on device
- Memory Usage: ~50-100MB for model storage in memory
- One-Time Operation: Model remains loaded for app lifetime
- Background Loading: Consider loading during app initialization
Error Conditions
Throws Exception if:
- Platform is not supported (Android/iOS only)
- Model file is missing or corrupted in assets
- Insufficient memory is available for model loading
- PyTorch Lite initialization fails
Example:
try {
await repository.loadModel();
print('Model loaded successfully');
} catch (e) {
print('Failed to load model: $e');
// Handle error - perhaps show web-only classification
}
See also:
- classifyImage which requires the model to be loaded first
- ClassificationService.loadModel for the underlying implementation
Implementation
Future<void> loadModel() async {
await _classificationService.loadModel();
}