Loading preprocessing/100.py 0 → 100644 +33 −0 Original line number Diff line number Diff line from pycocotools.coco import COCO from collections import defaultdict import numpy as np import skimage.io as io import matplotlib.pyplot as plt import pylab import pickle import shutil path = '/softpro/ss18/caption/cocoapi/100/' coco = COCO('/softpro/ss18/caption/cocoapi/annotations/train/instances_train2017.json') cats = coco.loadCats(coco.getCatIds()) nms = [cat['name'] for cat in cats] pic100 = dict() for category in nms: catIds = coco.getCatIds(catNms=[category]) imgIds = coco.getImgIds(catIds=catIds) i = 0 for pic in imgIds: if i == 100: break img = coco.loadImgs(pic)[0] file_name = img['file_name'] if file_name in pic100.keys(): continue pic100[file_name] = (category) i += 1 with open('100_pics_or_didnt_happen.pickle', 'wb') as handle: pickle.dump(pic100, handle, protocol=pickle.HIGHEST_PROTOCOL) Loading
preprocessing/100.py 0 → 100644 +33 −0 Original line number Diff line number Diff line from pycocotools.coco import COCO from collections import defaultdict import numpy as np import skimage.io as io import matplotlib.pyplot as plt import pylab import pickle import shutil path = '/softpro/ss18/caption/cocoapi/100/' coco = COCO('/softpro/ss18/caption/cocoapi/annotations/train/instances_train2017.json') cats = coco.loadCats(coco.getCatIds()) nms = [cat['name'] for cat in cats] pic100 = dict() for category in nms: catIds = coco.getCatIds(catNms=[category]) imgIds = coco.getImgIds(catIds=catIds) i = 0 for pic in imgIds: if i == 100: break img = coco.loadImgs(pic)[0] file_name = img['file_name'] if file_name in pic100.keys(): continue pic100[file_name] = (category) i += 1 with open('100_pics_or_didnt_happen.pickle', 'wb') as handle: pickle.dump(pic100, handle, protocol=pickle.HIGHEST_PROTOCOL)