AnnotationParser is a universal Python library that parses annotation files from different formats (LabelMe, COCO, VOC, etc.) into a single unified Shape data structure. This allows you to work with annotations using a consistent interface, regardless of the original format.
Project description
AnnotationParser
AnnotationParser is a universal Python library that parses annotation files from various formats (LabelMe, COCO, VOC, etc.) and converts them into a single, unified Shape type.
This approach allows you to read, filter, and save shapes using the same interface, regardless of the original annotation format.
Note: Currently only the LabelMe format is fully implemented and tested. Other formats are planned for future releases (see Limitations & Roadmap).
Table of Contents
- Features
- Usage Examples
- Command-Line Interface (CLI)
- Supported Formats
- Limitations & Roadmap
- Contributing
- Development & Testing
- FAQ / Common Issues
- Author
- License
Features
- Unified API for reading, saving, and filtering shapes in annotation files
- Converts any supported format into a universal
Shapetype for downstream processing - Extensible adapter system for multiple formats (LabelMe, COCO, VOC, ...)
- Functional and OOP usage styles
- High-level filtering and transformation functions for shape objects
- Clean, type-safe, and well-documented codebase
Usage Examples
Installation
Python 3.10+ required
Install with pip (recommended for most users):
pip install annotation-parser
Or, if you have the source code locally:
pip install -e .
Parse and Filter (LabelMe)
from annotation_parser import create, get_shapes_by_label
file = "tests/labelme/labelme_test.json"
parser = create(file, "labelme")
shapes = parser.parse() # tuple of Shape
# Get all shapes with label "person"
persons = get_shapes_by_label(shapes, "person")
print(persons)
Save Annotations
from annotation_parser import save_labelme
save_labelme(shapes, "result.json", backup=True)
Filter by Working Zone, Group Number, Custom Predicate
from annotation_parser import get_shapes_by_wz_number, get_shapes_by_number, filter_shapes
# Filter by working zone (wz_number)
zone2 = get_shapes_by_wz_number(shapes, wz_number=2)
# Filter by instance/group number
group_1 = get_shapes_by_number(shapes, number=1)
# Filter with any condition (lambda)
big_shapes = filter_shapes(shapes, lambda s: hasattr(s, "coords") and len(s.coords) > 3)
OOP Style (Advanced)
from annotation_parser import create
parser = create("tests/labelme/labelme_test.json", "labelme")
shapes = parser.parse()
# You can call parser.save(), parser.parse(), parser.filter_shapes() if needed
Functional Style (shortcut)
from annotation_parser import parse_labelme
shapes = parse_labelme("tests/labelme/labelme_test.json")
Command-Line Interface (CLI) [experimental]
Experimental! Not fully tested. See cli.py for current options.
python cli.py parse --file tests/labelme/labelme_test.json --adapter labelme
python cli.py save --file tests/labelme/labelme_test.json --adapter labelme --out result.json --backup
python cli.py filter --file tests/labelme/labelme_test.json --adapter labelme --label crop
Supported Formats
| Format | Status |
|---|---|
| LabelMe | ✅ Supported |
| COCO | 🕑 Planned |
| Pascal VOC | 🕑 Planned |
| YOLO | 🕑 Planned |
| ... | (Suggest yours!) |
💡 Want to see your annotation format supported? Open an issue or PR — or help me implement a new adapter! Any contribution or feedback on new formats is very welcome.
Limitations & Roadmap
- LabelMe format is currently the only one fully implemented and tested.
- Adapters for other formats (COCO, Pascal VOC, YOLO, etc.) are planned, not yet implemented.
- Standard logging (with configurable log levels and error handling) will be added in future releases.
- The command-line interface (
cli.py) is experimental and not fully tested; improvements needed.
Contributing
- PRs, bug reports, and suggestions are welcome!
- For new formats, contribute an adapter in
src/annotation_parser/adapters/ - All code should be type-checked (
mypy), formatted (black), and covered by tests (pytest).
Development & Testing
-
Install dev dependencies:
poetry install --with dev
-
Run tests:
pytest
FAQ / Common Issues
Q: Why do only LabelMe files work? A: Only the LabelMe adapter is currently implemented. COCO/VOC support is planned.
Q: CLI throws errors or doesn't work as expected?
A: cli.py is not fully tested. Check Limitations & Roadmap and use the Python API for production.
Author
Project: github.com/omigutin/annotation_parser Project Tracker: annotation_parser Project Board Contact: migutin83@yandex.ru
License
MIT License. See LICENSE for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file annotation_parser-0.1.0.tar.gz.
File metadata
- Download URL: annotation_parser-0.1.0.tar.gz
- Upload date:
- Size: 22.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.3 CPython/3.11.9 Windows/10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c0ab7f44ce5af9d64c2f926887391f54e0ec601d58537d3e652b7a55a78b2637
|
|
| MD5 |
f7d4a246d9c95ee11fc6cd621332d61a
|
|
| BLAKE2b-256 |
ba93f326fbd5404bb4b7e5b20508321bb138c79b6218218e1903e11c82db624e
|
File details
Details for the file annotation_parser-0.1.0-py3-none-any.whl.
File metadata
- Download URL: annotation_parser-0.1.0-py3-none-any.whl
- Upload date:
- Size: 33.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.3 CPython/3.11.9 Windows/10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9d3a0514c895ef968505ac12d7c99a613facf5d61ec00e7c3c52aa9b0a1e12ce
|
|
| MD5 |
87614a53c2e47cf5c2e43437bf7172cb
|
|
| BLAKE2b-256 |
5713efa80c33cc6e55fb226bc1aedb2b97cfa54e3be78bfd821b0be645d9c416
|