coco-types


Namecoco-types JSON
Version 0.0.8 PyPI version JSON
download
home_pageNone
SummaryPackage for handling COCO datasets types.
upload_time2023-04-21 11:14:25
maintainerNone
docs_urlNone
authorBagard Hoel
requires_python>=3.9
licenseMIT
keywords coco coco dataset
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # COCO 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](https://pypi.org/project/coco-types/), 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:
```python
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:
```python
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:
```python
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.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "coco-types",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": null,
    "keywords": "COCO,COCO dataset",
    "author": "Bagard Hoel",
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/f0/02/ba05e734edeb4ef2db2e86cd73e4596d6a336420dd5196d673d933458eea/coco_types-0.0.8.tar.gz",
    "platform": null,
    "description": "# COCO Types\n\nNote: This package loads the data as is and does not create dictionaries mapping ids to lists of images/annotations/categories.\n\n## Installation\n\nThe package is available on pypi [here](https://pypi.org/project/coco-types/), you can install it with:\n```\npip install coco-types\n```\n\n## Loading COCO data\n\nYou can load COCO dataset labels into Pydantic objects by using the `Dataset` and `DatasetKP` classes.\n\nFor an object detection dataset:\n```python\nimport coco_types\n\nwith open(\"path/to/json\", encoding=\"utf-8\") as data_file:\n    dataset = coco_types.Dataset.parse_raw(data_file.read())\n```\n\nFor a keypoint detection dataset:\n```python\nimport coco_types\n\nwith open(\"path/to/json\", encoding=\"utf-8\") as data_file:\n    dataset = coco_types.DatasetKP.parse_raw(data_file.read())\n```\n\n\n## Usage example:\n```python\nimport coco_types\n\nwith open(\"path/to/json\", encoding=\"utf-8\") as data_file:\n    dataset = coco_types.Dataset.parse_raw(data_file.read())\n\nimg = dataset.images[0]\nprint(f\"Image's filename {img.file_name}\")\nprint(f\"Image's id {img.id}\")\nprint(f\"Image's height {img.height}\")\nprint(f\"Image's width {img.width}\")\n\nimg_annotations = [annotation for annotation in dataset.annotations\n                   if annotation.image_id == img.id]\nann = img_annotations[0]\nprint(f\"Annotation's id: {ann.id}\")\nprint(f\"Annotation's image id: {ann.image_id}\")\nprint(f\"Annotation's category id: {ann.category_id}\")\nprint(f\"Annotation's iscrowd: {ann.iscrowd}\")\nprint(f\"Annotation's bbox: {ann.bbox}\")\nprint(f\"Annotation's area {ann.area}\")\n\nfor cat in dataset.categories:\n    if cat.id == ann.category_id:\n        break\n\nprint(f\"Category's name {cat.name}\")\nprint(f\"Category's supercategory {cat.supercategory}\")\n```\n\n### Keypoints\nIf using a dataset with keypoints (`coco_types.DatasetKP`), then annotations will have two additional attributes: `keypoints` and `num_keypoints`.\\\nIn the same way, categories will have  two additional attributes: `keypoints` and `skeleton`.\n\n\n## TypedDict versions\nA `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.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Package for handling COCO datasets types.",
    "version": "0.0.8",
    "split_keywords": [
        "coco",
        "coco dataset"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "cd7c8b7bc6b5da5a1fe289ec43693992e97fd11cefc5a8d406544a092530ca70",
                "md5": "394f5864697c95517238c2dc8d64cae0",
                "sha256": "37432f1a7e3f1e97dbbbb065eef7aecddcb3c0098f4ecea391ca8cabfe3e50cd"
            },
            "downloads": -1,
            "filename": "coco_types-0.0.8-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "394f5864697c95517238c2dc8d64cae0",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 6588,
            "upload_time": "2023-04-21T11:14:23",
            "upload_time_iso_8601": "2023-04-21T11:14:23.381995Z",
            "url": "https://files.pythonhosted.org/packages/cd/7c/8b7bc6b5da5a1fe289ec43693992e97fd11cefc5a8d406544a092530ca70/coco_types-0.0.8-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "f002ba05e734edeb4ef2db2e86cd73e4596d6a336420dd5196d673d933458eea",
                "md5": "391873c4c2411a52f15138539389d5f0",
                "sha256": "745ff1a63416dbdd5d351ee0c64f81a266d429264566566590cba442b364aa97"
            },
            "downloads": -1,
            "filename": "coco_types-0.0.8.tar.gz",
            "has_sig": false,
            "md5_digest": "391873c4c2411a52f15138539389d5f0",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 7279,
            "upload_time": "2023-04-21T11:14:25",
            "upload_time_iso_8601": "2023-04-21T11:14:25.307693Z",
            "url": "https://files.pythonhosted.org/packages/f0/02/ba05e734edeb4ef2db2e86cd73e4596d6a336420dd5196d673d933458eea/coco_types-0.0.8.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-04-21 11:14:25",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "lcname": "coco-types"
}
        
Elapsed time: 0.06176s