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
from pycocotools.coco import COCO | |
json_file = "/mnt/d/RarePlanes/datasets/synthetic/metadata_annotations/instances_train_aircraft.json" | |
coco=COCO(json_file) | |
# 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, select one at random | |
catIds = coco.getCatIds(catNms=['aircraft']); | |
imgIds = coco.getImgIds(catIds=catIds); | |
imgIds = coco.getImgIds(imgIds = [22]) | |
img = coco.loadImgs(imgIds[np.random.randint(0,len(imgIds))])[0] | |
print(img) | |
# load and display image | |
I = cv2.imread("/mnt/d/RarePlanes/datasets/synthetic/train/images/" + img['file_name']) | |
plt.axis('off') | |
plt.imshow(I) | |
plt.show() | |
# load and display instance annotations | |
plt.imshow(I); plt.axis('off') | |
annIds = coco.getAnnIds(imgIds=img['id'], catIds=catIds, iscrowd=None) | |
anns = coco.loadAnns(annIds) | |
coco.showAnns(anns) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment