我曾尝试克隆coco API以从coco数据集中下载特定的类,但当我在Google Colaboratory中运行代码时,它给出了这个错误:name 'coco' is not defined。
!git clone https://github.com/philferriere/cocoapi
#display COCO categories
cats = coco.loadCats(coco.getCatIds())
nms=[cat['name'] for cat in cats]
print('COCO categories: \n{}\n'.format(' '.join(nms)))
# get all images containing given categories (I'm selecting the "bird")
catIds = coco.getCatIds(catNms=['bird']);
imgIds = coco.getImgIds(catIds=catIds);发布于 2019-08-27 05:26:40
我认为这来自于https://github.com/philferriere/cocoapi/blob/master/PythonAPI/demos/pycocoDemo.ipynb中的示例
并且您需要复制更多的行:
from pycocotools.coco import COCO
# ... skipped some lines here
# initialize COCO api for instance annotations
coco=COCO(annFile)
cats = coco.loadCats(coco.getCatIds())
nms=[cat['name'] for cat in cats]
print('COCO categories: \n{}\n'.format(' '.join(nms)))
# get all images containing given categories (I'm selecting the "bird")
catIds = coco.getCatIds(catNms=['bird']);
imgIds = coco.getImgIds(catIds=catIds);https://stackoverflow.com/questions/57663824
复制相似问题