将COCO测试结果保存为HiEve格式

背景:

最近刚刚在HiEve数据集上做了实验,主要针对多人的姿态估计。因为dataloader一套主要参考COCO去做的,所以记录一下对测试结果格式的保存。将coco的测试结果转换为HiEve的格式,并保存成json。


修改方式

COCO结果保存的代码位于${project_root_dir}/lib/dataset/coco.py,主要代码是_coco_keypoint_results_one_category_kernel(self, data_pack)函数(大概位于359行左右)。将该函数进行了重写,如下所示:

def _coco_keypoint_results_one_category_kernel(self, data_pack):
        annolist = []

        keypoints = data_pack['keypoints']

        for img_kpts in keypoints:             
            frame_instance = {}
            frame_instance['ignore_regions'] = []

            annorect = []
            image = '%06d.jpg'%img_kpts[0]['image']
            frame_instance['image'] = [{'name': image}]
            for person in img_kpts:
                bbox_score = person['score']
                x1, y1, x2, y2 = person['bbox'][0], person['bbox'][1], person['bbox'][2], person['bbox'][3]
                annopoints = []
                point = []
                
                for i in range(person['keypoints'].shape[0]):
                    joint = {
                        'y': [person['keypoints'][i, 1]],
                        'score': [1],
                        'id': [i],
                        'x': [person['keypoints'][i, 0]]
                    }
                    point.append(joint)
                pose = {'point': point}
                annopoints.append(pose)

                instance = {
                    'score': [bbox_score],
                    'y1': [y1],
                    'y2': [y2],
                    'x2': [x2],
                    'x1': [x1],
                    'annopoints': annopoints,
                }
                annorect.append(instance)
            frame_instance['annorect'] = annorect
            annolist.append(frame_instance)
        hieve_res = {'annolist': annolist}      
        return hieve_res

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值