"No one is harder on a talented person than the person themselves" - Linda Wilkinson ; "Trust your guts and don't follow the herd" ; "Validate direction not destination" ;

April 12, 2019

Day #238 - Working with coco dataset

coco - common objects in context

Installation Steps https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/installation.md

Packages
pip install Cython
pip install contextlib2
pip install matplotlib
pip install pycocotools
pip install scikit-image
pip install --upgrade scikit-image

Demo Code (Minor Changes)
#https://github.com/cocodataset/cocoapi/blob/master/PythonAPI/pycocoDemo.ipynb
#Windows
#Python 3+ Environment
import matplotlib.pyplot as plt
from pycocotools.coco import COCO
from pycocotools.cocoeval import COCOeval
import numpy as np
from skimage import io
anntype = ['segm','bbox','keypoints']
anntype = anntype[1]
prefix = 'person_keypoints' if anntype =='keypoints' else 'instances'
print('Demo for %s'%anntype)
#Download Annotations from http://images.cocodataset.org/annotations/annotations_trainval2014.zip
#Download to location C:\datadir
#Initialize coco ground truth API
datadir = r'C:\datadir\annotations_trainval2014'
datatype = 'val2014'
annfile = '%s/annotations/%s_%s.json'%(datadir,prefix,datatype)
coco = COCO(annfile)
#display categories
cats = coco.loadCats(coco.getCatIds())
nms = [cat['name'] for cat in cats]
print('COCO categories: \n{}\n'.format(' '.join(nms)))
nms = [cat['supercategory'] for cat in cats]
print('COCO super categories: \n{}\n'.format(' '.join(nms)))
catids = coco.getCatIds(catNms=['person','dog','skateboard'])
imgids = coco.getImgIds(catIds=catids)
imgids = coco.getImgIds(imgIds=[324158])
img = coco.loadImgs(imgids[np.random.randint(0,len(imgids))])[0]
I = io.imread(img['coco_url'])
plt.axis('off')
plt.imshow(I)
plt.show()
plt.imshow(I)
plt.axis('off')
annids = coco.getAnnIds(imgIds=img['id'],catIds=catids,iscrowd=None)
anns = coco.loadAnns(annids)
coco.showAnns(anns)
plt.show()
view raw cocodataset.py hosted with ❤ by GitHub



Happy Mastering DL!!!

No comments: