Skip to contents

yolo_dataset_autolabel() batch-processes an entire folder of unannotated images using a trained yolo_fewshot_model (from yolo_fewshot_fit()). It predicts bounding boxes or instance segmentation polygons, writes standard YOLO .txt annotation files, splits the data into train, val, and test, and generates a data.yaml descriptor.

It also creates a review/ visual inspection folder with rendered boxes/polygons so the user can quickly audit the automated labels.

Usage

yolo_dataset_autolabel(
  input_dir,
  model,
  output_dir = NULL,
  task = c("detect", "segment"),
  classes = NULL,
  conf_threshold = NULL,
  max_objects = NULL,
  split_ratio = c(0.7, 0.2, 0.1),
  crop_to_objects = FALSE,
  crop_margin = 0.05,
  sahi = FALSE,
  engine = "gpu",
  device_id = -1,
  lower_size = NULL,
  upper_size = NULL,
  size_mode = c("relative", "absolute"),
  move = FALSE,
  as_job = FALSE,
  review = TRUE,
  rainbow = TRUE,
  show_bbox = TRUE,
  show_polygon = TRUE,
  show_points = FALSE,
  show_labels = TRUE,
  show_conf = TRUE,
  bbox = show_bbox,
  polygon = show_polygon,
  points = show_points,
  labels = show_labels,
  badge = TRUE,
  seed = 42,
  verbose = TRUE,
  ...
)

Arguments

input_dir

Directory containing raw unannotated images.

model

A yolo_fewshot_model object fitted with yolo_fewshot_fit().

output_dir

Target directory to write the YOLO dataset. If NULL (default), the dataset structure (images/, labels/, data.yaml) is generated directly inside input_dir. Specify a new directory path only if you wish to create a separate dataset folder.

task

Target task: "segment" (polygons) or "detect" (bounding boxes). Defaults to model$task.

classes

Character vector of class names. If NULL (default), automatically inferred from the model object or metadata.

conf_threshold

Minimum confidence / similarity threshold for accepting predicted instances (e.g. 0.50). If NULL (default), uses model$conf_threshold.

max_objects

Maximum number of objects to detect per image. If NULL (default), no limit is applied.

split_ratio

Numeric vector of length 3 for c(train, val, test) split. Defaults to c(0.70, 0.20, 0.10).

crop_to_objects

Logical. If TRUE, crops the image to the bounding box containing all detected objects plus a margin (default: FALSE).

crop_margin

Numeric. Margin fraction added around the object bounding box when crop_to_objects = TRUE (default: 0.05, i.e., 5%).

sahi

Logical or list. If TRUE (or a named list of SAHI options, e.g. list(slice_width = 640, slice_height = 640, overlap_width_ratio = 0.20)), uses Slicing Aided Hyper Inference (image_detect_sahi() / image_segment_sahi()) instead of standard full-image inference. This is ideal for high-resolution images containing hundreds of small, crowded, or tightly clustered objects (e.g. seeds, capsules, stomata, drone orthophotos). Defaults to FALSE.

engine

Execution engine override: "cpu" or "gpu". If NULL, uses model$engine.

device_id

GPU device ID if engine = "gpu". Defaults to -1.

lower_size

Optional numeric value to filter out small detected objects. When size_mode = "relative" (default), objects with a bounding box area less than lower_size times the mean area of all candidate boxes in that image are removed (e.g., lower_size = 0.2 removes small debris, dust, or grains smaller than 20% of the average object size). When size_mode = "absolute", objects with an area (in pixels) below lower_size are removed. Defaults to NULL (no lower size filter).

upper_size

Optional numeric value to filter out abnormally large detected objects. When size_mode = "relative" (default), objects with a bounding box area greater than upper_size times the mean area of all candidate boxes in that image are removed (e.g., upper_size = 2.0 removes objects larger than 200% of the average object size). When size_mode = "absolute", objects with an area (in pixels) above upper_size are removed. Defaults to NULL (no upper size filter).

size_mode

Character string specifying how lower_size and upper_size are interpreted. "relative" (default) treats values as proportions/multiples of the mean bounding box area. "absolute" treats values as area in pixels.

move

Logical. If TRUE (default), moves the source images to the target split folders instead of copying them, saving disk space and avoiding duplicate files. An undo operation can be performed via yolo_dataset_undo() to restore files to their original location. Defaults to TRUE.

as_job

Logical. If TRUE and running inside RStudio, launches the batch auto-labeling process in the background via RStudio Background Jobs, leaving the main R console completely free. Defaults to FALSE.

review

Logical or integer. If TRUE, writes annotated review images to review/ subfolder for visual inspection. An integer can be provided (e.g. review = 100) to randomly sample that number of images across the dataset to generate review previews. Defaults to TRUE. subfolder for visual inspection of all images. An integer can be provided (e.g. review = 30) to limit the number of review images generated. Setting review = FALSE avoids creating duplicate preview images.

rainbow

Logical. If TRUE, review previews are rendered with distinct rainbow colors per instance. Defaults to TRUE.

show_bbox

Logical. Whether to draw bounding boxes on review previews. Defaults to TRUE. Supported alias: bbox.

show_polygon

Logical. Whether to draw segmentation polygons on review previews. Defaults to TRUE. Supported alias: polygon.

show_points

Logical. If TRUE, draws points at the centroid of each object using the same color as the box. Defaults to FALSE. Supported alias: points.

show_labels

Logical. Whether to display class name on labels/badges in review images. Defaults to TRUE. Supported aliases: show_class, labels.

show_conf

Logical. Whether to display confidence score on labels/badges in review images. Defaults to TRUE. Supported alias: show_scores.

bbox, polygon, points, labels

Backward-compatible aliases for show_bbox, show_polygon, show_points, and show_labels.

badge

Logical. Whether to draw a filled background badge behind labels in review images. Defaults to TRUE.

seed

Random seed for reproducible splitting. Defaults to 42.

verbose

Logical. Show progress messages. Defaults to TRUE.

...

Additional arguments passed to methods or aliases (e.g. show_labels, show_scores, label_box).

Value

A yolo_dataset S3 object pointing to the created dataset.