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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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() |
Happy Mastering DL!!!
No comments:
Post a Comment