SimpleHumanPose代码及原理分析(一)-- coco keypoints数据集

SimpleHumanPose代码及原理分析(一)-- coco keypoints数据集

最近,在研究SimpleHumanPose,感觉学到了不少新的知识,所以记录一下。
先简单地说下SimpleHumanPose,这个网络是解决关键点keypoints的,算法效果很好。

一. coco keypoints数据集框架介绍

coco数据集下载地址
在这里插入图片描述
这是我下载的内容,其中左边是图片下载地址,右边是标签下载地址。
在这里插入图片描述
第一个annotations文件夹里面全部都是标签:
在这里插入图片描述
其中红色框就是关键点检测所对应的coco标签,一个是训练集的还有一个就是验证集上的。(这里注意下,coco数据集的图片是固定不变的,换句话说就是不管你是要用coco数据集完成什么任务:分类、分割、关键点检测,训练验证的图片都是一样的,只不过唯一不一样的地方就是annotations里面json文件的格式不一样而已。)

二. coco keypoints数据集结构

在这里插入图片描述
上图就是我截取的部分coco keypoints数据集的person_keypoints_train2017.json
其中,“info”、“licenses”、"categories"基本上来说没有价值利用,重要的就是==“images"和"annotations”==这两项。
“images”:他本身是一个列表,每张图片所包含的所有信息都是在一个字典里面,所有图片字典就构建了这个列表。
{“license”: 4,
“file_name”: “000000397133.jpg”,
“coco_url”: “http://images.cocodataset.org/val2017/000000397133.jpg”,
“height”: 427,
“width”: 640,
“date_captured”: “2013-11-14 17:02:52”,
“flickr_url”: “http://farm7.staticflickr.com/6116/6255196340_da26cf2c9e_z.jpg”,
“id”: 397133}
annotations:他本身也是一个列表,其中,每张图片的标注信息就是一个字典,所有标签字典就构成了列表。
{“segmentation”:[[0.43,299.58,2.25,299.58,9.05,287.78,32.66,299.13,39.01,296.4,48.09,290.96,43.55,286.87,62.16,291.86,61.25,286.87,37.65,279.15,18.13,272.8,0,262.81]],
“num_keypoints”: 1,
“area”: 1037.7819,
“iscrowd”: 0,
“keypoints”: [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,9,277,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], #标注的关键点,每三个为一组(x,y,v),x和y表示坐标,最后v表示的是:定义为 v=0:未标记(在这种情况下 x=y=0),v=1:标记但不可见,v=2:标记并且可见。这里只有一个点被标记,所以v=2.
“image_id”: 397133, #与images中"id"保持一致
“bbox”: [0,262.81,62.16,36.77],
“category_id”: 1,
“id”: 1218137}

三、coco数据集处理及coco api

在python处理中,我们可以使用coco api进行数据处理:

from pycocotools.coco import COCO
def load_train_data(self, score=False):
        coco = COCO(self.train_annot_path)
        train_data = []
        for aid in coco.anns.keys(): #annotations/id,这里不是image_id
            ann = coco.anns[aid] #获取annotations中每一个字典(即每张图片的标签信息)
            imgname = 'train2017/' + coco.imgs[ann['image_id']]['file_name']
            joints = ann['keypoints']
 
            if (ann['image_id'] not in coco.imgs) or ann['iscrowd'] or (np.sum(joints[2::3]) == 0) or (ann['num_keypoints'] == 0):
                continue
           
            # sanitize bboxes
            x, y, w, h = ann['bbox']
            img = coco.loadImgs(ann['image_id'])[0]
            width, height = img['width'], img['height']
            x1 = np.max((0, x))
            y1 = np.max((0, y))
            x2 = np.min((width - 1, x1 + np.max((0, w - 1))))
            y2 = np.min((height - 1, y1 + np.max((0, h - 1))))
            if ann['area'] > 0 and x2 >= x1 and y2 >= y1:
                bbox = [x1, y1, x2-x1, y2-y1]
            else:
                continue
            
            if score:
                data = dict(image_id = ann['image_id'], imgpath = imgname, bbox=bbox, joints=joints, score=1)
            else:
                data = dict(image_id = ann['image_id'], imgpath = imgname, bbox=bbox, joints=joints)

            train_data.append(data)

        return train_data
    

在这里插入图片描述
上图就是经过处理后将每张图片的基本信息提取出所得到的train_data列表,每张图片所对应的就是一个字典。

四、制作自己的coco keypoints数据集

有空再贴代码吧~~

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

进我的收藏吃灰吧~~

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值