Loading preprocessing/categories_of_pictures.py 0 → 100644 +32 −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 json import os path = '/softpro/ss18/caption/cocoapi/images_txt/' coco = COCO('/softpro/ss18/caption/cocoapi/annotations/train/instances_train2017.json') cats = coco.loadCats(coco.getCatIds()) nms = [cat['name'] for cat in cats] pics = defaultdict(list) for category in nms: print(category) catIds = coco.getCatIds(catNms=[category]) imgIds = coco.getImgIds(catIds=catIds) for pic in imgIds: img = coco.loadImgs(pic)[0] file_name = img['file_name'] pics[file_name].append(category) for k, v in pics.items(): with open(path + k + '.txt', 'w') as handle: for category_name in v: out = category_name + '\n' handle.write(out) Loading
preprocessing/categories_of_pictures.py 0 → 100644 +32 −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 json import os path = '/softpro/ss18/caption/cocoapi/images_txt/' coco = COCO('/softpro/ss18/caption/cocoapi/annotations/train/instances_train2017.json') cats = coco.loadCats(coco.getCatIds()) nms = [cat['name'] for cat in cats] pics = defaultdict(list) for category in nms: print(category) catIds = coco.getCatIds(catNms=[category]) imgIds = coco.getImgIds(catIds=catIds) for pic in imgIds: img = coco.loadImgs(pic)[0] file_name = img['file_name'] pics[file_name].append(category) for k, v in pics.items(): with open(path + k + '.txt', 'w') as handle: for category_name in v: out = category_name + '\n' handle.write(out)