add landmarks for actor3
This commit is contained in:
1 parent
ad93886668
commit
e2e8d8baf8
5 files changed
+93
-21
No files matched your search
@@ -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
|
||||
@@ -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',
|
||||
|
||||
Reference in new issue
Block a user