create static method

(InterpreterOptions, Delegate?) create(
  1. PerformanceConfig? config, {
  2. bool addMediaPipeCustomOps = false,
})

Creates InterpreterOptions and an optional Delegate based on config.

Implementation

static (InterpreterOptions, Delegate?) create(
  PerformanceConfig? config, {
  bool addMediaPipeCustomOps = false,
}) {
  final options = InterpreterOptions();
  if (addMediaPipeCustomOps) options.addMediaPipeCustomOps();
  final effectiveConfig = config ?? const PerformanceConfig();
  final threadCount =
      effectiveConfig.numThreads?.clamp(0, 8) ??
      math.min(4, Platform.numberOfProcessors);
  options.threads = threadCount;

  if (effectiveConfig.mode == PerformanceMode.disabled) {
    return (options, null);
  }
  if (effectiveConfig.mode == PerformanceMode.auto) {
    return _createAutoMode(options, threadCount);
  }
  if (effectiveConfig.mode == PerformanceMode.xnnpack) {
    return _createXnnpack(options, threadCount);
  }
  if (effectiveConfig.mode == PerformanceMode.gpu) {
    return _createGpu(options);
  }
  if (effectiveConfig.mode == PerformanceMode.coreml) {
    return _createCoreml(options);
  }
  return (options, null);
}