Skip to main content

Unofficial APIs for the MS-COCO dataset using PyTorch

Project description

pytorchcocotools

Build Documentation GitHub Release PyPI - Package Version PyPI - Python Version Docs with MkDocs uv linting: ruff ty prek security: bandit Semantic Versions Copier License

Unofficial APIs for the MS-COCO dataset using PyTorch. Uses the official repository of the pycocotools packages as reference.

The file format is explained in the official documentation and nicely summarized here.

[!WARNING] This is work in progress, feel free to contribute!

Features

  • Strongly typed COCO data format represetation
  • Drop-in compatible COCO and COCOeval classes
  • (Almost) drop-in compatible mask methods
  • Pure torch implementation
  • torchvision data set using the latest transformation API
  • fully unit tested and documented

Installation

With pip:

python -m pip install pytorchcocotools

With uv:

uv add pytorchcocotools

How to use it

Pretty much all you need to do is to change the import statement from pycocotools to pytorchcocotools:

-import pycocotools
+import pytorchcocotools

So all imports look like this:

from pytorchcocotools.coco import COCO
from pytorchcocotools.cocoeval import COCOeval

...

API

[!WARNING] While the API is mostly compatible with the original pycocotools package, there are some differences. For some methods you need to adapt the handling of the return type. See the examples below.

[!NOTE] All methods are documented with detailed type hints.

mask

All methods now have a optional device and requires_grad parameters that allows to specify the device on which the masks should be created and whether gradients are required. This is useful for acceleration.

[!IMPORTANT] > decode, encode, toBbox and frPyObjects now always return the batch/channel dimension implementation as opposed to a single return element if only a single element was passed. This was done to make the API more consistent by providing single, defined return types, but is open for further discussion.

COCO

One major difference is that the COCO class now uses a strongly typed data structure to represent the COCO data format. This makes it easier to work with the data and to understand the structure of the data, but also might cause problems with data sources that do not strictly follow the data format.

COCOeval

Strongly typed as well. Includes also minor fixes, e.g. the __str__ now also returns the stats.

Other additions

  • pytorchcocotools.utils.coco.download.CocoDownloader: While gsutils rsync is the officially recommended way to download the data, this allows you to trigger the download from Python.
  • The logger property in both all classes from the logging module replaces the print command, so you can fully customize it.
  • pytorchcocotools.torch.dataset.CocoDetection: A drop-in replacement for the dataset from torchvision, now strongly typed using the new transforms.v2 api.

Docs

uv run mkdocs build -f ./mkdocs.yml -d ./_build/

Update template

copier update --trust -A --vcs-ref=HEAD

Credits

This project was generated with 🚀 python project template.

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

pytorchcocotools-0.2.0.tar.gz (53.4 kB view details)

Uploaded Source

Built Distribution

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

pytorchcocotools-0.2.0-py3-none-any.whl (71.2 kB view details)

Uploaded Python 3

File details

Details for the file pytorchcocotools-0.2.0.tar.gz.

File metadata

  • Download URL: pytorchcocotools-0.2.0.tar.gz
  • Upload date:
  • Size: 53.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for pytorchcocotools-0.2.0.tar.gz
Algorithm Hash digest
SHA256 1aca29735e4a49ce6c4b3af4d2fb79e3dbe03ac8410068214257bd78babad2fe
MD5 2e68f5193d141cd2cf4768a900ed26bf
BLAKE2b-256 cd5bd57e19eba985bed9950712e041034f9910a87d98f18905548214ad745ed0

See more details on using hashes here.

File details

Details for the file pytorchcocotools-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: pytorchcocotools-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 71.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for pytorchcocotools-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 646444e83f59797a96c454c7e17235d521ce7857a898f6e9c88efb3d9925ca96
MD5 2d2e0ba37d770b7fa7540343a802c835
BLAKE2b-256 b45765af831c644b290acbc6bf48ee792723eb7667fd056482cf3b88f0a2f69b

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