ClassificationRepository class

Repository for handling mosquito image classification and observation operations.

This repository orchestrates the classification of mosquito images using both local ML models and web-based prediction services. It enriches classification results with species data from the database and handles observation submissions to the CulicidaeLab ecosystem.

Architecture Pattern

The repository implements the Repository pattern to provide a clean abstraction over multiple data sources and services:

  • Local Classification: On-device PyTorch Lite model inference
  • Remote Classification: Server-based classification with advanced models
  • Data Enrichment: Species and disease information from local database
  • Observation Submission: Integration with CulicidaeLab server API

Classification Workflow

Local Classification

  1. Load and initialize PyTorch Lite model
  2. Process image through local ML model
  3. Enrich results with species data from database
  4. Retrieve associated diseases for identified species
  5. Return comprehensive ClassificationResult

Remote Classification

  1. Upload image to CulicidaeLab server
  2. Receive prediction with probability distribution
  3. Return WebPredictionResult with detailed probabilities

Usage Example

final repository = ClassificationRepository(
  classificationService: classificationService,
  mosquitoRepository: mosquitoRepository,
  httpClient: http.Client(),
);

// Load local model
await repository.loadModel();

// Classify image locally
final result = await repository.classifyImage(imageFile, 'en');
print('Species: ${result.species.name}');
print('Confidence: ${result.confidencePercentage}');
print('Diseases: ${result.relatedDiseases.map((d) => d.name).join(', ')}');

// Get web prediction
final webResult = await repository.getWebPrediction(imageFile);
print('Top prediction: ${webResult.scientificName}');
print('Alternatives: ${webResult.getTopAlternatives(3)}');

Error Handling

The repository handles various error conditions:

  • Model Loading Failures: Platform compatibility, memory constraints
  • Network Errors: Server unavailability, timeout, connectivity issues
  • Data Inconsistencies: Unknown species, missing translations
  • API Errors: Invalid responses, authentication failures

Integration Points

  • CulicidaeLab Server: Remote classification and observation submission
  • Local Database: Species and disease information
  • PyTorch Lite: On-device machine learning inference
  • File System: Image processing and temporary storage

See also:

Constructors

ClassificationRepository({required ClassificationService classificationService, required MosquitoRepository mosquitoRepository, required Client httpClient})
Creates a new classification repository with required dependencies.

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

classifyImage(File imageFile, String languageCode) Future<ClassificationResult>
Classifies a mosquito image and returns enriched results with species data.
getWebPrediction(File imageFile) Future<WebPredictionResult>
Gets a web-based prediction for a mosquito image.
loadModel() Future<void>
Loads the local mosquito classification model.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
submitObservation({required Map<String, dynamic> finalPayload}) Future<Observation>
Submits a mosquito observation to the remote server.
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited