loadModel method

Future<bool> loadModel()

Loads the YOLO model for inference.

This method must be called before predict to initialize the model. Returns true if the model was loaded successfully, false otherwise.

Example:

bool success = await yolo.loadModel();
if (success) {
  print('Model loaded successfully');
} else {
  print('Failed to load model');
}

@throws ModelLoadingException if the model file cannot be found @throws PlatformException if there's an issue with the platform-specific code

Implementation

Future<bool> loadModel() async {
  try {
    final result = await _channel.invokeMethod('loadModel', {
      'modelPath': modelPath,
      'task': task.name,
    });
    return result == true;
  } on PlatformException catch (e) {
    if (e.code == 'MODEL_NOT_FOUND') {
      throw ModelLoadingException('Model file not found: $modelPath');
    } else if (e.code == 'INVALID_MODEL') {
      throw ModelLoadingException('Invalid model format: $modelPath');
    } else if (e.code == 'UNSUPPORTED_TASK') {
      throw ModelLoadingException('Unsupported task type: ${task.name} for model: $modelPath');
    } else {
      throw ModelLoadingException('Failed to load model: ${e.message}');
    }
  } catch (e) {
    throw ModelLoadingException('Unknown error loading model: $e');
  }
}