Skip to main content

COCO 数据集库。

项目描述

可可库

COCO 数据集库。为多种 COCO 数据集格式提供可序列化的原生 Python 绑定。

支持的绑定及其对应的模块:

  • 物体检测:objectdetection
  • 关键点检测:keypointdetection
  • 全景分割:panopticsegmentation
  • 图片说明:imagecaptioning

安装

coco-lib在 PyPI 上可用:

pip install coco-lib

用法

创建数据集(对象检测)

>>> from coco_lib.common import Info, Image, License
>>> from coco_lib.objectdetection import ObjectDetectionAnnotation, \
...                                      ObjectDetectionCategory, \
...                                      ObjectDetectionDataset
>>> from datetime import datetime
>>> info = Info(  # Describe the dataset
...    year=datetime.now().year, 
...    version='1.0', 
...    description='This is a test dataset', 
...    contributor='Test', 
...    url='https://test', 
...    date_created=datetime.now()
... )
>>> mit_license = License(  # Set the license
...     id=0, 
...     name='MIT', 
...     url='https://opensource.org/licenses/MIT'
... )
>>> images = [  # Describe the images
...     Image(
...         id=0, 
...         width=640, height=480, 
...         file_name='test.jpg', 
...         license=mit_license.id,
...         flickr_url='',
...         coco_url='',
...         date_captured=datetime.now()
...     ),
...     ...
... ]
>>> categories = [  # Describe the categories
...     ObjectDetectionCategory(
...         id=0,
...         name='pedestrian',
...         supercategory=''
...     ),
...     ...
... ]
>>> annotations = [  # Describe the annotations
...     ObjectDetectionAnnotation(
...         id=0,
...         image_id=0,
...         category_id=0,
...         segmentation=[],
...         area=800.0,
...         bbox=[300.0, 100.0, 20.0, 40.0],
...         is_crowd=0
...     ),
...     ...
... ]
>>> dataset = ObjectDetectionDataset(  # Create the dataset
...     info=info,
...     images=images,
...     licenses=[mit_license],
...     categories=categories,
...     annotations=annotations
... )
>>> dataset.save('test_dataset.json', indent=2)  # Save the dataset

加载数据集

>>> from coco_lib.objectdetection import ObjectDetectionDataset
>>> dataset = ObjectDetectionDataset.load('test_dataset.json')  # Load the dataset

项目详情


下载文件

下载适用于您平台的文件。如果您不确定要选择哪个,请了解有关安装包的更多信息。

源分布

coco-lib-0.1.3.tar.gz (4.2 kB 查看哈希)

已上传 source

内置分布

coco_lib-0.1.3-py3-none-any.whl (5.4 kB 查看哈希)

已上传 py3