Loading and Saving Annotations
SAM Annotator provides robust functionality for loading and saving annotations in various formats. This guide explains how to manage your annotation data effectively.
Annotation Storage Structure
When you specify a category path for your annotations, SAM Annotator creates the following directory structure:
category_path/
├── images/ # Place your images here
├── labels/ # Annotation files will be saved here
├── masks/ # Visualization of masks will be saved here
├── metadata/ # Metadata about annotations
└── exports/ # Exported annotations in various formats
File Formats
SAM Annotator uses a text-based format for storing annotations internally, but can export to multiple industry-standard formats.
Internal Format
Annotations are stored in the labels/
directory with .txt
files corresponding to each image. Each line represents a polygon annotation in the following format:
class_id x1 y1 x2 y2 ... xn yn
Where:
- class_id
is the numeric ID of the annotation class
- x1 y1, x2 y2, ...
are normalized coordinates (0-1) of the polygon vertices
Visualization
For each annotated image, SAM Annotator creates a visualization in the masks/
directory. This visualization shows:
- The segmentation mask on the left
- The original image with a semi-transparent overlay on the right
These visualizations make it easy to review your annotations visually.
Automatic Saving
Annotations are automatically saved when:
1. You press the S
key
2. You navigate to another image (using N
or P
keys)
3. You exit the application
Loading Annotations
When you open an image that has existing annotations, SAM Annotator automatically loads them. The process works as follows:
- SAM Annotator looks for a corresponding
.txt
file in thelabels/
directory - If found, it loads the polygon coordinates and scales them to match the current display dimensions
- Annotations are displayed on the image with their assigned class colors
Manual Importing (Coming Soon)
Support for manually importing annotations from other tools and formats is planned for a future release.
Caching
SAM Annotator implements a caching mechanism to improve performance when working with large datasets. This means:
- Loaded annotations are kept in memory for faster access
- The cache is automatically cleared when needed to manage memory usage
- You can manually clear the cache by restarting the application
Common Issues
Missing Annotations
If annotations aren't appearing for an image:
- Check if the corresponding .txt
file exists in the labels/
directory
- Verify that the filename matches the image (same name, different extension)
- Ensure the annotation file has the correct format
Corrupted Annotation Files
If annotation files become corrupted:
1. Look for backup files in the backups/
directory
2. Restore the backup by copying it to the labels/
directory with the correct filename
Best Practices
- Create Regular Backups: Use the backup functionality to save your progress
- Consistent Naming: Keep image filenames consistent to avoid issues with annotation matching
- Check Visualizations: Review the mask visualizations to ensure annotations are correct
- Export Regularly: Export your annotations to standard formats periodically