Loads sample images and their matching .txt annotation labels from a YOLO
dataset directory and displays them in a multi-panel grid with overlaid segmentation polygons
or bounding boxes. By default, randomly samples n images from the requested split.
Usage
yolo_dataset_preview(
dir = "yolo_dataset",
split = c("train", "val", "test"),
show_bbox = TRUE,
show_polygon = TRUE,
show_points = FALSE,
show_labels = TRUE,
bbox = show_bbox,
polygon = show_polygon,
points = show_points,
labels = show_labels,
n = 4L,
which = NULL,
images = NULL,
only_augmented = NULL,
only_original = NULL,
only_tiles = FALSE,
pattern = NULL,
random = is.null(which) && is.null(images),
seed = NULL,
mfrow = NULL,
rainbow = TRUE,
col = NULL,
lwd = 1.5,
fill = NULL,
label_bg = FALSE,
cex = 0.6,
title = TRUE,
save = FALSE,
file_name = NULL,
width = NULL,
height = NULL,
dpi = 300,
...
)Arguments
- dir
Character or
yolo_datasetobject. Path to the dataset directory (or list fromyolo_dataset_export()/yolo_dataset_split()).- split
Character. The subset to preview:
"train"(default),"val", or"test".- show_bbox
Logical. Whether to draw bounding boxes and annotations. Defaults to
TRUE. Supported alias:bbox.- show_polygon
Logical. For segmentation datasets, whether to draw polygons. Defaults to
TRUE. Supported alias:polygon.- show_points
Logical. If
TRUE, draws points at the centroid of each bounding box or polygon using the same color as the box. Defaults toFALSE. Supported alias:points.- show_labels
Logical. If
TRUE(default), displays class name labels. Supported aliases:labels,show_class.- bbox, polygon, points, labels
Backward-compatible aliases for
show_bbox,show_polygon,show_points, andshow_labels.- n
Integer. Number of sample images to preview. Defaults to
4L. Supported aliases:n_images,num_images.- which
Optional integer vector of image indices (e.g.
1:4) or character vector of image names or stems (e.g.c("img_3_aug1", "img_553_aug2")) to plot specific images.- images
Alias for
which.- only_augmented
Logical. If
TRUE, only previews augmented images (containing_aug). Defaults toTRUEifdiris an augmented dataset (yolo_dataset_aug), andFALSEotherwise.- only_original
Logical. If
TRUE, only previews original pristine images (excluding synthetic augmentations_aug[0-9]+, synthetic backgroundssynth_bg_, external backgroundsbg_, and scrambled backgroundsscramble_). Defaults toFALSE(orNULL).- only_tiles
Logical. If
TRUE, only previews tiled crop images (matching_tile_[0-9]+_[0-9]+). Defaults toFALSE.- pattern
Optional regex pattern to filter specific image names (e.g.
"toras5\\.png"). Defaults toNULL.- random
Logical. If
TRUE(default whenwhichisNULL), samples random images from the split. IfFALSE, picks the firstnimages.- seed
Optional integer seed for reproducible random selection.
- mfrow
Numeric vector of length 2 giving
c(rows, cols)for the multi-panel layout.- rainbow
Logical. If
TRUE(default), assigns distinct rainbow colors to each object within the image (matching review previews). IfFALSE, colors are assigned by class.- col
Border color for bounding boxes/polygons. If provided, overrides
rainbowand default class palette.- lwd
Numeric. Line width for borders. Defaults to
1.5.- fill
Fill color for polygons with transparency (e.g.
"#00FF6633"). IfNULL, no fill.- label_bg
Logical. If
TRUE, draws a subtle background badge behind each label. IfFALSE(default), draws clean, discreet text matching review previews without blocking objects.- cex
Numeric. Text size for class name labels. Defaults to
0.6.- title
Logical or character. If
TRUE(default), displays panel titles with filename and object count.- save
Logical. If
TRUE, saves the generated plot to a file. Defaults toFALSE.- file_name
Optional character string. Custom file name or path to save the plot (e.g.
"dataset_preview.png").- width
Numeric. Width of the output plot. If
<= 50, interpreted as inches; if> 50, interpreted as pixels. Defaults tomax(7, nc * 3.5).- height
Numeric. Height of the output plot. If
<= 50, interpreted as inches; if> 50, interpreted as pixels. Defaults tomax(6, nr * 3.5).- dpi
Numeric. Resolution in dots per inch (DPI) for raster formats (PNG, JPEG, TIFF). Defaults to
300.- ...
Additional arguments.
Examples
if (FALSE) { # interactive()
dataset <- yolo_dataset_export(img, dir = "dataset_cafe", model = "persam")
yolo_dataset_preview(dataset, n = 4, random = TRUE)
plot(dataset, n = 6)
plot(dataset, n = 4, save = TRUE, file_name = "preview.png")
}
