Giter Club home page Giter Club logo

coco-types's Introduction

COCO Types

PyPI PyPI - Python Version PyPI - Downloads License Linting Tests

Package for handling COCO datasets types.
Note: This package loads the data as is and does not create dictionaries mapping ids to lists of images/annotations/categories.

Installation

The package is available on pypi here, you can install it with:

pip install coco-types

Loading COCO data

You can load COCO dataset labels into Pydantic objects by using the Dataset and DatasetKP classes.

For an object detection dataset:

import coco_types

with open("path/to/json", encoding="utf-8") as data_file:
    dataset = coco_types.Dataset.parse_raw(data_file.read())

For a keypoint detection dataset:

import coco_types

with open("path/to/json", encoding="utf-8") as data_file:
    dataset = coco_types.DatasetKP.parse_raw(data_file.read())

Usage example:

import coco_types

with open("path/to/json", encoding="utf-8") as data_file:
    dataset = coco_types.Dataset.parse_raw(data_file.read())

img = dataset.images[0]
print(f"Image's filename {img.file_name}")
print(f"Image's id {img.id}")
print(f"Image's height {img.height}")
print(f"Image's width {img.width}")

img_annotations = [annotation for annotation in dataset.annotations
                   if annotation.image_id == img.id]
ann = img_annotations[0]
print(f"Annotation's id: {ann.id}")
print(f"Annotation's image id: {ann.image_id}")
print(f"Annotation's category id: {ann.category_id}")
print(f"Annotation's iscrowd: {ann.iscrowd}")
print(f"Annotation's bbox: {ann.bbox}")
print(f"Annotation's area {ann.area}")

for cat in dataset.categories:
    if cat.id == ann.category_id:
        break

print(f"Category's name {cat.name}")
print(f"Category's supercategory {cat.supercategory}")

Keypoints

If using a dataset with keypoints (coco_types.DatasetKP), then annotations will have two additional attributes: keypoints and num_keypoints.
In the same way, categories will have two additional attributes: keypoints and skeleton.

TypedDict versions

A TypedDict version of the pydantic models can be accessed using coco_types.dicts.* (for example coco_types.dicts.Dataset). This can be useful if you have data that is slightly malformed / follows a slightly different format but is still usable.

coco-types's People

Contributors

hoel-bagard avatar

Watchers

 avatar

Forkers

demycode

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.