withClassifierOptions static method

YOLO withClassifierOptions({
  1. required String modelPath,
  2. YOLOTask? task,
  3. required Map<String, dynamic> classifierOptions,
  4. bool useGpu = true,
  5. bool useMultiInstance = false,
})

Creates a YOLO instance with classifier options for custom preprocessing

This constructor is specifically designed for classification models that need custom preprocessing, such as 1-channel grayscale models. 1-channel support is detected automatically from the model's input tensor.

Supported keys: labels (class names when the model has no embedded metadata), enableColorInversion, enableMaxNormalization, inputMean, and inputStd.

Example:

final yolo = YOLO.withClassifierOptions(
  modelPath: 'assets/handwriting_model.tflite',
  task: YOLOTask.classify,
  classifierOptions: {
    'enableColorInversion': true,
    'enableMaxNormalization': true,
  },
);

if need custom Normalization:

final grayscaleOptions = {
  'enableMaxNormalization': false,
  'inputMean': 127.5,
  'inputStd': 127.5,
  // 'labels': [...] (if the model has no embedded labels)
};

Implementation

static YOLO withClassifierOptions({
  required String modelPath,
  YOLOTask? task,
  required Map<String, dynamic> classifierOptions,
  bool useGpu = true,
  bool useMultiInstance = false,
}) {
  return YOLO(
    modelPath: modelPath,
    task: task,
    useGpu: useGpu,
    useMultiInstance: useMultiInstance,
    classifierOptions: classifierOptions,
  );
}