forked from zhongshaoyy/Audio2Face
-
Notifications
You must be signed in to change notification settings - Fork 1
/
dataset.py
30 lines (23 loc) · 1.1 KB
/
dataset.py
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
from torch.utils.data import Dataset
import numpy as np
class BlendshapeDataset(Dataset):
def __init__(self, feature_file, target_file):
self.wav_feature = np.load(feature_file)
# reshape to avoid automatic conversion to doubletensor
self.blendshape_target = np.loadtxt(target_file) / 100.0
self._align()
def __len__(self):
return len(self.wav_feature)
def _align(self):
"""
align audio feature with blendshape feature
generally, number of audio feature is less
"""
n_audioframe, n_videoframe = len(self.wav_feature), len(self.blendshape_target)
print('Current dataset -- n_videoframe: {}, n_audioframe:{}'.format(n_videoframe, n_audioframe))
assert n_videoframe - n_audioframe <= 40
if n_videoframe != n_audioframe:
start_videoframe = 16
self.blendshape_target = self.blendshape_target[start_videoframe : start_videoframe+n_audioframe]
def __getitem__(self, index):
return self.wav_feature[index], self.blendshape_target[index]