MS_COCO資料集轉協同顯著資料集方法
實驗環境:Ubuntu16,python2
說明:COCO2014版本未直接提供語義分割真值圖,COCO2017版直接提供語義分割真值圖。因此我們使用COCO2017。
第一步 下載COCO官方API 到Ubuntu桌面 解壓
得到檔案目錄/root/Desktop/cocostuffapi-master/
第二步 安裝COCO python API :
在/root/Desktop/cocostuffapi-master/PythonAPI/目錄下以次輸入:
python setup.py build_ext --inplace
python setup.py build_ext install
完成API工具安裝
第三步:檢視COCO物體類別(即協同顯著資料集組名):
from pycocotools.coco import COCO import numpy as np
annFile = '/root/Desktop/annotations/stuff_train2017.json' coco=COCO(annFile)
cats = coco.loadCats(coco.getCatIds()) nms=[cat['name'] for cat in cats] print('COCO categories: \n{}\n'.format(' '.join(nms)))
COCO categories: person bicycle car motorcycle airplane bus train truck boat traffic light fire hydrant stop sign parking meter bench bird cat dog horse sheep cow elephant bear zebra giraffe backpack umbrella handbag tie suitcase frisbee skis snowboard sports ball kite baseball bat baseball glove skateboard surfboard tennis racket bottle wine glass cup fork knife spoon bowl banana apple sandwich orange broccoli carrot hot dog pizza donut cake chair couch potted plant bed dining table toilet tv laptop mouse remote keyboard cell phone microwave oven toaster sink refrigerator book clock vase scissors teddy bear hair drier toothbrush COCO supercategories: outdoor food indoor appliance sports person animal vehicle furniture accessory electronic kitchen
第四步:獲得某一物體類別的所有圖片:
from pycocotools.coco import COCO import numpy as np
annFile = '/root/Desktop/annotations/stuff_train2017.json' coco=COCO(annFile)
catIds = coco.getCatIds(catNms=['person']) imgIds = coco.getImgIds(catIds=catIds) print(imgIds)