相关文章推荐
任性的山羊  ·  JavaScript ...·  3 月前    · 
粗眉毛的镜子  ·  Qt QTextEdit ...·  5 月前    · 
温暖的硬盘  ·  「Python」 ...·  1 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I have tried to clone coco API to download a specific class from coco dataset, but when I run codes in Google Colaboratory, it gives me this error: 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);

I think this is from the example in https://github.com/philferriere/cocoapi/blob/master/PythonAPI/demos/pycocoDemo.ipynb

And you need to copy some more lines:

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);
        

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.