I want to download only person class and binary segmentation from COCO dataset. How can I do it?
use pycocotools .
from pycocotools.coco import COCO
coco = COCO('/home/office/cocoDataset/annotations/instances_train2017.json')
category_ids = coco.getCatIds(catNms=['person'])
annotations = coco.getAnnIds(imgIds=image_id, catIds=category_ids, iscrowd=False)
annotation[i]
hence merge all the annotations and save it
if annotations:
mask = coco.annToMask(annotations[0])
for i in range(len(annotations)):
mask |= coco.annToMask(annotations[i])
mask = mask * 255
im = Image.fromarray(mask)
im.save('~/mask_name.png')