loadModel method

Future<void> loadModel()

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

  1. Asset Extraction: Copies model file from assets to device storage
  2. Model Initialization: Loads the PyTorch Lite model into memory
  3. Label Loading: Loads species labels for result mapping
  4. 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:

Implementation

Future<void> loadModel() async {
  await _classificationService.loadModel();
}