目錄
1.COCO數(shù)據(jù)集簡介
2.COCO數(shù)據(jù)集的優(yōu)缺點(簡述)
3.COCO數(shù)據(jù)集信息統(tǒng)計
4.下次將推出VOC轉(zhuǎn)COCO的腳本,期待關(guān)注。
1.COCO數(shù)據(jù)集簡介
微軟發(fā)布的 COCO 數(shù)據(jù)庫是一個大型圖像數(shù)據(jù)集, 專為對象檢測、分割、人體關(guān)鍵點檢測、語義分割和字幕生成而設(shè)計。
COCO 數(shù)據(jù)庫的網(wǎng)址是:
- MS COCO 數(shù)據(jù)集主頁:http://mscoco.org/
- Github 網(wǎng)址:https://github.com/Xinering/cocoapi
- 關(guān)于 API 更多的細(xì)節(jié)在網(wǎng)站:?http://mscoco.org/dataset/#download
- 推薦參考文章:https://zhuanlan.zhihu.com/p/29393415
COCO API?提供了 Matlab, Python 和 Lua 的 API 接口. 該 API 接口可以提供完整的圖像標(biāo)簽數(shù)據(jù)的加載, parsing 和可視化。此外,網(wǎng)站還提供了數(shù)據(jù)相關(guān)的文章, 教程等。
2.COCO數(shù)據(jù)集的優(yōu)缺點(簡述)
優(yōu)點:數(shù)據(jù)集量大,作為官方數(shù)據(jù)集廣泛用于深度學(xué)習(xí)--目標(biāo)檢測,是一個極富挑戰(zhàn)性的數(shù)據(jù)集。
? ? ? ? ? ?采用json標(biāo)注格式(VOC采用的是xml格式),具有良好的自我描述性,便于閱讀。
缺點:由于數(shù)據(jù)集量很大,json文件一般也很大,當(dāng)我們需要打開json文件時,導(dǎo)致文本編輯器卡死
3.COCO數(shù)據(jù)集信息統(tǒng)計
比如說我們想要知道由于訓(xùn)練的數(shù)據(jù)的具體信息或測試數(shù)據(jù)的具體信息,要通過json統(tǒng)計,針對COCO數(shù)據(jù)集的缺點,寫者編寫了一個Python腳本統(tǒng)計json文件中的數(shù)據(jù)信息。
具體代碼如下:
from pycocotools.coco import COCO
#文件路徑
dataDir='D:/Users/Desktop/'
dataType='trainval2014'
annFile='{}/instances_{}.json'.format(dataDir,dataType)
# initialize COCO api for instance annotations
coco_train=COCO(annFile)
# display COCO categories and supercategories
#顯示所有類別
cats = coco_train.loadCats(coco_train.getCatIds())
cat_nms=[cat['name'] for cat in cats]
print('COCO categories:\n{}'.format('\n'.join(cat_nms))+'\n')
#統(tǒng)計單個類別的圖片數(shù)量與標(biāo)注數(shù)量
for cat_name in cat_nms:
catId = coco_train.getCatIds(catNms=cat_name)
if cat_name == "person":
print(catId)
imgId = coco_train.getImgIds(catIds=catId)
annId = coco_train.getAnnIds(imgIds=imgId, catIds=catId, iscrowd=False)
print("{:<15} {:<6d} {:<10d}\n".format(cat_name, len(imgId), len(annId)))
#統(tǒng)計全部的類別及全部的圖片數(shù)量和標(biāo)注數(shù)量
print("NUM_categories: "+str(len(coco_train.dataset['categories'])))
print("NUM_images: "+str(len(coco_train.dataset['images'])))
print("NUM_annotations: "+str(len(coco_train.dataset['annotations'])))
運行結(jié)果展示
運行代碼可能出現(xiàn)的bug:
問題:提示pycocotools.coco module缺少
解決辦法:python執(zhí)行pip install?pycocotools,成功安裝即可
如果有遇到其他問題,請評論區(qū)留言,與寫者一起交流
4.下次將推出VOC轉(zhuǎn)COCO的腳本,期待關(guān)注。
更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主
微信掃碼或搜索:z360901061
微信掃一掃加我為好友
QQ號聯(lián)系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元

