add soft/noisey label for GAN loss
This commit is contained in:
1 parent
5a6725072a
commit
6fe3a2c3cd
6 files changed
+38
-20
No files matched your search
@@ -48,7 +48,7 @@ model:
|
||||
path_mean_dict: ${path_data}/mean_deca_coeff_Actor6_processing2.npy
|
||||
|
||||
pretrain: True
|
||||
pretrain_path: ${path_cwd}/logs/experiments/runs/audio2motion/2022-06-09_17-19-57/checkpoints/epoch_009-v1.ckpt
|
||||
pretrain_path: ${path_cwd}/logs/experiments/runs/audio2motion/2022-06-09_21-35-54/checkpoints/epoch_014.ckpt
|
||||
|
||||
opt_optim:
|
||||
lr_G: 0.0005 # 0.00125
|
||||
|
||||
+2
-1
@@ -49,12 +49,13 @@ model:
|
||||
path_mean_dict: ${path_data}/mean_deca_coeff_Actor7_processing.npy
|
||||
|
||||
pretrain: True
|
||||
pretrain_path: ${path_cwd}/logs/experiments/runs/audio2motion/2022-06-09_17-19-57/checkpoints/epoch_009-v1.ckpt
|
||||
pretrain_path: ${path_cwd}/logs/experiments/runs/audio2motion/2022-06-09_17-19-57/checkpoints/epoch_040.ckpt
|
||||
|
||||
opt_optim:
|
||||
lr_G: 0.0005 # 0.00125
|
||||
lr_D: 0.0005 # 0.00125
|
||||
|
||||
|
||||
opt_loss:
|
||||
lambda_rec_exp: 0.5
|
||||
lambda_rec_pos: 1
|
||||
@@ -15,7 +15,7 @@ if __name__ == "__main__":
|
||||
sub_folder = "processing2" # processing, smile, body
|
||||
|
||||
path_data = Path(f"/ssdata1/lsen/DATA/{actor}/{sub_folder}")
|
||||
path_save = Path(f'data/{actor}/{actor}-raw-{sub_folder}-2h')
|
||||
path_save = Path(f'data/{actor}/{actor}-raw-{sub_folder}-10min')
|
||||
path_save.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
# set logging
|
||||
@@ -118,6 +118,9 @@ if __name__ == "__main__":
|
||||
# ####################################
|
||||
|
||||
if vid in vid_train:
|
||||
# if durations_train / 3600 > 6: break
|
||||
if durations_train / 60 > 10: continue
|
||||
|
||||
durations_train += nframes/fps
|
||||
list_train.append(vid)
|
||||
|
||||
|
||||
+23
-10
@@ -1,27 +1,40 @@
|
||||
import torch
|
||||
import torch.nn.functional as F
|
||||
import logging
|
||||
|
||||
def get_label(pred, target_is_real, soft_and_noisy=False):
|
||||
|
||||
if target_is_real:
|
||||
if not soft_and_noisy:
|
||||
return torch.ones_like(pred) # all 1
|
||||
else:
|
||||
# 0~1 uniform [0,1) , NOTE: not randn_like, which is not [0,1)
|
||||
# [0,1) --> [0,0.5) --> [0.5, 1.0)
|
||||
return torch.rand_like(pred) * 0.5 + 0.5
|
||||
else:
|
||||
if not soft_and_noisy:
|
||||
return torch.zeros_like(pred) # all 0
|
||||
else:
|
||||
# 0~1 uniform [0,1) , NOTE: not randn_like, which is not [0,1)
|
||||
# [0,1) --> [0,0.3)
|
||||
return torch.rand_like(pred) * 0.3
|
||||
|
||||
|
||||
def adversarial_loss(pred, target_is_real=True, loss_mode="vanilla"):
|
||||
target = get_label(pred, target_is_real, soft_and_noisy=True)
|
||||
# logging.info(f"[validation] target ={target.shape}, target_is_real={target_is_real}")
|
||||
|
||||
if loss_mode == "vanilla":
|
||||
if target_is_real:
|
||||
target = torch.ones_like(pred)
|
||||
else:
|
||||
target = torch.zeros_like(pred)
|
||||
return F.binary_cross_entropy_with_logits(pred, target)
|
||||
|
||||
elif loss_mode == "lsgan":
|
||||
if target_is_real:
|
||||
target = torch.ones_like(pred)
|
||||
else:
|
||||
target = torch.zeros_like(pred)
|
||||
return F.mse_loss(pred, target)
|
||||
|
||||
elif loss_mode == "hinge":
|
||||
if target_is_real:
|
||||
loss = torch.maximum(1-pred, torch.ones_like(pred)).mean()
|
||||
loss = torch.maximum(1-pred, target).mean()
|
||||
else:
|
||||
loss = torch.maximum(1+pred, torch.zeros_like(pred)).mean()
|
||||
loss = torch.maximum(1+pred, target).mean()
|
||||
return loss
|
||||
|
||||
else:
|
||||
|
||||
@@ -49,9 +49,11 @@ class Generator(nn.Module):
|
||||
self.decoder = nn.Sequential(
|
||||
nn.Linear(in_features=128 + dim_z, out_features=2048), # 2048,
|
||||
nn.LeakyReLU(0.02, True),
|
||||
nn.Dropout(0.3),
|
||||
|
||||
nn.Linear(in_features=2048, out_features=128), # 128,
|
||||
nn.LeakyReLU(0.02, True),
|
||||
nn.Dropout(0.3),
|
||||
|
||||
nn.Linear(in_features=128, out_features=dim_x), # dim_x
|
||||
)
|
||||
@@ -130,15 +132,15 @@ class Discriminator(torch.nn.Module):
|
||||
nn.LeakyReLU(0.02, True),
|
||||
|
||||
|
||||
nn.Conv2d(256, 256, kernel_size=(3,1), stride=(2,1), padding=(1,0), bias=True), # 64 x 1 x 1
|
||||
nn.Conv2d(256, 256, kernel_size=(3,1), stride=(2,1), padding=(1,0), bias=True), # 64 x 1 x 1
|
||||
nn.LeakyReLU(0.02, True),
|
||||
nn.Conv2d(256, 256, kernel_size=(3,1), stride=(1,1), padding=(1,0), bias=True), # 32 x 8 x 1
|
||||
nn.Conv2d(256, 256, kernel_size=(3,1), stride=(1,1), padding=(1,0), bias=True), # 32 x 8 x 1
|
||||
nn.LeakyReLU(0.02, True),
|
||||
|
||||
nn.Conv2d(256, 128, kernel_size=(3,1), stride=(2,1), padding=(1,0), bias=True), # 128 x 1 x 1
|
||||
nn.Conv2d(256, 128, kernel_size=(3,1), stride=(2,1), padding=(1,0), bias=True), # 128 x 1 x 1
|
||||
nn.LeakyReLU(0.02, True),
|
||||
|
||||
nn.Flatten(), # 128,
|
||||
nn.Flatten(), # 128,
|
||||
)
|
||||
|
||||
|
||||
@@ -147,10 +149,10 @@ class Discriminator(torch.nn.Module):
|
||||
nn.Linear(in_features=128 + dim_x, out_features=2048), # 2048,
|
||||
nn.LeakyReLU(0.02, True),
|
||||
|
||||
nn.Linear(in_features=2048, out_features=128), # 128,
|
||||
nn.Linear(in_features=2048, out_features=128), # 128,
|
||||
nn.LeakyReLU(0.02, True),
|
||||
|
||||
nn.Linear(in_features=128, out_features=16), # 16
|
||||
nn.Linear(in_features=128, out_features=16), # 16
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -373,7 +373,6 @@ class Audio2MotionGANModel(LightningModule):
|
||||
batch_z = torch.randn(B, N, self.opt.dim_z).type_as(batch_c) # (B, dim_latent)
|
||||
batch_pdt = self.netG(batch_z, batch_c) #(B, N, nc_motion)
|
||||
|
||||
|
||||
##################################################
|
||||
######### Discriminator #########
|
||||
# GT label
|
||||
|
||||
Reference in new issue
Block a user