-
Notifications
You must be signed in to change notification settings - Fork 1
/
dataloader.py
42 lines (31 loc) · 1.14 KB
/
dataloader.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
31
32
33
34
35
36
37
38
39
40
41
42
import os
import glob
import numpy as np
import pickle as pkl
from common import *
from torch.utils.data import Dataset, DataLoader
import random
from align import Align
from video import Video
class GRIDDataset(Dataset):
def __init__(self,
video_path,
align_path,
video_padding_length,
):
self.video_path = video_path
self.align_path = align_path
self.video_padding_length = video_padding_length
self.videos = glob.glob(os.path.join(video_path, "*", "*"))
self.n_videos = len(self.videos)
def __len__(self):
return self.n_videos
def __getitem__(self, index):
file = self.videos[index]
video = Video(file)
align = Align(os.path.join(self.align_path, video.speaker, 'align', video.name+".align"))
return {'video_input': video.get_frames(0, video.n_frames, self.video_padding_length),
'video_length': self.video_padding_length,
'targets_input': align.sentence(),
'targets_length': align.sentence_length,
}