Skip to contents

yolo_train_workflow() implements a complete active-learning bootstrap pipeline:

  1. Few-Shot Sampling: Selects a small subset of representative sample images (e.g., 3–4 images) from an unlabelled dataset directory.

  2. Auto-Annotation via Few-Shot / Exemplar Matching: Uses yolo_dataset_export() with Meta PerSAM (or Grounded-SAM) to accurately annotate the sampled images.

  3. Offline Augmentation: Optionally expands those few images with yolo_dataset_augment() into 20–50+ diverse images (3D perspective warping, contrast CLAHE, random cutout, noise, blur, rotations).

  4. High-Resolution Tiling: Optionally slices images into uniform tiles with yolo_dataset_tiling() (e.g. 640x640), optimizing small object resolution and dataset volume.

  5. Automated Training: Trains a high-performance YOLO model via yolo_train().

  6. Model Export: Produces ready-to-deploy .onnx and .pt model files that can be directly passed into yolo_dataset_autolabel() to annotate thousands of remaining images in a few seconds!

Usage

yolo_train_workflow(
  data,
  sample_n = 4L,
  sample_images = NULL,
  model_fewshot = "persam",
  class_names = "object",
  task = c("detect", "segment"),
  prompt = NULL,
  prompt_mode = c("first", "each"),
  sim_threshold = 0.7,
  crop_to_objects = TRUE,
  crop_margin = 0.1,
  augment = TRUE,
  augment_total = 30L,
  augment_args = list(),
  tiling = TRUE,
  tile_size = 640L,
  tiling_args = list(),
  train_model = "yolo26n",
  epochs = 50L,
  batch = 8L,
  device = "auto",
  close_mosaic = 15L,
  output_dir = pliman_model_dir(),
  output_name = NULL,
  temp_dir = NULL,
  dataset_dir = NULL,
  keep_dataset = TRUE,
  as_job = FALSE,
  review = FALSE,
  show_class = FALSE,
  show_conf = FALSE,
  badge = FALSE,
  interactive = is.null(prompt) && base::interactive(),
  verbose = TRUE,
  ...
)

Arguments

data

Directory path containing unlabelled images (e.g. "dataset_complex"), or a vector of image paths.

sample_n

Number of images to sample from data if sample_images is not provided (default 4L).

sample_images

Optional vector of specific image paths or filenames to label. If NULL (default), samples sample_n images from data.

model_fewshot

Few-shot / exemplar model to label the sample images. Defaults to "persam". Can also be "grounded-sam", "ben2", or an existing model.

class_names

Names of the classes to detect. Defaults to "object".

task

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

prompt

Visual exemplar prompt points or bounding box for PerSAM, or text prompt for Grounded-SAM. If NULL (default) and interactive = TRUE, opens an interactive locator window on the first sampled image.

prompt_mode

Prompt reuse mode: "first" (default, prompt once on image 1 and propagate to all sample images) or "each" (prompt on each sample image).

sim_threshold

Similarity threshold for PerSAM (default 0.70).

crop_to_objects

Logical. Whether to crop sampled images to object bounding boxes with margin. Defaults to TRUE.

crop_margin

Margin proportion around objects when cropping (default 0.10).

augment

Logical. Whether to apply offline data augmentation (default TRUE).

augment_total

Target total number of augmented training images (default 30L).

augment_args

List of custom arguments passed to yolo_dataset_augment().

tiling

Logical. Whether to apply dataset tiling (default TRUE).

tile_size

Tile size in pixels (default 640).

tiling_args

List of custom arguments passed to yolo_dataset_tiling().

train_model

Base pre-trained YOLO architecture to train (default "yolo26n", or "yolo11n", "yolo26s").

epochs

Number of training epochs (default 50).

batch

Batch size (default 8L, or 4L on low-VRAM GPUs).

device

Device to train on ("auto", 0, or "cpu"). Defaults to "auto".

close_mosaic

Number of final epochs to disable mosaic augmentation (default 15).

output_dir

Target directory to save the final exported .onnx and .pt model files. Defaults to pliman_model_dir().

output_name

Filename for the exported model (e.g. "model_capsulas.onnx"). If NULL, an informative name based on data is automatically generated.

temp_dir

Directory used to construct the bootstrap training dataset. If NULL (default), creates a temporary folder inside tempdir().

dataset_dir

Optional character directory path to save or reuse the constructed YOLO training dataset. If NULL (default), uses temp_dir or creates a persistent directory when keep_dataset = TRUE.

keep_dataset

Logical. If FALSE (default), removes the temporary bootstrap dataset after training.

as_job

Logical. If TRUE and running inside RStudio, launches the entire workflow (bootstrapping, augmentation, tiling, and YOLO training) as an asynchronous RStudio Background Job, immediately freeing up the R console. Default is FALSE. If TRUE, keeps the folder intact.

review

Logical. Whether to generate review preview images during few-shot labeling (default FALSE).

show_class

Logical. Whether to display class names on labels/badges during review (default FALSE).

show_conf

Logical. Whether to display confidence values on labels/badges during review (default FALSE).

badge

Logical. Whether to draw a filled badge behind label text (default FALSE).

interactive

Logical. Whether to allow interactive clicking/refinement (default interactive()).

verbose

Logical. Whether to display informative progress messages (default TRUE).

...

Additional arguments passed to yolo_train() (e.g., scale = 0.35, degrees = 15).

Value

An object of class c("yolo_workflow", "yolo_train") containing:

  • model_file: Path to the exported .onnx model ready for inference.

  • pt_file: Path to the PyTorch .pt model weights.

  • classes: Class names.

  • task: Task type ("detect" or "segment").

  • sample_images: Paths of the sample images used for bootstrap labeling.

  • dataset_dir: Path to the training dataset (if keep_dataset = TRUE).

  • workflow: Summary list of workflow parameters and metadata.

  • Plus all metrics, diagnostic plots, and summaries from yolo_train().

Examples

if (FALSE) { # interactive()
library(pliman)

# 1. Run bootstrap workflow: label 4 sample images with PerSAM, augment to 30, tile 640, train YOLO
wf <- yolo_train_workflow(
  data = "dataset_complex",
  sample_n = 4,
  model_fewshot = "persam",
  class_names = "cápsula",
  augment = TRUE,
  augment_total = 30,
  tiling = TRUE,
  tile_size = 640,
  train_model = "yolo26n",
  epochs = 50,
  output_name = "modelo_capsulas.onnx"
)

# 2. Automatically propagate trained model across ALL hundreds of images in the folder!
ds_full <- yolo_dataset_autolabel("dataset_complex", model = wf, output_dir = "dataset_full")
}