Name | coco_types JSON |
Version |
0.0.5
JSON |
| download |
home_page | None |
Summary | Package for handling COCO datasets types. |
upload_time | 2023-04-17 18:21:19 |
maintainer | None |
docs_url | None |
author | Bagard Hoel |
requires_python | >=3.9 |
license | MIT |
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
`TypedDict` version of the objects 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.
## TODOs:
- Rename EncodedRLE to COCO_RLE ?
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/56/23/ed3c17f9a9df3fd8f634d785c76789dbb6fbfd20c020a8f9fd5e3600c480/coco_types-0.0.5.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\n`TypedDict` version of the objects 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\n\n## TODOs:\n- Rename EncodedRLE to COCO_RLE ?\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Package for handling COCO datasets types.",
"version": "0.0.5",
"split_keywords": [
"coco",
"coco dataset"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "8932cc9c20f824df0cca29baae7d15ce075a2ee080c73e3defd188cb5c8cbe69",
"md5": "aba52cfc177b9672e5b1d441d2239ba5",
"sha256": "fb1ec8cf6370bbbebec10a636070111ff617b09d1580970eb8a2f173328f9bdd"
},
"downloads": -1,
"filename": "coco_types-0.0.5-py3-none-any.whl",
"has_sig": false,
"md5_digest": "aba52cfc177b9672e5b1d441d2239ba5",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9",
"size": 6560,
"upload_time": "2023-04-17T18:21:20",
"upload_time_iso_8601": "2023-04-17T18:21:20.855214Z",
"url": "https://files.pythonhosted.org/packages/89/32/cc9c20f824df0cca29baae7d15ce075a2ee080c73e3defd188cb5c8cbe69/coco_types-0.0.5-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "5623ed3c17f9a9df3fd8f634d785c76789dbb6fbfd20c020a8f9fd5e3600c480",
"md5": "998205622ac681f9df79205707f8a28e",
"sha256": "652d0a33b969dd5702ec0371080a810b7f69399f9c129eac8ed6a39c9d838e71"
},
"downloads": -1,
"filename": "coco_types-0.0.5.tar.gz",
"has_sig": false,
"md5_digest": "998205622ac681f9df79205707f8a28e",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9",
"size": 7236,
"upload_time": "2023-04-17T18:21:19",
"upload_time_iso_8601": "2023-04-17T18:21:19.782912Z",
"url": "https://files.pythonhosted.org/packages/56/23/ed3c17f9a9df3fd8f634d785c76789dbb6fbfd20c020a8f9fd5e3600c480/coco_types-0.0.5.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-04-17 18:21:19",
"github": false,
"gitlab": false,
"bitbucket": false,
"lcname": "coco_types"
}