我试图克隆coco API,以便从coco数据集中下载特定类,但是在google colaboratory中运行代码时,会出现错误,就像未定义名称'coco'一样
!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);
答案 0 :(得分:0)
我认为这是来自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);