-
Notifications
You must be signed in to change notification settings - Fork 0
/
div2h5.py
30 lines (25 loc) · 925 Bytes
/
div2h5.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
import os
import glob
import h5py
import scipy.misc as misc
import numpy as np
import cv2
dataset_dir = "/share/datasets/DIV2K"
dataset_type = "train"
f = h5py.File("datasets/DIV2K_{}.h5".format(dataset_type), "w")
dt = h5py.special_dtype(vlen=np.dtype('uint8'))
for subdir in ["HR", "X2", "X3", "X4", "X8"]:
if subdir in ["HR"]:
im_paths = glob.glob(os.path.join(dataset_dir,
"DIV2K_{}_HR".format(dataset_type),
"*.png"))
else:
im_paths = glob.glob(os.path.join(dataset_dir,
"DIV2K_{}_LR_bicubic_{}".format(dataset_type,subdir),
"*.png"))
im_paths.sort()
grp = f.create_group(subdir)
for i, path in enumerate(im_paths):
im = cv2.imread(path)
print(path)
grp.create_dataset(str(i), data=im)