create static method

Future<FaceDetection> create(
  1. FaceDetectionModel model, {
  2. InterpreterOptions? options,
  3. PerformanceConfig? performanceConfig,
})

Creates and initializes a face detection model instance.

This factory method loads the specified TensorFlow Lite model from package assets and prepares it for inference. Different model variants are optimized for different use cases (see FaceDetectionModel for details).

The options parameter allows you to customize the TFLite interpreter configuration (e.g., number of threads, use of GPU delegate).

The performanceConfig parameter enables hardware acceleration delegates. Use PerformanceConfig.xnnpack() for 2-5x speedup on CPU. If both options and performanceConfig are provided, options takes precedence.

Returns a fully initialized FaceDetection instance ready to detect faces.

Note: Most users should use the high-level FaceDetector class instead of working with this low-level API directly.

Example:

// Default (auto mode)
final detector = await FaceDetection.create(
  FaceDetectionModel.frontCamera,
);

// With XNNPACK acceleration
final detector = await FaceDetection.create(
  FaceDetectionModel.backCamera,
  performanceConfig: PerformanceConfig.xnnpack(),
);

Throws StateError if the model cannot be loaded or initialized.

Implementation

static Future<FaceDetection> create(
  FaceDetectionModel model, {
  InterpreterOptions? options,
  PerformanceConfig? performanceConfig,
}) => _createWithLoader(
  model: model,
  load: (opts) => Interpreter.fromAsset(
    'packages/face_detection_tflite/assets/models/${faceDetectionModelFile(model)}',
    options: opts,
  ),
  options: options,
  performanceConfig: performanceConfig,
);