switchModel method

Future<void> switchModel(
  1. String newModelPath,
  2. YOLOTask newTask
)

Implementation

Future<void> switchModel(String newModelPath, YOLOTask newTask) async {
  if (_viewId == null) {
    throw StateError('Cannot switch model: view not initialized');
  }

  try {
    final Map<String, dynamic> arguments = {
      'viewId': _viewId,
      'modelPath': newModelPath,
      'task': newTask.name,
      'useGpu': _useGpu,
    };

    if (_instanceId != 'default') {
      arguments['instanceId'] = _instanceId;
    }

    await _channel.invokeMethod('setModel', arguments);
  } on PlatformException catch (e) {
    throw YOLOErrorHandler.handleError(
      e,
      'Failed to switch to model $newModelPath for task ${newTask.name}',
    );
  } catch (e) {
    throw YOLOErrorHandler.handleError(
      e,
      'Failed to switch to model $newModelPath for task ${newTask.name}',
    );
  }
}