-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREDSloader_test.py
71 lines (57 loc) · 2.16 KB
/
REDSloader_test.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
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
import math
import os
import torchvision.utils
from fogsr.data import build_dataloader, build_dataset
def main(mode='folder'):
"""Test reds dataset.
Args:
mode: There are two modes: 'lmdb', 'folder'.
"""
opt = {}
opt['dist'] = False
opt['phase'] = 'train'
opt['name'] = 'REDS'
opt['type'] = 'REDSDataset'
if mode == 'folder':
opt['dataroot_gt'] = '/home/cbj/dataset/REDS/train/train_sharp'
opt['dataroot_lq'] = '/home/cbj/dataset/REDS/train/train_sharp_bicubic'
opt['dataroot_flow'] = None
opt['meta_info_file'] = 'fogsr/data/meta_info/meta_info_REDS_GT.txt'
opt['io_backend'] = dict(type='disk')
elif mode == 'lmdb':
opt['dataroot_gt'] = '/home/cbj/dataset/REDS/train/train_sharp_with_val.lmdb'
opt['dataroot_lq'] = '/home/cbj/dataset/REDS/train/train_sharp_bicubic_with_val.lmdb'
opt['dataroot_flow'] = None
opt['meta_info_file'] = 'fogsr/data/meta_info/meta_info_REDS_GT.txt'
opt['io_backend'] = dict(type='lmdb')
opt['val_partition'] = 'REDS4'
opt['num_frame'] = 5
opt['gt_size'] = 256
opt['interval_list'] = [1]
opt['random_reverse'] = True
opt['use_hflip'] = True
opt['use_rot'] = True
opt['num_worker_per_gpu'] = 1
opt['batch_size_per_gpu'] = 16
opt['scale'] = 4
opt['dataset_enlarge_ratio'] = 1
os.makedirs('tmp', exist_ok=True)
dataset = build_dataset(opt)
data_loader = build_dataloader(dataset, opt, num_gpu=0, dist=opt['dist'], sampler=None)
nrow = int(math.sqrt(opt['batch_size_per_gpu']))
padding = 2 if opt['phase'] == 'train' else 0
print('start...')
for i, data in enumerate(data_loader):
if i > 5:
break
print(i)
lq = data['lq']
gt = data['gt']
key = data['key']
print(key)
for j in range(opt['num_frame']):
torchvision.utils.save_image(
lq[:, j, :, :, :], f'tmp/lq_{i:03d}_frame{j}.png', nrow=nrow, padding=padding, normalize=False)
torchvision.utils.save_image(gt, f'tmp/gt_{i:03d}.png', nrow=nrow, padding=padding, normalize=False)
if __name__ == '__main__':
main()