MCPcopy Create free account
hub / github.com/MotrixLab/ADHMR / normalize_pose_cuda

Function normalize_pose_cuda

ADHMR/lib/utils/pose_utils.py:23–74  ·  view source on GitHub ↗
(pose, mean_and_std=None,res_w_h=None, which='zero_center',scale = None)

Source from the content-addressed store, hash-verified

21 return joints
22
23def normalize_pose_cuda(pose, mean_and_std=None,res_w_h=None, which='zero_center',scale = None):
24 batch_size = pose.shape[0] # pose: float32 [K, 17, 2 or 3]
25 dims = pose.shape[2]
26
27 if which == 'zero_center':
28 # zero-centered
29 center_output = (pose - pose[:,0].reshape((batch_size, 1, -1))).float() # torch.Size([K, 17, 2]) float
30 # avoid divide by zero
31 avoid_zero = np.zeros((17, 3))
32 avoid_zero[0, :] = 1
33 std_avoid_zero = mean_and_std['std'] + torch.from_numpy(avoid_zero).to(device='cuda', dtype=center_output.dtype) # [17, 3]
34 if dims == 2:
35 pose = torch.div(center_output - mean_and_std['mean'][:, :2], std_avoid_zero[:, :2]) # torch.Size([K, 17, 2])
36 else:
37 pose = torch.div(center_output - mean_and_std['mean'], std_avoid_zero) # torch.Size([K, 17, 3])
38 elif which == 'scale':
39 pose = (pose - pose[:,0].reshape((batch_size, 1, -1))).float()
40 for idx in range(batch_size):
41 res_idx = res_w_h[idx].split(' ')
42 res_w, res_h = int(res_idx[0]), int(res_idx[1])
43 if dims == 2:
44 pose[idx, :, :] = pose[idx, :, :] / res_w #- torch.tensor([1, res_h / res_w]).float().cuda()
45 else:
46 pose[idx, :, :2] = pose[idx, :, :2] / res_w #- torch.tensor([1, res_h / res_w]).float().cuda()
47 pose[idx, :, 2:] = pose[idx, :, 2:] / res_w
48 elif which == 'scale_s':
49 #scale = scale.transpose(1,0)
50 #print('tran',scale)
51 if dims ==2:
52 pose[:,:,0] = pose[:,:,0] / (scale[0].view(-1,1))
53 pose[:,:,1] = pose[:,:,1] / (scale[1].view(-1,1))
54 else:
55 pose[:,:,0] = pose[:,:,0] / (scale[0].view(-1,1))
56 pose[:,:,1] = pose[:,:,1] / (scale[1].view(-1,1))
57 pose[:,:,2] = pose[:,:,2] / (scale[2].view(-1,1))
58 pose = (pose - pose[:,0].reshape((batch_size, 1, -1))).float()
59 elif which == 'scale_t':
60 if not mean_and_std:
61 mean_and_std =1
62 if dims ==2:
63 pose[:,:,0] = pose[:,:,0] / (scale[0].view(-1,1))- 0.5*mean_and_std
64 pose[:,:,1] = pose[:,:,1] / (scale[1].view(-1,1))- 0.5*mean_and_std
65 else:
66 pose[:,:,0] = pose[:,:,0] / (scale[0].view(-1,1))- 0.5*mean_and_std
67 pose[:,:,1] = pose[:,:,1] / (scale[1].view(-1,1))- 0.5*mean_and_std
68 pose[:,:,2] = pose[:,:,2] / (scale[2].view(-1,1))
69 pose = pose * 2
70 else:
71 assert 0, 'only support zero_center or scale normalization'
72 pose = pose.reshape((batch_size, -1))
73
74 return pose
75def denormalize_pose_cuda(pose, mean_and_std=None,res_w_h=None, which='zero_center',scale = None,two_d = False):
76 """
77 pose: [N, 17*3]

Callers 4

trainMethod · 0.50
trainMethod · 0.50
gen_meshMethod · 0.50
gen_meshMethod · 0.50

Calls 1

toMethod · 0.45

Tested by

no test coverage detected