remap-yolo: Remap Class IDs in YOLO Annotations¶
The remap-yolo command performs bulk remapping of class IDs in YOLO annotation text files according to a provided mapping file. This is useful for harmonizing label indices, merging similar classes, or removing unwanted classes from your dataset.
Usage¶
Parameters¶
MAP_FILE: File (CSV or JSON) containing the class ID remapping definitionsYOLO_DIR: Directory containing YOLO text annotation files to process--output-dir: (Optional) Output directory for remapped annotations; if omitted, original files are overwritten
Data Loss Risk
If --output-dir is not specified, original annotation files will be overwritten without confirmation.
Always use --output-dir when testing a new remapping.
Mapping File Formats¶
The MAP_FILE can be provided in two formats:
CSV Format¶
Simple two-column format with original class IDs in the first column and target class IDs in the second column:
JSON Format¶
A JSON object with original class IDs as keys and target class IDs as values:
Special Values
If a class ID is mapped to a negative value (e.g., -1), annotations with that class will be removed entirely.
How It Works¶
- The command detects the mapping file format based on file extension
- For each text file in the input directory, it:
- Processes each line (each represents one bounding box)
- Checks if the class ID (first value in each line) needs remapping
- Replaces the class ID if a match is found, or removes the line if mapped to a negative value
- Writes the modified annotations either in-place or to the output directory
Processing Details
- Only class IDs that match entries in the mapping file are modified
- Lines with class IDs mapped to negative values are removed completely
- The command reports how many annotation files were modified
Examples¶
Using a CSV mapping file with an output directory:
Using a JSON mapping file and overwriting existing files:
Merging multiple classes into one class ID:
Wheremerge_classes.csv might contain:
This would merge classes 1, 2, and 3 into class 0.