我正在尝试使用以下 COCO API 命令下载 COCO 数据集图像:
from pycocotools.coco import COCO
import requests
catIds = COCO.getCatIds(catNms=['person','dog', 'car'])
...但我收到以下错误消息。知道为什么会这样吗?
---------------------------------------------------------------------------
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'
以前,我使用这些说明配置了 pycocotools 。
编辑:
还有一些奇怪的错误信息。查看代码似乎没有“人”、“狗”或“汽车”这样的类别。为什么会这样?
我的代码:
a = COCO()
catIds = a.getCatIds(catNms=['person','dog', 'car'])
收到错误信息:
---------------------------------------------------------------------------
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'
