Skip to main content

Helper for dealing with MS-COCO annotations

Project description

COCO-Assistant

CircleCI Codacy Badge Code style: black PyPi License License: MIT

Helper for dealing with MS-COCO annotations.

Overview

The MS COCO annotation format along with the pycocotools library is quite popular among the computer vision community. Yet I for one found it difficult to play around with the annotations. Deleting a specific category, combining multiple mini datasets to generate a larger dataset, viewing distribution of classes in the annotation file are things I would like to do without writing a separate script for each. The COCO Assistant is designed (or being designed) to assist with this problem. Please note that currently, the Assistant can only help out with object detection datasets. Any contributions and/or suggestions are welcome.

Requirements

Your data directory should look as follows:

Example:
.
├── images
│   ├── train
│   ├── val
|   ├── test
|   
├── annotations
│   ├── train.json
│   ├── val.json
│   ├── test.json

Installation

1. Installation: pip

pip install coco-assistant

2. Installation: From Source

# Clone the repository
git clone https://github.com/ashnair1/COCO-Assistant.git
# Build and install the library
make

Usage

Usage is similar to how you would use pycocotools

from coco_assistant import COCO_Assistant

# Specify image and annotation directories
img_dir = os.path.join(os.getcwd(), 'images')
ann_dir = os.path.join(os.getcwd(), 'annotations')

# Create COCO_Assistant object
cas = COCO_Assistant(img_dir, ann_dir)

Package features

1. Merge datasets

The merge function allows you to merge multiple datasets.

In[1]: cas = COCO_Assistant(img_dir, ann_dir)                                                                                                                                                              
loading annotations into memory...
Done (t=0.09s)
creating index...
index created!
loading annotations into memory...
Done (t=0.06s)
creating index...
index created!

In[2]: cas.merge(merge_images=True)                                                                                                                                                                                       
Merging image dirs
100%|█████████████████████████████████████████████████████████████████████| 2/2 [00:00<00:00, 18.33it/s]
Merging annotations
100%|█████████████████████████████████████████████████████████████████████| 2/2 [00:00<00:00, 14.72it/s]

The merged dataset (images and annotation) can be found in ./results/merged

2. Remove categories

Removes a specific category from an annotation file.

In[1]: cas = COCO_Assistant(img_dir, ann_dir)                                                                                                                                                              
loading annotations into memory...
Done (t=0.09s)
creating index...
index created!
loading annotations into memory...
Done (t=0.06s)
creating index...
index created!

# In interactive mode
In[2]: cas.remove_cat(interactive=True)
['tiny.json', 'tiny2.json']
Choose directory index (1:first, 2: second ..):
1

Categories present:
['building', 'vehicles']

Enter categories you wish to remove as a list:
['building']
Removing specified categories...

# In non-interactive mode
In[3]: cas.remove_cat(interactive=False, jc="tiny.json", rcats=['building'])
Removing specified categories...

The modified annotation can be found in ./results/removal

3. Generate annotation statistics

  1. Generate countplot of instances per category that occur in the annotation files. cas.ann_stats(stat="area",arearng=[10,144,512,1e5],save=False)

  2. Generate pie-chart that shows distribution of objects according to their size (as specified in areaRng). cas.ann_stats(stat="cat", arearng=None, show_count=False, save=False)

4. Visualise annotations

Couldn't pycocotools visualise annotations (via showAnns) as well? Sure it could, but I required a way to freely view all the annotations of a particular dataset so here we are.

In[1]: cas.visualise()
Choose directory index (1:first, 2: second ..):
['tiny', 'tiny2']
1

5. Generate segmentation masks

The cas.get_segmasks() function allows you to create segmentation masks from your MS COCO object detection datasets. Please ensure your category ids start from 1. Similar to the Pascal VOC dataset, the mask values are their classes and a colour palette is applied (optional) to enable visualisation. The generated masks are stored in the ./results folder. Samples are shown below.

Detection Segmentation
SpaceNet SpaceNet SpaceNet_mask
iSAID iSAID iSAID_mask

Contributing

Refer CONTRIBUTING.md

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

coco_assistant-0.3.5.tar.gz (17.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

coco_assistant-0.3.5-py3-none-any.whl (18.2 kB view details)

Uploaded Python 3

File details

Details for the file coco_assistant-0.3.5.tar.gz.

File metadata

  • Download URL: coco_assistant-0.3.5.tar.gz
  • Upload date:
  • Size: 17.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.6.6

File hashes

Hashes for coco_assistant-0.3.5.tar.gz
Algorithm Hash digest
SHA256 767f66ec379ceb85a4e7e4234a9c1ad8e90ffb2784a054603873018b55a6b40c
MD5 fdbcb69c771c83f45dcbe0a4bb380b4c
BLAKE2b-256 4a6f6910357ec707cd40be0c5ada02e0412e770caadd2629a7c7e4ff4cf04377

See more details on using hashes here.

File details

Details for the file coco_assistant-0.3.5-py3-none-any.whl.

File metadata

  • Download URL: coco_assistant-0.3.5-py3-none-any.whl
  • Upload date:
  • Size: 18.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.6.6

File hashes

Hashes for coco_assistant-0.3.5-py3-none-any.whl
Algorithm Hash digest
SHA256 084c5441e5debad0770e2d0f4f37606929769d5bfae0e0d1790e74f05c1f6b34
MD5 04a003b18f1e63417df9e6d9cd5d3ce1
BLAKE2b-256 18a2f45d27d15d41a691ea21a89722b3d92022109a2aaf34a004d7821d82a337

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page