forked from m-tassano/fastdvdnet
-
Notifications
You must be signed in to change notification settings - Fork 1
/
dataset.py
45 lines (36 loc) · 1.47 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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
"""
Dataset related functions
Copyright (C) 2018, Matias Tassano <[email protected]>
This program is free software: you can use, modify and/or
redistribute it under the terms of the GNU General Public
License as published by the Free Software Foundation, either
version 3 of the License, or (at your option) any later
version. You should have received a copy of this license along
this program. If not, see <http://www.gnu.org/licenses/>.
"""
import os
import glob
import torch
from torch.utils.data.dataset import Dataset
from utils import open_sequence
NUMFRXSEQ_VAL = 15 # number of frames of each sequence to include in validation dataset
VALSEQPATT = '*' # pattern for name of validation sequence
class ValDataset(Dataset):
"""Validation dataset. Loads all the images in the dataset folder on memory.
"""
def __init__(self, valsetdir=None, gray_mode=False, num_input_frames=NUMFRXSEQ_VAL):
self.gray_mode = gray_mode
# Look for subdirs with individual sequences
seqs_dirs = sorted(glob.glob(os.path.join(valsetdir, VALSEQPATT)))
# open individual sequences and append them to the sequence list
sequences = []
for seq_dir in seqs_dirs:
seq, _, _ = open_sequence(seq_dir, gray_mode, expand_if_needed=False, \
max_num_fr=num_input_frames)
# seq is [num_frames, C, H, W]
sequences.append(seq)
self.sequences = sequences
def __getitem__(self, index):
return torch.from_numpy(self.sequences[index])
def __len__(self):
return len(self.sequences)