Giter Site home page Giter Site logo

coco-assistant's Introduction

COCO-Assistant

CircleCI PyPI version 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)

So what can this package do?:

Merge datasets

The combine function allows you to merge multiple datasets.

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!

cas.combine()                                                                                                                                                                                       
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/combination

Remove_cat

Removes a specific category from an annotation file.

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!

cas.remove_cat()
['tiny.json', 'tiny2.json']
Select categories to use
tiny.json

Categories present:
['building', 'vehicles]

Select categories to use:
building
['building']
Press n if you're done entering categories, else continue
n
Using specified categories...

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

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", show_count=False, save=False)

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.

cas.visualise()
Choose directory:
['tiny', 'tiny2']

Todo:

  1. Converter for converting COCO annotations to YOLO format
  2. Write tests for stats, converters and visualiser.

coco-assistant's People

Contributors

ashnair1 avatar dependabot[bot] avatar justhungryman avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.