首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何下载COCO数据集图像?

如何下载COCO数据集图像?
EN

Data Science用户
提问于 2019-11-23 12:39:49
回答 2查看 7.1K关注 0票数 2

我正在尝试使用以下COCO命令下载COCO映像:

代码语言:javascript
复制
from pycocotools.coco import COCO
import requests
catIds = COCO.getCatIds(catNms=['person','dog', 'car'])

...but正在收到以下错误消息。知道为什么会这样吗?

代码语言:javascript
复制
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-42-9cc4e2f62a0e> in <module>
----> 1 catIds = COCO.getCatIds(catNms=['person','dog', 'car'])

TypeError: getCatIds() missing 1 required positional argument: 'self'

以前,我使用这些指示配置了化茧工具。

编辑:

仍然有一些奇怪的错误信息。查看代码,似乎没有“人”、“狗”或“车”这样的类别。为什么会这样呢?

我的代码:

代码语言:javascript
复制
a = COCO()  
catIds = a.getCatIds(catNms=['person','dog', 'car'])

收到错误消息:

代码语言:javascript
复制
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-12-57400207fde1> in <module>
      1 a = COCO() # calling init
----> 2 catIds = a.getCatIds(catNms=['person','dog', 'car'])

~\Anaconda3\lib\site-packages\pycocotools\coco.py in getCatIds(self, catNms, supNms, catIds)
    171             cats = self.dataset['categories']
    172         else:
--> 173             cats = self.dataset['categories']
    174             cats = cats if len(catNms) == 0 else [cat for cat in cats if cat['name']          in catNms]
    175             cats = cats if len(supNms) == 0 else [cat for cat in cats if cat['supercategory'] in supNms]

KeyError: 'categories'

从文件“cocoapi/PythonAPI/pycocotools/coco.py”中提取:

EN

回答 2

Data Science用户

发布于 2019-11-24 02:40:29

COCO是一个python类,getCatIds不是一个静态方法,只能由类COCO的实例/对象调用,而不能从类本身调用。

您可能可以通过这样做来解决这个问题:

代码语言:javascript
复制
a = COCO() # calling init
catIds = a.getCatIds(catNms=['person','dog', 'car']) # calling the method from the class

(答案基于从https://github.com/cocodataset/cocoapi/blob/master/PythonAPI/pycocotools/coco.py读取代码)

票数 0
EN

Data Science用户

发布于 2019-12-25 19:16:14

根据演示代码这里,您必须分别下载数据,然后使用pycocotools包访问数据:

代码语言:javascript
复制
from pycocotools.coco import COCO

# After downloading images from http://cocodataset.org/#download

# Define location of annotations
dataDir = '..'
dataType = 'val2017'
annFile = f'{dataDir}/annotations/instances_{dataType}.json'

# Create instance
coco = COCO(annFile)

# Filter for specific categories 
catIds = coco.getCatIds(catNms=['person','dog', 'car'])
票数 0
EN
页面原文内容由Data Science提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://datascience.stackexchange.com/questions/63639

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档