Spaces:
Build error
Build error
File size: 5,276 Bytes
865fd8a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
import os
import pickle
from tqdm import tqdm
import shutil
import torch
import numpy as np
import librosa
import random
speakers = ['seth', 'conan', 'oliver', 'chemistry']
data_root = "../ExpressiveWholeBodyDatasetv1.0/"
split = 'train'
def split_list(full_list,shuffle=False,ratio=0.2):
n_total = len(full_list)
offset_0 = int(n_total * ratio)
offset_1 = int(n_total * ratio * 2)
if n_total==0 or offset_1<1:
return [],full_list
if shuffle:
random.shuffle(full_list)
sublist_0 = full_list[:offset_0]
sublist_1 = full_list[offset_0:offset_1]
sublist_2 = full_list[offset_1:]
return sublist_0, sublist_1, sublist_2
def moveto(list, file):
for f in list:
before, after = '/'.join(f.split('/')[:-1]), f.split('/')[-1]
new_path = os.path.join(before, file)
new_path = os.path.join(new_path, after)
# os.makedirs(new_path)
# os.path.isdir(new_path)
# shutil.move(f, new_path)
#转移到新目录
shutil.copytree(f, new_path)
#删除原train里的文件
shutil.rmtree(f)
return None
def read_pkl(data):
betas = np.array(data['betas'])
jaw_pose = np.array(data['jaw_pose'])
leye_pose = np.array(data['leye_pose'])
reye_pose = np.array(data['reye_pose'])
global_orient = np.array(data['global_orient']).squeeze()
body_pose = np.array(data['body_pose_axis'])
left_hand_pose = np.array(data['left_hand_pose'])
right_hand_pose = np.array(data['right_hand_pose'])
full_body = np.concatenate(
(jaw_pose, leye_pose, reye_pose, global_orient, body_pose, left_hand_pose, right_hand_pose), axis=1)
expression = np.array(data['expression'])
full_body = np.concatenate((full_body, expression), axis=1)
if (full_body.shape[0] < 90) or (torch.isnan(torch.from_numpy(full_body)).sum() > 0):
return 1
else:
return 0
for speaker_name in speakers:
speaker_root = os.path.join(data_root, speaker_name)
videos = [v for v in os.listdir(speaker_root)]
print(videos)
haode = huaide = 0
total_seqs = []
for vid in tqdm(videos, desc="Processing training data of {}......".format(speaker_name)):
# for vid in videos:
source_vid = vid
vid_pth = os.path.join(speaker_root, source_vid)
# vid_pth = os.path.join(speaker_root, source_vid, 'images/half', split)
t = os.path.join(speaker_root, source_vid, 'test')
v = os.path.join(speaker_root, source_vid, 'val')
# if os.path.exists(t):
# shutil.rmtree(t)
# if os.path.exists(v):
# shutil.rmtree(v)
try:
seqs = [s for s in os.listdir(vid_pth)]
except:
continue
# if len(seqs) == 0:
# shutil.rmtree(os.path.join(speaker_root, source_vid))
# None
for s in seqs:
quality = 0
total_seqs.append(os.path.join(vid_pth,s))
seq_root = os.path.join(vid_pth, s)
key = seq_root # correspond to clip******
audio_fname = os.path.join(speaker_root, source_vid, s, '%s.wav' % (s))
# delete the data without audio or the audio file could not be read
if os.path.isfile(audio_fname):
try:
audio = librosa.load(audio_fname)
except:
# print(key)
shutil.rmtree(key)
huaide = huaide + 1
continue
else:
huaide = huaide + 1
# print(key)
shutil.rmtree(key)
continue
# check motion file
motion_fname = os.path.join(speaker_root, source_vid, s, '%s.pkl' % (s))
try:
f = open(motion_fname, 'rb+')
except:
shutil.rmtree(key)
huaide = huaide + 1
continue
data = pickle.load(f)
w = read_pkl(data)
f.close()
quality = quality + w
if w == 1:
shutil.rmtree(key)
# print(key)
huaide = huaide + 1
continue
haode = haode + 1
print("huaide:{}, haode:{}, total_seqs:{}".format(huaide, haode, total_seqs.__len__()))
for speaker_name in speakers:
speaker_root = os.path.join(data_root, speaker_name)
videos = [v for v in os.listdir(speaker_root)]
print(videos)
haode = huaide = 0
total_seqs = []
for vid in tqdm(videos, desc="Processing training data of {}......".format(speaker_name)):
# for vid in videos:
source_vid = vid
vid_pth = os.path.join(speaker_root, source_vid)
try:
seqs = [s for s in os.listdir(vid_pth)]
except:
continue
for s in seqs:
quality = 0
total_seqs.append(os.path.join(vid_pth, s))
print("total_seqs:{}".format(total_seqs.__len__()))
# split the dataset
test_list, val_list, train_list = split_list(total_seqs, True, 0.1)
print(len(test_list), len(val_list), len(train_list))
moveto(train_list, 'train')
moveto(test_list, 'test')
moveto(val_list, 'val')
|