Skip to content

Instantly share code, notes, and snippets.

@eminorhan
Last active October 8, 2021 16:34
Show Gist options
  • Save eminorhan/123e920cee96a0f384146024446a4c1f to your computer and use it in GitHub Desktop.
Save eminorhan/123e920cee96a0f384146024446a4c1f to your computer and use it in GitHub Desktop.
COCO-API cheat sheet
from pycocotools.coco import COCO
import numpy as np
dataDir = '/home/emin/coco'
dataType = 'val2017'
annFile = '{}/annotations/instances_{}.json'.format(dataDir, dataType)
coco = COCO(annFile) # build COCO object
catIds = coco.getCatIds() # category ids (80)
imgIds = coco.getImgIds() # image ids (5000 for val2017)
annIds = coco.getAnnIds() # annotation ids (36781 for val2017)
sorted_imgIds = np.sort(imgIds) # sort image ids so they match the order in binary target matrix
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment