Hey,上周用CrowdPose数据集做了一个实验,实验结果还不错,正好想把实验用数据集转成CrowdPose数据集的格式,所以学习了CrowdPose数据集的论文:CrowdPose: Efficient Crowded Scenes Pose Estimation and A New Benchmark
首先文章提出了一个’crowd index’用来表示图片’crowd’的程度,计算方式如下:n表示图片上总共有多少个人,分母表示第i个人总共标注了多少个关键点分子表示在这个人的bbox里面,有多少个关键点不属于这个人但却出现在这个人的bbox内(所以才叫’crowd’)。显而易见,这个值越大,说明人’crowd’的程度越严重。
文章提出自己的方法,包含两个关键点:
1、joint-candidate single person pose estimation (SPPE)
2、global maximum joints association
这些关键点有AlphaPose论文介绍的很详细了,加之,我近期的重点在于处理数据集的标注文件,因此我重点说一下CrowdPose数据集的可视化:
直接放代码:
import cv2
import matplotlib.pyplot as plt
import json
json_data = open('/Users/sqx/Downloads/json/crowdpose_val.json', 'r')
json_data = json.load(json_data)
print(json_data.keys())
# dict_keys(['images', 'annotations', 'categories'])
images_list = json_data['images']
annotations_list = json_data['annotations']
categories_list = json_data['categories']
print('images lenth:', len(images_list))
print('annotations lenth:', len(annotations_list))
print('categories lenth:', len(categories_list))
# images lenth: 2000
# annotations lenth: 8527
# categories lenth: 1
print('categories:', categories_list)
# categories: [{'supercategory': 'person', 'id': 1, 'name': 'person', 'keypoints': ####['left_shoulder', 'right_shoulder', 'left_elbow', 'right_elbow', 'left_wrist', #'right_wrist', 'left_hip', 'right_hip', 'left_knee', 'right_knee', 'left_ankle', #'right_ankle', 'head', 'neck'], 'skeleton': [[16, 14], [14, 12], [17, 15], [15, 13], [12, #13], [6, 12], [7, 13], [6, 7], [6, 8], [7, 9], [8, 10], [9, 11]]}]
print(images_list[0].keys())
print(annotations_list[0].keys())
# dict_keys(['file_name', 'id', 'height', 'width', 'crowdIndex'])
# dict_keys(['num_keypoints', 'iscrowd', 'keypoints', 'image_id', 'bbox', 'category_id', 'id'])
vis_id = 109132
def find_filename(img_id, meta):
for block in meta:
# print(block)
if block['id'] == img_id:
return block['file_name'], block['crowdIndex']
continue
return None, None
def get_annokpts(img_id, meta):
kpts = []
bboxes = []
for block in meta:
if block['image_id'] == img_id:
kpts.append(block['keypoints'])
bboxes.append(block['bbox'])
continue
return kpts, bboxes
def vis_box(img, bboxes):
for box in bboxes:
x0, y0, x1, y1 = box
img = cv2.rectangle(img, (x0, y0), (x1, y1), color=[0, 255, 0], thickness=2, lineType=cv2.LINE_AA) # 12
return img
def vis_keypoints(img, kpts, crowdIndex):
links = [[0, 2], [1, 3], [2, 4], [3, 5], [6, 8], [8, 10], [7, 9], [9, 11], [12, 13], [0, 13], [1, 13], [6, 13],
[7, 13]]
for kpt in kpts:
x_ = kpt[0::3]
y_ = kpt[1::3]
v_ = kpt[2::3]
for order1, order2 in links:
if v_[order1] > 0 and v_[order2] > 0:
img = cv2.line(img, (x_[order1], y_[order1]), (x_[order2], y_[order2]), color=[100, 255, 255],
thickness=2, lineType=cv2.LINE_AA)
for x, y, v in zip(x_, y_, v_):
if int(v) > 0:
img = cv2.circle(
img, (int(x), int(y)),
radius=3, color=[255, 0, 255], thickness=-1, lineType=cv2.LINE_AA)
font = cv2.FONT_HERSHEY_SIMPLEX
img = cv2.putText(img, 'crowdIndex: ' + str(crowdIndex), (0, 50), font, 1.2, (0, 0, 0), 2)
return img
file_name, crowdIndex = find_filename(vis_id, images_list)
kpts, bboxes = get_annokpts(vis_id, annotations_list)
img = cv2.imread('/Users/sqx/Downloads/images/' + file_name)
plt.figure(figsize=(12,10))
plt.imshow(cv2.cvtColor(img, cv2.COLOR_BGR2RGB))
plt.show()
img = vis_box(img,bboxes)
plt.figure(figsize=(12,10))
plt.imshow(cv2.cvtColor(img, cv2.COLOR_BGR2RGB))
plt.show()
img=vis_keypoints(img,kpts,crowdIndex)
plt.figure(figsize=(12,10))
plt.imshow(cv2.cvtColor(img, cv2.COLOR_BGR2RGB))
plt.show()
运行结果:
以上,大家可以直接修改第5行:json_data和第87行img的路径就可以得到运行结果了,大家可以通过这个代码去了解CrowdPose数据集的格式。
最近我们租了台带GPU的远程服务器,不管是跑实验还是运行python脚本,都很快,它们的环境都是配置好的,解决了我们配置实验环境的麻烦。有需要的朋友可以通过以下方式了解:智星云官网: http://www.ai-galaxy.cn/,淘宝店:https://shop36573300.taobao.com/公众号: 智星AI,
最后给大家推荐一首小提琴曲“Csárdás”《查尔达斯》是意大利作曲家蒙蒂根据舞曲改编创作的一首小提琴曲。很经典的一首,出现在很多电影的配乐里。祝大家天天都有好心情,PEACE
参考资料:
https://github.com/MVIG-SJTU/AlphaPose/blob/pytorch/doc/CrowdPose.md
https://arxiv.org/pdf/1812.00324.pdf
https://blog.csdn.net/github_36923418/article/details/88219960
https://blog.csdn.net/github_36923418/article/details/88540865
http://www.ai-galaxy.cn/
https://shop36573300.taobao.com/
公众号: 智星AI