diff --git a/experiments/audio2mesh/train_audio2mesh_CN_20220322.yaml b/experiments/audio2mesh/train_audio2mesh_CN_20220322.yaml index 4f6f2f8..9f9ec2b 100644 --- a/experiments/audio2mesh/train_audio2mesh_CN_20220322.yaml +++ b/experiments/audio2mesh/train_audio2mesh_CN_20220322.yaml @@ -1,4 +1,4 @@ -GPUS: '9' +GPUS: '3' WORKERS: 4 OUTPUT_DIR: 'experiments/audio2mesh' @@ -6,7 +6,7 @@ DEBUG: False verbose: False VISUAL: - vsdm_env: "audio2mesh-actor3-1h" + vsdm_env: "audio2mesh-actor3-2h-ldmk" FREQ: epoch_save: 5 @@ -34,7 +34,7 @@ DATASET: flip: False shifting_speed: True - root: './data/Actor3/Actor3-raw-1h' # obama-deca-3-5-08-mini + root: './data/Actor3/Actor3-raw-2h' # obama-deca-3-5-08-mini root_raw: '/mfs/lsen/DATA/Actor3/processing' path_mean_dict: './data/Actor3/DECA_Actor3_mean.npy' filter: 'savgol' @@ -69,9 +69,9 @@ TRAIN: resume: False reset_lr: False - resume_suffix: "20220128-10H10M10S" + resume_suffix: "20220403-00H39M11S" epoch_begin: 0 # 5000 # 2300 # 2600 - epoch_end: 100 + epoch_end: 500 LOSS: diff --git a/scripts/Actor3Data/run-30-dectect-landmark.py b/scripts/Actor3Data/run-30-dectect-landmark.py new file mode 100644 index 0000000..a578028 --- /dev/null +++ b/scripts/Actor3Data/run-30-dectect-landmark.py @@ -0,0 +1,73 @@ +from torch.utils.data import Dataset, DataLoader + +import torch +import numpy as np +from PIL import Image +from pathlib2 import Path +from face_alignment import FaceAlignment, LandmarksType +from zmq import device + + +class ImagesDataset(Dataset): + def __init__(self, path_folder:Path): + + self.path_folder = path_folder + self.list_image = sorted(path_folder.glob("*.jpg"), reverse=False) + print(f"Have {len(self.list_image)} images, like {self.list_image[:3]}") + + + def __len__(self): + return len(self.list_image) + + def __getitem__(self, idx): + path_frame = self.list_image[idx] + image = Image.open(str(path_frame)).convert('RGB') # (h, w, 3) + image = np.asarray(image) + return {"image_name": path_frame.stem, "image": image} + + +if __name__ == "__main__": + + path_data = Path("/mfs/lsen/DATA/Actor3/processing") + vpath_videos = sorted(path_data.glob("*")) + print(f"Have {len(vpath_videos)} dir files") + + device = "cuda:1" + model = FaceAlignment(LandmarksType._2D, device=device, face_detector='sfd') + print(f"load FaceAlignment model in {device}") + + # IDs = ["2-23min"] + # for each word + for i, ipath_item in enumerate(vpath_videos): + iname = ipath_item.stem + print(f"processing {i}/{len(vpath_videos)} -> {ipath_item} ... ") + + # if iname not in IDs: continue + + ipath_infor = ipath_item.joinpath("video/info.json") + ipath_ldmks = ipath_item.joinpath("landmarks_FAN") + ipath_frame = ipath_item.joinpath("frames") + ipath_ldmks.mkdir(parents=True, exist_ok=True) + + dataset = ImagesDataset(ipath_frame) + dloader = DataLoader(dataset, batch_size=16, num_workers=8) + + for k, ibatch in enumerate(dloader): + ibatch_name = ibatch["image_name"] + ibatch_data = ibatch["image"].to(device) # B x H x W x 3 + ibatch_data = ibatch_data.permute(0, 3, 1, 2) # B x H x W x 3 + # print(f"ibatch_data shape = {ibatch_data.shape}, path={ibatch_name[:3]}") + if k%100 == 0: + print(f"batching {k}/{len(dloader)} ... ") + + pred = model.get_landmarks_from_batch(ibatch_data, return_landmark_score=False) + # print(f"pred len = {len(pred)}, type= {type(pred)}, [0] shape={pred[0].shape}") + + # save landmarks + for jldmk, jname in zip(pred, ibatch_name): + jpath_ldmk = ipath_ldmks.joinpath(jname + ".txt") + np.savetxt(jpath_ldmk, jldmk, fmt=" %3d") + + + + # break \ No newline at end of file diff --git a/scripts/Actor3Data/run-41-train-dict-data-raw-deca.py b/scripts/Actor3Data/run-41-train-dict-data-raw-deca.py index 9e717b5..664c62a 100644 --- a/scripts/Actor3Data/run-41-train-dict-data-raw-deca.py +++ b/scripts/Actor3Data/run-41-train-dict-data-raw-deca.py @@ -30,7 +30,7 @@ def landmark_resample_fps(y, source_fps = 30, target_fps=25): if __name__ == "__main__": path_data = Path("/mfs/lsen/DATA/Actor3/processing") - path_save = Path('data/Actor2/Actor3-raw-1h') # processing + path_save = Path('data/Actor3/Actor3-raw-2h') # processing path_save.mkdir(parents=True, exist_ok=True) v_dir_videos = sorted(path_data.glob("*/audio/feat_DECA_exp_trim.npy")) @@ -40,8 +40,8 @@ if __name__ == "__main__": vids = set([ipath.stem for ipath in v_dir_videos]) # print(f"vids total= {vids}") - vid_test = set(["BU6A9965"]) - vid_valid = set(["BU6A9965"]) + vid_test = set(["BU6A9978"]) + vid_valid = set(["BU6A9965","BU6A9980","BU6A9978"]) # vid_train = set(['AA7A9570', 'AA7A9571', 'AA7A9572', 'AA7A9573', 'AA7A9574', 'AA7A9575', 'AA7A9576', 'AA7A9579', # 'AA7A9580', 'AA7A9582', 'AA7A9583', 'AA7A9584', 'AA7A9585', 'AA7A9600', 'AA7A9601', 'AA7A9602', # 'AA7A9603', 'AA7A9604', 'AA7A9605', 'AA7A9606', 'AA7A9607', 'AA7A9608', 'AA7A9609', 'AA7A9610', diff --git a/src/models/base.py b/src/models/base.py index 4ec94c3..c4a3be4 100644 --- a/src/models/base.py +++ b/src/models/base.py @@ -279,20 +279,19 @@ class Base(): self.logger.info('loading the model from %s' % path_checkpoint) # net.module.set_actnorm_init(True) # set actnorm - - if load_info: - # load training state - path_state = load_path.joinpath("checkpoints", f'{load_suffix}_net_train_state.pth') - load_state = torch.load(str(path_state), map_location=str(self.device)) + # if load_info: + # # load training state + # path_state = load_path.joinpath("checkpoints", f'{load_suffix}_net_train_state.pth') + # load_state = torch.load(str(path_state), map_location=str(self.device)) - for name in self.names_model: - optimizer_ = getattr(self, 'optimizer_' + name) - scheduler_ = getattr(self, 'scheduler_' + name) - optimizer_.load_state_dict(load_state['optimizers']['optimizer_' + name]) - scheduler_.load_state_dict(load_state['schedulers']['scheduler_' + name]) + # for name in self.names_model: + # optimizer_ = getattr(self, 'optimizer_' + name) + # scheduler_ = getattr(self, 'scheduler_' + name) + # optimizer_.load_state_dict(load_state['optimizers']['optimizer_' + name]) + # scheduler_.load_state_dict(load_state['schedulers']['scheduler_' + name]) - if self.opt.TRAIN.reset_lr: - optimizer_.param_groups[0]['lr'] = self.opt.TRAIN.lr + # if self.opt.TRAIN.reset_lr: + # optimizer_.param_groups[0]['lr'] = self.opt.TRAIN.lr def print_networks(self, verbose): """Print the total number of parameters in the network and network architecture diff --git a/train.py b/train.py index f38c800..855d69d 100644 --- a/train.py +++ b/train.py @@ -40,7 +40,7 @@ def parese_args(): # losses: same format as |losses| of plot_current_losses def logger_loss(logger, epoch, batch, loss_dict): if isinstance(batch, str): - msg_head = f"\n[Epoch:{epoch:03d}-{batch}]" + msg_head = f"[Epoch:{epoch:03d}-{batch}]" else: msg_head = f"[Epoch:{epoch:03d}-{batch:04d}]"