Skip to content

Commit 5d8db61

Browse files
committed
init mtp converter 241112
1 parent 764dc0d commit 5d8db61

File tree

3 files changed

+141
-1
lines changed

3 files changed

+141
-1
lines changed

mmhuman3d/data/data_converters/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
from .mpi_inf_3dhp_hybrik import MpiInf3dhpHybrIKConverter
4545
from .mpii_neural_annot import MpiiNeuralConverter
4646
from .mscoco_neural_annot import MscocoNeuralConverter
47+
from .mtp import MtpConverter
4748
from .penn_action import PennActionConverter
4849
from .posetrack import PosetrackConverter
4950
from .pw3d import Pw3dConverter
@@ -92,5 +93,5 @@
9293
'Crowd3dConverter', 'BedlamConverter','Pw3dConverter', 'DecoConverter',
9394
'Hi4dConverter', 'Idea400Converter', 'Pw3dBedlamConverter',
9495
'RichConverter', 'SynbodyWhacConverter', 'ArcticConverter', 'SynHandConverter',
95-
'SignAvatarConverter',
96+
'SignAvatarConverter', 'MtpConverter',
9697
]

mmhuman3d/data/data_converters/mtp.py

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
import glob
2+
import json
3+
import os
4+
import pdb
5+
import random
6+
import time
7+
from typing import List
8+
9+
import cv2
10+
import numpy as np
11+
from tqdm import tqdm
12+
import torch
13+
# from scipy.spatial.distance import cdist
14+
15+
# import mmcv
16+
# from mmhuman3d.models.body_models.builder import build_body_model
17+
# from mmhuman3d.core.conventions.keypoints_mapping import smplx
18+
from mmhuman3d.core.conventions.keypoints_mapping import (
19+
convert_kps,
20+
get_keypoint_idx,
21+
get_keypoint_idxs_by_part,
22+
)
23+
from mmhuman3d.models.body_models.utils import batch_transform_to_camera_frame
24+
from mmhuman3d.models.body_models.utils import transform_to_camera_frame
25+
from mmhuman3d.data.data_structures.human_data import HumanData
26+
from .base_converter import BaseModeConverter
27+
from .builder import DATA_CONVERTERS
28+
from mmhuman3d.models.body_models.builder import build_body_model
29+
from mmhuman3d.core.cameras import build_cameras
30+
31+
@DATA_CONVERTERS.register_module()
32+
class MtpConverter(BaseModeConverter):
33+
"""Synbody dataset."""
34+
ACCEPTED_MODES = ['train', 'val']
35+
36+
def __init__(self, modes: List = []) -> None:
37+
38+
self.device = torch.device('cuda:0') if torch.cuda.is_available() else torch.device('cpu')
39+
self.misc_config = dict(
40+
bbox_body_scale=1.2,
41+
bbox_facehand_scale=1.0,
42+
bbox_source='keypoints2d_original',
43+
flat_hand_mean=True,
44+
cam_param_type='prespective',
45+
cam_param_source='original',
46+
smplx_source='original',
47+
# contact_label=['part_segmentation', 'contact_region'],
48+
# part_segmentation=['left_foot', 'right_foot'],
49+
)
50+
51+
self.smplx_shape = {
52+
'betas': (-1, 10),
53+
'transl': (-1, 3),
54+
'global_orient': (-1, 3),
55+
'body_pose': (-1, 21, 3),
56+
'left_hand_pose': (-1, 15, 3),
57+
'right_hand_pose': (-1, 15, 3),
58+
'leye_pose': (-1, 3),
59+
'reye_pose': (-1, 3),
60+
'jaw_pose': (-1, 3),
61+
'expression': (-1, 10)
62+
}
63+
64+
super(MtpConverter, self).__init__(modes)
65+
66+
67+
def _keypoints_to_scaled_bbox_fh(self,
68+
keypoints,
69+
occ=None,
70+
scale=1.0,
71+
convention='smplx'):
72+
'''Obtain scaled bbox in xyxy format given keypoints
73+
Args:
74+
keypoints (np.ndarray): Keypoints
75+
scale (float): Bounding Box scale
76+
77+
Returns:
78+
bbox_xyxy (np.ndarray): Bounding box in xyxy format
79+
'''
80+
bboxs = []
81+
for body_part in ['head', 'left_hand', 'right_hand']:
82+
kp_id = get_keypoint_idxs_by_part(body_part, convention=convention)
83+
84+
# keypoints_factory=smplx.SMPLX_KEYPOINTS)
85+
kps = keypoints[kp_id]
86+
87+
if occ == None:
88+
conf = 1
89+
else:
90+
occ_p = occ[kp_id]
91+
92+
if np.sum(occ_p) / len(kp_id) >= 0.1:
93+
conf = 0
94+
# print(f'{body_part} occluded, occlusion: {np.sum(occ_p) / len(kp_id)}, skip')
95+
else:
96+
# print(f'{body_part} good, {np.sum(self_occ_p + occ_p) / len(kp_id)}')
97+
conf = 1
98+
99+
xmin, ymin = np.amin(kps, axis=0)
100+
xmax, ymax = np.amax(kps, axis=0)
101+
102+
width = (xmax - xmin) * scale
103+
height = (ymax - ymin) * scale
104+
105+
x_center = 0.5 * (xmax + xmin)
106+
y_center = 0.5 * (ymax + ymin)
107+
xmin = x_center - 0.5 * width
108+
xmax = x_center + 0.5 * width
109+
ymin = y_center - 0.5 * height
110+
ymax = y_center + 0.5 * height
111+
112+
bbox = np.stack([xmin, ymin, xmax, ymax, conf],
113+
axis=0).astype(np.float32)
114+
115+
bboxs.append(bbox)
116+
return bboxs[0], bboxs[1], bboxs[2]
117+
118+
119+
def convert_by_mode(self, dataset_path: str, out_path: str,
120+
mode: str) -> dict:
121+
"""
122+
Args:
123+
dataset_path (str): Path to directory where raw images and
124+
annotations are stored.
125+
out_path (str): Path to directory to save preprocessed npz file
126+
mode (str): Mode in accepted modes
127+
128+
Returns:
129+
dict:
130+
A dict containing keys image_path, bbox_xywh, keypoints2d,
131+
keypoints2d_mask, keypoints3d, keypoints3d_mask, cam_param
132+
stored in HumanData() format
133+
"""
134+
135+
# get all images

tools/convert_datasets.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,10 @@
183183
type='MscocoNeuralConverter', # real, have few multihuman
184184
prefix='mscoco',
185185
modes=['train']),
186+
mtp=dict(
187+
type='MtpConverter', # real
188+
prefix='mtp',
189+
modes=['train', 'val']),
186190
renbody=dict(
187191
type='RenbodyConverter', # real
188192
prefix='renbody',

0 commit comments

Comments
 (0)