
Interactively or Programmatically Review YOLO Dataset Annotations
Source:R/utils_yolo_train.R
yolo_dataset_review.RdRevies annotations for a specific image in a YOLO dataset. Supports interactive inspection,
removing false positive objects (by clicking on boxes/masks, center dots, or by index),
adding missed objects, re-labeling from scratch or appending detections using deep learning models
(e.g., PerSAM one-shot visual exemplars, YOLO ONNX/PT models, Grounded-SAM text prompts, or classical
segmentation via analyze_objects()), and synchronizing updated labels with visual review previews.
Usage
yolo_dataset_review(
dir = "yolo_dataset",
image = NULL,
which = NULL,
split = c("train", "val", "test", "all"),
model = NULL,
task = c("detect", "segment"),
mode = c("edit", "replace", "append"),
class_names = NULL,
class_id = NULL,
prompt = NULL,
interactive = base::interactive(),
remove = NULL,
keep = NULL,
delete_image = FALSE,
box_threshold = 0.25,
text_threshold = 0.25,
sim_threshold = 0.5,
min_dist = 20,
iou_threshold = 0.5,
min_area = 15,
filter_edge = FALSE,
backup = TRUE,
resume = TRUE,
review = TRUE,
rainbow = TRUE,
show_bbox = TRUE,
show_polygon = TRUE,
show_points = FALSE,
show_labels = TRUE,
show_indices = TRUE,
point_pch = 19,
point_cex = 1.6,
engine = c("gpu", "cpu"),
device_id = -1,
verbose = TRUE,
...
)
yolo_dataset_edit(
dir = "yolo_dataset",
image = NULL,
which = NULL,
split = c("train", "val", "test", "all"),
model = NULL,
task = c("detect", "segment"),
mode = c("edit", "replace", "append"),
class_names = NULL,
class_id = NULL,
prompt = NULL,
interactive = base::interactive(),
remove = NULL,
keep = NULL,
delete_image = FALSE,
box_threshold = 0.25,
text_threshold = 0.25,
sim_threshold = 0.5,
min_dist = 20,
iou_threshold = 0.5,
min_area = 15,
filter_edge = FALSE,
backup = TRUE,
resume = TRUE,
review = TRUE,
rainbow = TRUE,
show_bbox = TRUE,
show_polygon = TRUE,
show_points = FALSE,
show_labels = TRUE,
show_indices = TRUE,
point_pch = 19,
point_cex = 1.6,
engine = c("gpu", "cpu"),
device_id = -1,
verbose = TRUE,
...
)
yolo_image_review(
dir = "yolo_dataset",
image = NULL,
which = NULL,
split = c("train", "val", "test", "all"),
model = NULL,
task = c("detect", "segment"),
mode = c("edit", "replace", "append"),
class_names = NULL,
class_id = NULL,
prompt = NULL,
interactive = base::interactive(),
remove = NULL,
keep = NULL,
delete_image = FALSE,
box_threshold = 0.25,
text_threshold = 0.25,
sim_threshold = 0.5,
min_dist = 20,
iou_threshold = 0.5,
min_area = 15,
filter_edge = FALSE,
backup = TRUE,
resume = TRUE,
review = TRUE,
rainbow = TRUE,
show_bbox = TRUE,
show_polygon = TRUE,
show_points = FALSE,
show_labels = TRUE,
show_indices = TRUE,
point_pch = 19,
point_cex = 1.6,
engine = c("gpu", "cpu"),
device_id = -1,
verbose = TRUE,
...
)
yolo_image_edit(
dir = "yolo_dataset",
image = NULL,
which = NULL,
split = c("train", "val", "test", "all"),
model = NULL,
task = c("detect", "segment"),
mode = c("edit", "replace", "append"),
class_names = NULL,
class_id = NULL,
prompt = NULL,
interactive = base::interactive(),
remove = NULL,
keep = NULL,
delete_image = FALSE,
box_threshold = 0.25,
text_threshold = 0.25,
sim_threshold = 0.5,
min_dist = 20,
iou_threshold = 0.5,
min_area = 15,
filter_edge = FALSE,
backup = TRUE,
resume = TRUE,
review = TRUE,
rainbow = TRUE,
show_bbox = TRUE,
show_polygon = TRUE,
show_points = FALSE,
show_labels = TRUE,
show_indices = TRUE,
point_pch = 19,
point_cex = 1.6,
engine = c("gpu", "cpu"),
device_id = -1,
verbose = TRUE,
...
)Arguments
- dir
Character or
yolo_datasetobject. Path to the YOLO dataset root directory (default:"yolo_dataset").- image
Character vector, integer vector, or
NULL. The image(s) to edit. Can be:A character vector of image paths, filenames, or stems (e.g.,
imgsfromlist.files(),"img_001.jpg", orc("ds1_001.jpg", "ds2_002.jpg")).A numeric vector of 1-based indices matching the
[index]shown inyolo_dataset_preview()(e.g.,image = 1orwhich = 12)."all": Reviews all images in the dataset sequentially.NULL(default): lists available images and prompts the user in interactive sessions.
- which
Optional integer vector or character vector. Alias for
image(e.g.,yolo_dataset_review("wood_log_seg", which = 12)).- split
Optional character string (
"train","val","test", or"all"). When numeric indices are passed viawhichorimage, selects which split folder to index (defaults to"train", matchingyolo_dataset_preview()).- model
Character or
NULL. Model to use for re-labeling or object extraction:"persam"or"sam-exemplar": One-shot interactive exemplar-guided segmentation/detection using SAM 2.1."grounded-sam": Open-vocabulary text prompt detection using Grounding DINO + SAM.An ONNX or PT model file path (e.g.,
"yolo11n.onnx","best.pt", or standard YOLO model name).NULL(default): edits existing annotations without running a new model (or runs classicalanalyze_objects()if segmentation arguments are passed).
- task
Character. The YOLO task:
"detect"(bounding boxes) or"segment"(polygons). Auto-detected from dataset if available.- mode
Character. How model predictions interact with existing labels:
"replace"(default whenmodelis provided): Replaces existing annotations with new predictions."append": Keeps existing annotations and appends new model predictions."edit"(default whenmodelisNULL): Starts from existing annotations and allows interactive or programmatic additions/deletions.
- class_names
Character vector. Class names for the dataset. If
NULL(default), automatically inferred fromdata.yamlor existing annotations.- class_id
Integer vector. Numeric class IDs corresponding to
class_names.- prompt
Character, list, or matrix. Prompt for model inference (text prompt for Grounded-SAM, or exemplar coordinates for PerSAM).
- interactive
Logical. Whether to activate the interactive graphical editor (using
graphics::locator()) to click-to-delete unwanted objects and click-to-add missed objects. Defaults tobase::interactive().- remove
Integer vector or
"all". Specific object indices to remove programmatically (e.g.,remove = c(2, 5)).- keep
Integer vector. Specific object indices to retain, removing all others.
- delete_image
Logical. If
TRUE, permanently deletes the specified image(s), matching.txtlabel file(s), and review preview(s) from the dataset. Can also be triggered interactively by typingrm. Defaults toFALSE. Supported alias:rm.- box_threshold
Numeric. Confidence threshold for bounding box detection (default:
0.25).- text_threshold
Numeric. Text threshold for Grounded-SAM (default:
0.25).- sim_threshold
Numeric. Cosine similarity threshold for PerSAM exemplar matching (default:
0.50).- min_dist
Numeric. Minimum pixel distance between object centers for PerSAM (default:
20).- iou_threshold
Numeric. NMS IoU threshold for overlapping detections (default:
0.50).- min_area
Numeric. Minimum pixel area to keep an object (default:
15).- filter_edge
Logical. Whether to automatically filter out border artifacts touching image edges (default:
FALSE).- backup
Logical. Whether to create a backup of the original
.txtlabel file as<stem>.txt.bakbefore saving (default:TRUE).- resume
Logical. When reviewing the whole dataset (
image = NULLor"all"), whether to continue a previous review by showing only the images not reviewed yet (default:TRUE). Images saved ([Enter],c,n,p,q) or skipped (s) are recorded in.review_log.txtat the dataset root;abortdoes not record the current image. If there is no log yet (reviews made before it existed), images with a label backup (<stem>.txt.bak) are taken as reviewed. Useresume = FALSEto clear the log and review all images again from the start (label backups are kept). Explicit selections viaimage/whichare always shown, reviewed or not.- review
Logical. Whether to update the visual review image in
review/review_<stem>.jpgif present (default:TRUE).- rainbow
Logical. If
TRUE(default), uses distinct rainbow palette colors for each object.- show_bbox
Logical. Whether to display bounding box rectangles (default:
TRUE).- show_polygon
Logical. Whether to display segmentation polygons (default:
TRUE).- show_points
Logical. Whether to display solid colored dots at object centers (default:
FALSE).- show_labels
Logical. Whether to display class names and confidence badges (default:
TRUE).- show_indices
Logical. Whether to display object index numbers (
#1,#2, ...) for easy identification (default:TRUE).- point_pch
Integer. Plotting symbol for center points (default:
19, solid circle).- point_cex
Numeric. Size of center points (default:
1.6).- engine
Character. Execution engine:
"gpu"(default) or"cpu".- device_id
Integer. GPU device ID (default:
-1for auto).- verbose
Logical. Whether to display formatted progress and messages via
cli(default:TRUE).- ...
Additional arguments passed to
analyze_objects()or model inference.
Value
An invisible list containing:
- image_path
Full path to the image file
- label_path
Full path to the updated
.txtlabel file- boxes
data.frameof updated bounding boxes and coordinates- polygons
listof updated segmentation polygons- n_objects
Number of saved objects
- backup_path
Path to backup file (if created)
Details
yolo_dataset_review() follows the exact same engine and argument conventions as yolo_dataset_export().
It can be used in two complementary modes:
Interactive GUI: Launches an interactive graphics session where the user can click on unwanted objects to delete them (
[r]), click opposite corners to add new bounding boxes ([a]), delete objects by index directly in console ([d <index>]), or re-run exemplar matching with PerSAM.Programmatic Scripting: Specify
remove = c(2, 5)to drop objects,keep = c(1, 3)to retain specific instances, or passmodel = "persam"/model = "best.onnx"to re-annotate automatically.
When changes are confirmed, the original .txt file is safely backed up as <stem>.txt.bak (if backup = TRUE),
coordinates are written in normalized YOLO format, and the review image in review/review_<stem>.jpg is updated.
Examples
if (FALSE) { # \dontrun{
# 1. Interactive editing: click to remove broken/unwanted seeds, press [c] to save
yolo_dataset_review("meu_dataset", image = "img_005.jpg")
# 2. Relabel image with PerSAM (click 1 exemplar object to re-segment all instances)
yolo_dataset_review("meu_dataset", image = "img_005.jpg", model = "persam")
# 3. Relabel using a custom trained ONNX model
yolo_dataset_review("meu_dataset", image = "img_005.jpg", model = "yolo11n.onnx")
# 4. Programmatic removal of objects #2 and #5 without opening GUI
yolo_dataset_review("meu_dataset", image = "img_005.jpg", remove = c(2, 5))
# 5. Review the whole dataset in several sessions: each call shows only the
# images not reviewed yet; resume = FALSE starts over from the first image
yolo_dataset_review("meu_dataset")
yolo_dataset_review("meu_dataset", resume = FALSE)
} # }