【小卒数据处理】COCO数据集格式,与筛选,分割处理【Python处理之二】

数据集下载好了之后我们想进行处理这里我们有俩个方式:

1.使用cocoAPI,进行处理

2.自己读取进行处理

不管是第一种方法还是第二种方法都是可以的,我们这里比较推荐的是第二种方法,因为比较方便,自己想读取什么数据都是可以的,既然决定了读取数据,让我们来看看数据的具体是什么样子的吧.。(你也可以使用COCOAPI的实例程序运行

或者使用如下程序,记得把路径改一下再运行:

#这里仅做展示代码作用
from pycocotools.coco import COCO
import numpy as np
import skimage.io as io
import matplotlib.pyplot as plt
import pylab
from collections import defaultdict
import json


#signal person photo in MSCOCO
def load_data( annFile):
    coco = COCO(annFile)
    catID = coco.getCatIds(catNms=['person'])
    imgID = coco.getImgIds(catIds=catID)


    dict=json.load(open(annFile, 'r'))
    dictnew = defaultdict(str)
    for img in dict['images']:
        fileid=img['file_name']


        dictnew[fileid]=img['id']
    strimg='000000119445.jpg'
    imgid=dictnew[strimg]
    annID = coco.getAnnIds(imgIds=imgid)
    personNumber = len(annID)
    anns = coco.loadAnns(annID)


    for j in range(personNumber):
        bndbox = anns[j]['bbox']
        keyPoints = anns[j]['keypoints']
        keypointsRow = [str(personNumber),
                        str(bndbox[0]) + '_' + str(bndbox[1]) + '_' + str(bndbox[2]) + '_' + str(bndbox[3]),
                        str(keyPoints[0]) + '_' + str(keyPoints[1]) + '_' + str(keyPoints[2]),
                        str(keyPoints[3]) + '_' + str(keyPoints[4]) + '_' + str(keyPoints[5]),
                        str(keyPoints[6]) + '_' + str(keyPoints[7]) + '_' + str(keyPoints[8]),
                        str(keyPoints[9]) + '_' + str(keyPoints[10]) + '_' + str(keyPoints[11]),
                        str(keyPoints[12]) + '_' + str(keyPoints[13]) + '_' + str(keyPoints[14]),
                        str(keyPoints[15]) + '_' + str(keyPoints[16]) + '_' + str(keyPoints[17]),
                        str(keyPoints[18]) + '_' + str(keyPoints[19]) + '_' + str(keyPoints[20]),
                        str(keyPoints[21]) + '_' + str(keyPoints[22]) + '_' + str(keyPoints[23]),
                        str(keyPoints[24]) + '_' + str(keyPoints[25]) + '_' + str(keyPoints[26]),
                        str(keyPoints[27]) + '_' + str(keyPoints[28]) + '_' + str(keyPoints[29]),
                        str(keyPoints[30]) + '_' + str(keyPoints[31]) + '_' + str(keyPoints[32]),
                        str(keyPoints[33]) + '_' + str(keyPoints[34]) + '_' + str(keyPoints[35]),
                        str(keyPoints[36]) + '_' + str(keyPoints[37]) + '_' + str(keyPoints[38]),
                        str(keyPoints[39]) + '_' + str(keyPoints[40]) + '_' + str(keyPoints[41]),
                        str(keyPoints[42]) + '_' + str(keyPoints[43]) + '_' + str(keyPoints[44]),
                        str(keyPoints[45]) + '_' + str(keyPoints[46]) + '_' + str(keyPoints[47]),
                        str(keyPoints[48]) + '_' + str(keyPoints[49]) + '_' + str(keyPoints[50]), ]
        print(keypointsRow)


if __name__ == '__main__':
    dataDir = '/media/blacktea/DATA/MScoco/'
    dataType = 'val2017'
    annFile = '{}/annotations/person_keypoints_{}.json'.format(dataDir, dataType)
    sel=COCO()
    load_data(annFile=annFile)

然后,进一步我们一起来看一下如何提取自己需要的数据吧~

 

下一节:https://blog.csdn.net/weixin_41994751

 

 

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值