add infer loss for LuoXData with long data by clip & alignment data
This commit is contained in:
1 parent
386df9a4ab
commit
ded9b27f71
42 files changed
+1233
-1361
No files matched your search
@@ -55,9 +55,13 @@ class Audio2MeshSpecificModel(Base):
|
||||
debug(opt, f"template_verts shape = {self.template_verts.shape}")
|
||||
debug(opt, f"mean_dict keys = {self.mean_dict.keys()}", verbose=True)
|
||||
|
||||
self.loss_func_l1 = nn.L1Loss(reduction="mean")
|
||||
self.loss_func_wing = WingLoss(reduction="mean")
|
||||
# self.loss_func_l1 = nn.L1Loss(reduction="mean")
|
||||
# self.loss_func_wing = WingLoss(reduction="mean")
|
||||
|
||||
self.loss_func_wing = WingLoss(reduction="none") # return (B, )
|
||||
self.loss_func_l1 = nn.L1Loss(reduction="none")
|
||||
|
||||
|
||||
if self.isTrain:
|
||||
self.names_loss = opt.LOSS.names
|
||||
|
||||
@@ -198,6 +202,27 @@ class Audio2MeshSpecificModel(Base):
|
||||
print(f"save infer_result shape = {samples_pt.shape} -> {path_save_npy}")
|
||||
|
||||
|
||||
# def infer_loss(self, batch_cond, batch_data):
|
||||
# """
|
||||
# input parameters:
|
||||
# batch_cond: B x nsteps x 16 x nfeat_speech
|
||||
# batch_data: B x nsteps x nfeat_motion
|
||||
# return:
|
||||
# loss: B x nsteps x 3
|
||||
# """
|
||||
# self.eval()
|
||||
# self.cond = batch_cond.float().to(self.device) # (B x nsteps x 16 x nc_condit)
|
||||
# self.data = batch_data.float().to(self.device) # (B x nsteps x nc_motion)
|
||||
|
||||
# with torch.no_grad():
|
||||
# samples_pt = self.netG(self.cond) # B x N x 16 x nc_condit
|
||||
# samples_pt += self.template_verts # B x N x 5023 x 3
|
||||
|
||||
# loss = self.eval_losses_for_infer_loss(self.pred, self.data)
|
||||
|
||||
# return loss
|
||||
|
||||
|
||||
def testing(self, batch_input, cur_epoch=0, cur_batch=0):
|
||||
self.eval() # set eval model
|
||||
self.set_input(batch_input)
|
||||
@@ -258,6 +283,8 @@ class Audio2MeshSpecificModel(Base):
|
||||
return verts
|
||||
|
||||
|
||||
|
||||
|
||||
def eval_losses(self, batch_pdt_geo, batch_tgt):
|
||||
""" Computes the VAE loss function.
|
||||
pramas:
|
||||
@@ -272,23 +299,51 @@ class Audio2MeshSpecificModel(Base):
|
||||
|
||||
# synthesis geo rec
|
||||
loss = 0
|
||||
loss_rec_geo = self.loss_func_wing(batch_pdt_geo, batch_tgt_geo)
|
||||
loss_dict["loss_rec_geo"] = loss_rec_geo.detach()
|
||||
loss_rec_geo = self.loss_func_wing(batch_pdt_geo, batch_tgt_geo) # B
|
||||
loss_dict["loss_rec_geo"] = loss_rec_geo.mean().detach()
|
||||
loss_rec_geo = self.loss_func_l1(batch_pdt_geo, batch_tgt_geo) # B
|
||||
loss_dict["loss_rec_geo_l1"] = loss_rec_geo.mean().detach()
|
||||
|
||||
loss_rec_geo2 = self.loss_func_wing(batch_pdt_geo, batch_tgt_geo, weight=self.vertices_weight)
|
||||
loss_dict["loss_rec_geo_w"] = loss_rec_geo2.detach()
|
||||
loss += loss_rec_geo2 * self.opt.LOSS.lambda_rec_geo
|
||||
|
||||
loss_rec_geo2 = self.loss_func_wing(batch_pdt_geo, batch_tgt_geo, weight=self.vertices_weight) # B x nsteps x num_vertices x 3
|
||||
loss_rec_geo2 = loss_rec_geo2.sum(dim=(2, 3)) / (3 * self.opt.MODEL.num_vertices) # B x nsteps
|
||||
|
||||
# filter outliar
|
||||
threshold_rec, mean_rec = torch.quantile(loss_rec_geo2, q=0.75) * 1.5, torch.quantile(loss_rec_geo2, q=0.5)
|
||||
b_outlier_rec = loss_rec_geo2 > threshold_rec # B x nsteps
|
||||
|
||||
# synthesis geo volocity
|
||||
diff_pdt_geo = batch_pdt_geo[:, 1:, :] - batch_pdt_geo[:, :-1, :]
|
||||
diff_tgt_geo = batch_tgt_geo[:, 1:, :] - batch_tgt_geo[:, :-1, :]
|
||||
|
||||
loss_vol_geo = self.loss_func_wing(diff_pdt_geo, diff_tgt_geo)
|
||||
loss_dict["loss_vol_geo"] = loss_vol_geo.detach()
|
||||
loss_vel_geo = self.loss_func_wing(diff_pdt_geo, diff_tgt_geo)
|
||||
loss_dict["loss_vel_geo"] = loss_vel_geo.mean().detach()
|
||||
loss_vel_geo = self.loss_func_l1(diff_pdt_geo, diff_tgt_geo) # 1,
|
||||
loss_dict["loss_vel_geo_l1"] = loss_vel_geo.mean().detach()
|
||||
|
||||
loss_vol_geo2 = self.loss_func_wing(diff_pdt_geo, diff_tgt_geo, weight=self.vertices_weight)
|
||||
loss_dict["loss_vol_geo_w"] = loss_vol_geo2.detach()
|
||||
loss += loss_vol_geo2 * self.opt.LOSS.lambda_vol_geo
|
||||
loss_vel_geo2 = self.loss_func_wing(diff_pdt_geo, diff_tgt_geo, weight=self.vertices_weight) # B x nsteps x num_vertices x 3
|
||||
loss_vel_geo2 = loss_vel_geo2.sum(dim=(2, 3)) / (3 * self.opt.MODEL.num_vertices) # B x nsteps
|
||||
|
||||
# filter outliar
|
||||
threshold_vol, mean_vol = torch.quantile(loss_vel_geo2, q=0.75) * 1.5, torch.quantile(loss_vel_geo2, q=0.5)
|
||||
b_outlier_vol = loss_vel_geo2 > threshold_vol # B x (nsteps-1)
|
||||
|
||||
# find outliar in both loss data
|
||||
b_outlier_rec[:, :-1] = b_outlier_rec[:, :-1] & b_outlier_vol[:, :]
|
||||
if torch.any(b_outlier_rec):
|
||||
# print(f"b_outlier_rec = {b_outlier_rec}")
|
||||
# print(f"outerliar size= {loss_rec_geo2[b_outlier_rec].shape} / {loss_rec_geo2.numel()} ")
|
||||
loss_rec_geo2[b_outlier_rec] = mean_rec
|
||||
loss_vel_geo2[b_outlier_rec[:, :-1]] = mean_vol
|
||||
|
||||
# calculate again
|
||||
loss_rec_geo2 = loss_rec_geo2.mean()
|
||||
loss_dict["loss_rec_geo_w"] = loss_rec_geo2.detach()
|
||||
loss += loss_rec_geo2 * self.opt.LOSS.lambda_rec_geo
|
||||
|
||||
loss_vel_geo2 = loss_vel_geo2.mean()
|
||||
loss_dict["loss_vel_geo_w"] = loss_vel_geo2.detach()
|
||||
loss += loss_vel_geo2 * self.opt.LOSS.lambda_vel_geo
|
||||
|
||||
# total loss
|
||||
loss_dict['loss_all'] = loss.detach()
|
||||
|
||||
Reference in new issue
Block a user