Advanced editing tools for COCO dataset annotations
Project description
pycocoedit
An open-source lightweight Python package for editing and analyzing COCO datasets.
pycocoedit is a Python package for editing and analyzing COCO datasets.
It is particularly useful for specifying which images, annotations, or categories to include or exclude from your dataset.
With pycocoedit, you can apply custom filters to your dataset. These filters allow you to control inclusion or exclusion based on custom conditions for images, categories, and annotations.
For example, you can filter out specific images that have a certain number of annotations or exclude annotations with bounding boxes of a certain aspect ratio.
Usage
Example of filtering images and categories.
from pycocoedit.objectdetection.data import CocoData
from pycocoedit.objectdetection.filter import FilterType, ImageFileNameFilter, CategoryNameFilter
annotation = "path/to/annotation.json"
new_annotation = "path/to/new_annotation.json"
# only include images with file name "image1.jpg" and "image2.jpg"
file_filter = ImageFileNameFilter(FilterType.INCLUSION, ["image1.jpg", "image2.jpg"])
# only include categories with category name "cat" and "dog"
category_filter = CategoryNameFilter(FilterType.INCLUSION, ["cat", "dog"])
coco_data = CocoData(annotation)
# apply filters and export new annotation
coco_data.add_filter(file_filter).add_filter(category_filter).apply_filter().save(new_annotation)
Example of custom filter for annotations:
In this example, we create a custom filter that only includes annotations with bounding boxes of area less than 100.
from pycocoedit.objectdetection.data import CocoData
from pycocoedit.objectdetection.filter import BaseFilter, FilterType, TargetType
# only include annotations with area less than 100
class SmallBboxIncludeFilter(BaseFilter):
def __init__(self):
super().__init__(FilterType.INCLUSION, TargetType.ANNOTATION)
def apply(self, data: dict) -> bool:
return data["area"] < 100
annotation = "path/to/annotation.json"
new_annotation = "path/to/new_annotation.json"
coco_data = CocoData(annotation)
# apply custom filter and export new annotation
coco_data.add_filter(SmallBboxIncludeFilter()).apply_filter().save(new_annotation)
Installation
git clone https://github.com/hachimada/pycocoedit.git
cd pycocoedit
poetry install
Key Features
| Feature | What it gives you |
|---|---|
| LEGO-style chainable filters | One-liner include / exclude rules for images, annotations, categories, etc. |
| Custom rules | simply inherit BaseFilter, implement a short apply() method, and your custom logic is ready to use. |
| Built-in data cleanup | CocoData.correct() - Built-in data cleanup that removes orphaned annotations & empty categories. |
| Pure Python ≥ 3.10 | Zero external deps; runs anywhere CPython runs—no C build hassle. |
| Typed & unit-tested | IDE auto-completion and high confidence when refactoring. |
Task Support
| Task | Supported | version |
|---|---|---|
| Object Detection | ✅ (pycocoedit.objectdetection) |
0.1.0 |
| Image Segmentation | ✅ (use pycocoedit.objectdetection) |
0.1.0 |
| Keypoint Detection | ❌ (future release) | |
| Panoptic Segmentation | ❌ (future release) | |
| Image Captioning | ❌ (future release) |
Roadmap
- Image Captioning
- key-point support
- Panoptic Segmentation
Contributions and ideas are welcome—feel free to open an issue or pull request on GitHub!
License
This project is licensed under the Apache License 2.0 - see the LICENSE file 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 pycocoedit-0.0.1.tar.gz.
File metadata
- Download URL: pycocoedit-0.0.1.tar.gz
- Upload date:
- Size: 10.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.3 CPython/3.12.10 Linux/6.11.0-1014-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
53fa121a0228c155f1fff2579bb81508a0bc2563e9e4ddd88f30c2d6cbc42657
|
|
| MD5 |
2c5fa6b3dee55532fc6abb3a6d9c24cf
|
|
| BLAKE2b-256 |
8b4d61a3e8b693db0e0df31c0df3b9a8eefa45b65da2bc892941bb0ec852f7d5
|
File details
Details for the file pycocoedit-0.0.1-py3-none-any.whl.
File metadata
- Download URL: pycocoedit-0.0.1-py3-none-any.whl
- Upload date:
- Size: 12.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.3 CPython/3.12.10 Linux/6.11.0-1014-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
247c5a2460f46ed0f5ba4c4dc2162ce3e23460f2f8b16c1edf1acd41d27b6741
|
|
| MD5 |
83ddb4067dcaabe904f7329642f18486
|
|
| BLAKE2b-256 |
9705b37fbe5224b44c2977afe861cba3c5b1154182910bb6e3f0d7767e13c20f
|