predict method

Future<Map<String, dynamic>> predict(
  1. Uint8List imageBytes, {
  2. double? confidenceThreshold,
  3. double? iouThreshold,
})

Runs inference on a single image.

Takes raw image bytes as input and returns a map containing the inference results. The returned map contains:

  • 'boxes': List of detected objects with bounding box coordinates
  • 'detections': List of detections in YOLOResult-compatible format
  • Task-specific data (keypoints for pose, mask for segmentation, etc.)

The model must be loaded with loadModel before calling this method.

Example:

final results = await yolo.predict(imageBytes);
final detections = (results['detections'] as List)
    .map((d) => YOLOResult.fromMap(d as Map));

imageBytes The raw image data as a Uint8List confidenceThreshold Optional confidence threshold (0.0-1.0). Defaults to 0.25 if not specified. iouThreshold Optional IoU threshold for NMS (0.0-1.0). Defaults to 0.7 if not specified. returns A map containing:

  • 'boxes': List of bounding boxes
  • 'detections': List of YOLOResult-compatible detection maps
  • 'keypoints': (pose only) Raw keypoints data from platform throws ModelNotLoadedException if the model has not been loaded throws InferenceException if there's an error during inference

Implementation

Future<Map<String, dynamic>> predict(
  Uint8List imageBytes, {
  double? confidenceThreshold,
  double? iouThreshold,
}) async {
  if (!_isInitialized) {
    final success = await loadModel();
    if (!success) {
      throw ModelNotLoadedException(
        'Model failed to load. Cannot perform inference.',
      );
    }
  }
  return await _inference!.predict(
    imageBytes,
    confidenceThreshold: confidenceThreshold,
    iouThreshold: iouThreshold,
  );
}