7
7
from __future__ import absolute_import
8
8
from __future__ import division
9
9
from __future__ import print_function
10
-
10
+ import copy
11
+ from datadef import *
11
12
from collections import defaultdict
12
13
from collections import OrderedDict
13
14
import logging
@@ -63,7 +64,7 @@ def __init__(self, cfg, root, image_set, is_train, transform=None):
63
64
self .lpset_img_dir = "/home/wj/ai/mldata1/lspet/lspet/images"
64
65
self .penn_anno_path = "/home/wj/ai/mldata1/penn_action/Penn_Action/coco_labels"
65
66
self .penn_img_dir = "/home/wj/ai/mldata1/penn_action/Penn_Action/frames"
66
- self .crowd_pose_anno_path = '/home/wj/ai/mldata1/crowd_pose/CrowdPose/crowdpose_coco.pt' ,
67
+ self .crowd_pose_anno_path = '/home/wj/ai/mldata1/crowd_pose/CrowdPose/crowdpose_coco.pt'
67
68
self .crowd_pose_img_dir = '/home/wj/ai/mldata1/crowd_pose/images'
68
69
69
70
self .nms_thre = cfg .TEST .NMS_THRE
@@ -140,7 +141,7 @@ def _load_image_set_index(self):
140
141
def _get_db (self ):
141
142
gt_db = []
142
143
if self .is_train :
143
- ''' if self.is_train or self.use_gt_bbox:
144
+ if self .is_train or self .use_gt_bbox :
144
145
# use ground truth bbox
145
146
gt_db = self ._load_coco_keypoint_annotations ()
146
147
else :
@@ -149,8 +150,10 @@ def _get_db(self):
149
150
150
151
gt_db .extend (self ._load_mpii_keypoint_annotations ())
151
152
gt_db .extend (self ._load_lpset_keypoint_annotations ())
152
- gt_db.extend(self._load_penn_action_keypoint_annotations())'''
153
+ gt_db .extend (self ._load_penn_action_keypoint_annotations ())
153
154
gt_db .extend (self ._load_crowd_pose_keypoint_annotations ())
155
+ '''if is_debug():
156
+ gt_db.extend(self._load_penn_action_keypoint_annotations())'''
154
157
else :
155
158
if self .is_train or self .use_gt_bbox :
156
159
# use ground truth bbox
@@ -212,7 +215,7 @@ def _load_penn_action_keypoint_annotations(self):
212
215
with open (file ,"rb" ) as f :
213
216
datas = pickle .load (f )
214
217
for data in datas :
215
- tmp_db = self ._load_mpii_keypoint_annotation_kernal (data ,img_dir = self .penn_img_dir )
218
+ tmp_db = self ._load_penn_action_keypoint_annotation_kernal (data ,img_dir = self .penn_img_dir )
216
219
gt_db .extend (tmp_db )
217
220
218
221
print (f"Total load { len (gt_db )} penn action data." )
@@ -319,8 +322,11 @@ def _load_mpii_keypoint_annotation_kernal(self, data,img_dir):
319
322
joints_3d_vis = np .zeros ((self .num_joints , 3 ), dtype = np .float )
320
323
for ipt in range (self .num_joints ):
321
324
t_vis = kps [ipt ,2 ]
325
+ if t_vis < 0.99 and ipt < 5 :
326
+ t_vis = t_vis * 0.5
322
327
if t_vis > 1 :
323
328
t_vis = 1
329
+ joints_3d [ipt ,2 ] = t_vis
324
330
joints_3d_vis [ipt , 0 ] = t_vis
325
331
joints_3d_vis [ipt , 1 ] = t_vis
326
332
joints_3d_vis [ipt , 2 ] = 0
@@ -350,6 +356,70 @@ def _load_mpii_keypoint_annotation_kernal(self, data,img_dir):
350
356
351
357
return rec
352
358
359
+ def _load_penn_action_keypoint_annotation_kernal (self , data ,img_dir ):
360
+ """
361
+ coco ann: [u'segmentation', u'area', u'iscrowd', u'image_id', u'bbox', u'category_id', u'id']
362
+ iscrowd:
363
+ crowd instances are handled by marking their overlaps with all categories to -1
364
+ and later excluded in training
365
+ bbox:
366
+ [x1, y1, w, h]
367
+ :param index: coco image id
368
+ :return: db entry
369
+ """
370
+ img_name ,bboxes ,all_kps = data
371
+ if bboxes .shape [0 ]== 0 :
372
+ return []
373
+
374
+ rec = []
375
+ for bbox ,kps in zip (bboxes ,all_kps ):
376
+ # ignore objs without keypoints annotation
377
+ if np .max (kps [:,:2 ]) == 0 :
378
+ continue
379
+
380
+ joints_3d = kps
381
+ joints_3d_vis = np .zeros ((self .num_joints , 3 ), dtype = np .float )
382
+ for ipt in range (self .num_joints ):
383
+ t_vis = kps [ipt ,2 ]
384
+ if t_vis < 0.99 and ipt < 5 :
385
+ t_vis = t_vis * 0.5
386
+ if t_vis > 1 :
387
+ t_vis = 1
388
+ joints_3d [ipt ,2 ] = t_vis
389
+ joints_3d_vis [ipt , 0 ] = t_vis
390
+ joints_3d_vis [ipt , 1 ] = t_vis
391
+ joints_3d_vis [ipt , 2 ] = 0
392
+ src_idxs = list (range (5 ,17 ))
393
+ dst_idxs = [6 ,5 ,8 ,7 ,10 ,9 ,12 ,11 ,14 ,13 ,16 ,15 ]
394
+ tmp_joints_3d = copy .deepcopy (joints_3d )
395
+ tmp_joints_3d_vis = copy .deepcopy (joints_3d_vis )
396
+ joints_3d [dst_idxs ] = tmp_joints_3d [src_idxs ]
397
+ joints_3d_vis [dst_idxs ] = tmp_joints_3d_vis [src_idxs ]
398
+
399
+ clean_bbox = [bbox [0 ],bbox [1 ],bbox [2 ]- bbox [0 ],bbox [3 ]- bbox [1 ]]
400
+ if clean_bbox [2 ]< 2 or clean_bbox [3 ]< 2 :
401
+ print (f"Skip { img_dir } /{ img_name } { bbox } " )
402
+ continue
403
+ total_kps_nr = np .sum ((kps [...,2 ]> 0.1 ).astype (np .int32 ))
404
+ if total_kps_nr < 3 :
405
+ print (f"Skip { img_dir } /{ img_name } { total_kps_nr } { kps } { bbox } " )
406
+ continue
407
+ kp_bbox = odk .npget_bbox (joints_3d )
408
+ if kp_bbox is not None :
409
+ bbox = odb .bbox_of_boxes ([bbox ,kp_bbox ])
410
+ center , scale = self ._box2cs (clean_bbox )
411
+ rec .append ({
412
+ 'image' : osp .join (img_dir ,img_name ),
413
+ 'center' : center ,
414
+ 'scale' : scale ,
415
+ 'joints_3d' : joints_3d ,
416
+ 'joints_3d_vis' : joints_3d_vis ,
417
+ 'clean_bbox' :bbox ,
418
+ 'filename' : img_name ,
419
+ 'imgnum' : 0 ,
420
+ })
421
+
422
+ return rec
353
423
def _box2cs (self , box ):
354
424
x , y , w , h = box [:4 ]
355
425
return self ._xywh2cs (x , y , w , h )
0 commit comments