beta add render
This commit is contained in:
1 parent
83f99d9ec5
commit
b4c197a8ac
30 files changed
+3210
-235
No files matched your search
+25
-18
@@ -128,13 +128,14 @@ def batch_kp_2d_l1_loss(real_2d_kp, predicted_2d_kp, weights=None):
|
||||
kp_pred: N x K x 2
|
||||
"""
|
||||
if weights is not None:
|
||||
real_2d_kp[:,:,2] = weights[None,:]*real_2d_kp[:,:,2]
|
||||
real_2d_kp[..., 2] = weights[None, None, :] * real_2d_kp[...,2]
|
||||
|
||||
kp_gt = real_2d_kp.view(-1, 3)
|
||||
|
||||
kp_pred = predicted_2d_kp.contiguous().view(-1, 2)
|
||||
vis = kp_gt[:, 2]
|
||||
vis = kp_gt[..., 2]
|
||||
k = torch.sum(vis) * 2.0 + 1e-8
|
||||
dif_abs = torch.abs(kp_gt[:, :2] - kp_pred).sum(1)
|
||||
dif_abs = torch.abs(kp_gt[..., :2] - kp_pred).sum(1)
|
||||
|
||||
return torch.matmul(dif_abs, vis) * 1.0 / k
|
||||
|
||||
@@ -142,9 +143,11 @@ def batch_kp_2d_l1_loss(real_2d_kp, predicted_2d_kp, weights=None):
|
||||
def landmark_loss(predicted_landmarks, landmarks_gt, weight=1.):
|
||||
# (predicted_theta, predicted_verts, predicted_landmarks) = ringnet_outputs[-1]
|
||||
if torch.is_tensor(landmarks_gt) is not True:
|
||||
real_2d = torch.cat(landmarks_gt).cuda()
|
||||
real_2d = torch.cat(landmarks_gt).to(predicted_landmarks.device)
|
||||
else:
|
||||
real_2d = torch.cat([landmarks_gt, torch.ones((landmarks_gt.shape[0], 68, 1)).cuda()], dim=-1)
|
||||
dims = landmarks_gt.shape
|
||||
real_2d = torch.cat([landmarks_gt,
|
||||
torch.ones(dims[:-2]+[68, 1]).to(landmarks_gt.device)], dim=-1) # (..., 68, 3)
|
||||
# real_2d = torch.cat(landmarks_gt).cuda()
|
||||
|
||||
loss_lmk_2d = batch_kp_2d_l1_loss(real_2d, predicted_landmarks)
|
||||
@@ -154,20 +157,22 @@ def landmark_loss(predicted_landmarks, landmarks_gt, weight=1.):
|
||||
def eye_dis(landmarks):
|
||||
# left eye: [38,42], [39,41] - 1
|
||||
# right eye: [44,48], [45,47] -1
|
||||
eye_up = landmarks[:,[37, 38, 43, 44], :]
|
||||
eye_bottom = landmarks[:,[41, 40, 47, 46], :]
|
||||
eye_up = landmarks[..., [37, 38, 43, 44], :]
|
||||
eye_bottom = landmarks[..., [41, 40, 47, 46], :]
|
||||
dis = torch.sqrt(((eye_up - eye_bottom)**2).sum(2)) #[bz, 4]
|
||||
return dis
|
||||
|
||||
|
||||
def eyed_loss(predicted_landmarks, landmarks_gt, weight=1.):
|
||||
if torch.is_tensor(landmarks_gt) is not True:
|
||||
real_2d = torch.cat(landmarks_gt).cuda()
|
||||
real_2d = torch.cat(landmarks_gt).to(predicted_landmarks.device)
|
||||
else:
|
||||
real_2d = torch.cat([landmarks_gt, torch.ones((landmarks_gt.shape[0], 68, 1)).cuda()], dim=-1)
|
||||
|
||||
pred_eyed = eye_dis(predicted_landmarks[:,:,:2])
|
||||
gt_eyed = eye_dis(real_2d[:,:,:2])
|
||||
dims = landmarks_gt.shape
|
||||
real_2d = torch.cat([landmarks_gt,
|
||||
torch.ones(dims[:-2]+[68, 1]).to(landmarks_gt.device)], dim=-1)
|
||||
|
||||
pred_eyed = eye_dis(predicted_landmarks[..., :2])
|
||||
gt_eyed = eye_dis(real_2d[..., :2])
|
||||
|
||||
loss = (pred_eyed - gt_eyed).abs().mean()
|
||||
return loss
|
||||
@@ -176,19 +181,21 @@ def eyed_loss(predicted_landmarks, landmarks_gt, weight=1.):
|
||||
def lip_dis(landmarks):
|
||||
# up inner lip: [62, 63, 64] - 1
|
||||
# down innder lip: [68, 67, 66] -1
|
||||
lip_up = landmarks[:,[61, 62, 63], :]
|
||||
lip_down = landmarks[:,[67, 66, 65], :]
|
||||
lip_up = landmarks[..., [61, 62, 63], :]
|
||||
lip_down = landmarks[..., [67, 66, 65], :]
|
||||
dis = torch.sqrt(((lip_up - lip_down)**2).sum(2)) #[bz, 4]
|
||||
return dis
|
||||
|
||||
|
||||
def lipd_loss(predicted_landmarks, landmarks_gt, weight=1.):
|
||||
if torch.is_tensor(landmarks_gt) is not True:
|
||||
real_2d = torch.cat(landmarks_gt).cuda()
|
||||
real_2d = torch.cat(landmarks_gt).to(predicted_landmarks.device)
|
||||
else:
|
||||
real_2d = torch.cat([landmarks_gt, torch.ones((landmarks_gt.shape[0], 68, 1)).cuda()], dim=-1)
|
||||
|
||||
pred_lipd = lip_dis(predicted_landmarks[:,:,:2])
|
||||
dims = landmarks_gt.shape
|
||||
real_2d = torch.cat([landmarks_gt,
|
||||
torch.ones(dims[:-2]+[68, 1]).to(landmarks_gt.device)], dim=-1)
|
||||
|
||||
pred_lipd = lip_dis(predicted_landmarks[...,:2])
|
||||
gt_lipd = lip_dis(real_2d[:,:,:2])
|
||||
|
||||
loss = (pred_lipd - gt_lipd).abs().mean()
|
||||
|
||||
Reference in new issue
Block a user