Skip to main content

COCO Types

PyPI PyPI - Implementation 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.

Metadata

Release files for coco-types 0.0.10

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for coco-types 0.0.10
File Size Uploaded
coco_types-0.0.10.tar.gz 24.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for coco-types 0.0.10
File Interpreter ABI Platform
coco_types-0.0.10-py3-none-any.whl Python 3 none any Details

Total release size: 32.0 kB

Release files / coco_types-0.0.10.tar.gz

Download URL coco_types-0.0.10.tar.gz
Size 24.8 kB
Tags Source
SHA-256 checksum
How to use checksums
c23933b303feb78bf09310424c6ec2443a1e3b851e9febfc6ce91a822e08a420
BLAKE2b-256 checksum
How to use checksums
c695cc5f809784830a138f3e0472b586dd0d69e59d7f6796a9c2199d9ea0baf5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-httpx/0.24.0

Release files / coco_types-0.0.10-py3-none-any.whl

Download URL coco_types-0.0.10-py3-none-any.whl
Size 7.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4e7e3fc56ea2d21c4aa532771b52b4d641cea114304108a40cdee87c3dee7f8a
BLAKE2b-256 checksum
How to use checksums
484b0ca590124cc0c55e2d27f83d804244b03fe381c647a477d3883c608deb02
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-httpx/0.24.0

Release history Release notifications | RSS feed

This release

0.0.10 This release

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page