Spaces:
Running
Running
File size: 14,089 Bytes
2514fb4 |
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 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 |
import argparse
from os import path as osp
from utils.utils_video import scandir
from utils.utils_lmdb import make_lmdb_from_imgs
def create_lmdb_for_div2k():
"""Create lmdb files for DIV2K dataset.
Usage:
Before run this script, please run `extract_subimages.py`.
Typically, there are four folders to be processed for DIV2K dataset.
DIV2K_train_HR_sub
DIV2K_train_LR_bicubic/X2_sub
DIV2K_train_LR_bicubic/X3_sub
DIV2K_train_LR_bicubic/X4_sub
Remember to modify opt configurations according to your settings.
"""
# HR images
folder_path = 'trainsets/DIV2K/DIV2K_train_HR_sub'
lmdb_path = 'trainsets/DIV2K/DIV2K_train_HR_sub.lmdb'
img_path_list, keys = prepare_keys_div2k(folder_path)
make_lmdb_from_imgs(folder_path, lmdb_path, img_path_list, keys)
# LRx2 images
folder_path = 'trainsets/DIV2K/DIV2K_train_LR_bicubic/X2_sub'
lmdb_path = 'trainsets/DIV2K/DIV2K_train_LR_bicubic_X2_sub.lmdb'
img_path_list, keys = prepare_keys_div2k(folder_path)
make_lmdb_from_imgs(folder_path, lmdb_path, img_path_list, keys)
# LRx3 images
folder_path = 'trainsets/DIV2K/DIV2K_train_LR_bicubic/X3_sub'
lmdb_path = 'trainsets/DIV2K/DIV2K_train_LR_bicubic_X3_sub.lmdb'
img_path_list, keys = prepare_keys_div2k(folder_path)
make_lmdb_from_imgs(folder_path, lmdb_path, img_path_list, keys)
# LRx4 images
folder_path = 'trainsets/DIV2K/DIV2K_train_LR_bicubic/X4_sub'
lmdb_path = 'trainsets/DIV2K/DIV2K_train_LR_bicubic_X4_sub.lmdb'
img_path_list, keys = prepare_keys_div2k(folder_path)
make_lmdb_from_imgs(folder_path, lmdb_path, img_path_list, keys)
def prepare_keys_div2k(folder_path):
"""Prepare image path list and keys for DIV2K dataset.
Args:
folder_path (str): Folder path.
Returns:
list[str]: Image path list.
list[str]: Key list.
"""
print('Reading image path list ...')
img_path_list = sorted(list(scandir(folder_path, suffix='png', recursive=False)))
keys = [img_path.split('.png')[0] for img_path in sorted(img_path_list)]
return img_path_list, keys
def create_lmdb_for_reds():
"""Create lmdb files for REDS dataset.
Usage:
Before run this script, please run `regroup_reds_dataset.py`.
We take three folders for example:
train_sharp
train_sharp_bicubic
train_blur (for video deblurring)
Remember to modify opt configurations according to your settings.
"""
# train_sharp
folder_path = 'trainsets/REDS/train_sharp'
lmdb_path = 'trainsets/REDS/train_sharp_with_val.lmdb'
img_path_list, keys = prepare_keys_reds(folder_path)
make_lmdb_from_imgs(folder_path, lmdb_path, img_path_list, keys, multiprocessing_read=True)
# train_sharp_bicubic
folder_path = 'trainsets/REDS/train_sharp_bicubic'
lmdb_path = 'trainsets/REDS/train_sharp_bicubic_with_val.lmdb'
img_path_list, keys = prepare_keys_reds(folder_path)
make_lmdb_from_imgs(folder_path, lmdb_path, img_path_list, keys, multiprocessing_read=True)
# train_blur (for video deblurring)
folder_path = 'trainsets/REDS_blur/train_blur'
lmdb_path = 'trainsets/REDS_blur/train_blur_with_val.lmdb'
img_path_list, keys = prepare_keys_reds(folder_path)
make_lmdb_from_imgs(folder_path, lmdb_path, img_path_list, keys, multiprocessing_read=True)
# train_blur_bicubic (for video deblurring-sr)
folder_path = 'trainsets/REDS_blur_bicubic/train_blur_bicubic'
lmdb_path = 'trainsets/REDS_blur_bicubic/train_blur_bicubic_with_val.lmdb'
img_path_list, keys = prepare_keys_reds(folder_path)
make_lmdb_from_imgs(folder_path, lmdb_path, img_path_list, keys, multiprocessing_read=True)
def prepare_keys_reds(folder_path):
"""Prepare image path list and keys for REDS dataset.
Args:
folder_path (str): Folder path.
Returns:
list[str]: Image path list.
list[str]: Key list.
"""
print('Reading image path list ...')
img_path_list = sorted(list(scandir(folder_path, suffix='png', recursive=True)))
keys = [v.split('.png')[0] for v in img_path_list] # example: 000/00000000
return img_path_list, keys
def create_lmdb_for_vimeo90k():
"""Create lmdb files for Vimeo90K dataset.
Usage:
Remember to modify opt configurations according to your settings.
"""
# GT
folder_path = 'trainsets/vimeo90k/vimeo_septuplet/sequences'
lmdb_path = 'trainsets/vimeo90k/vimeo90k_train_GT_only4th.lmdb'
train_list_path = 'trainsets/vimeo90k/vimeo_septuplet/sep_trainlist.txt'
img_path_list, keys = prepare_keys_vimeo90k(folder_path, train_list_path, 'gt')
make_lmdb_from_imgs(folder_path, lmdb_path, img_path_list, keys, multiprocessing_read=True)
# LQ
folder_path = 'trainsets/vimeo90k/vimeo_septuplet_matlabLRx4/sequences'
lmdb_path = 'trainsets/vimeo90k/vimeo90k_train_LR7frames.lmdb'
train_list_path = 'trainsets/vimeo90k/vimeo_septuplet/sep_trainlist.txt'
img_path_list, keys = prepare_keys_vimeo90k(folder_path, train_list_path, 'lq')
make_lmdb_from_imgs(folder_path, lmdb_path, img_path_list, keys, multiprocessing_read=True)
def create_lmdb_for_vimeo90k_bd():
"""Create lmdb files for Vimeo90K dataset (blur-downsampled lr only).
Usage:
Remember to modify opt configurations according to your settings.
"""
# LQ (blur-downsampled, BD)
folder_path = 'trainsets/vimeo90k/vimeo_septuplet_BDLRx4/sequences'
lmdb_path = 'trainsets/vimeo90k/vimeo90k_train_BDLR7frames.lmdb'
train_list_path = 'trainsets/vimeo90k/vimeo_septuplet/sep_trainlist.txt'
img_path_list, keys = prepare_keys_vimeo90k(folder_path, train_list_path, 'lq')
make_lmdb_from_imgs(folder_path, lmdb_path, img_path_list, keys, multiprocessing_read=True)
def prepare_keys_vimeo90k(folder_path, train_list_path, mode):
"""Prepare image path list and keys for Vimeo90K dataset.
Args:
folder_path (str): Folder path.
train_list_path (str): Path to the official train list.
mode (str): One of 'gt' or 'lq'.
Returns:
list[str]: Image path list.
list[str]: Key list.
"""
print('Reading image path list ...')
with open(train_list_path, 'r') as fin:
train_list = [line.strip() for line in fin]
img_path_list = []
keys = []
for line in train_list:
folder, sub_folder = line.split('/')
img_path_list.extend([osp.join(folder, sub_folder, f'im{j + 1}.png') for j in range(7)])
keys.extend([f'{folder}/{sub_folder}/im{j + 1}' for j in range(7)])
if mode == 'gt':
print('Only keep the 4th frame for the gt mode.')
img_path_list = [v for v in img_path_list if v.endswith('im4.png')]
keys = [v for v in keys if v.endswith('/im4')]
return img_path_list, keys
def create_lmdb_for_dvd():
"""Create lmdb files for DVD dataset.
Usage:
We take two folders for example:
GT
input
Remember to modify opt configurations according to your settings.
"""
# train_sharp
folder_path = 'trainsets/DVD/train_GT'
lmdb_path = 'trainsets/DVD/train_GT.lmdb'
img_path_list, keys = prepare_keys_dvd(folder_path)
make_lmdb_from_imgs(folder_path, lmdb_path, img_path_list, keys, multiprocessing_read=True)
# train_sharp_bicubic
folder_path = 'trainsets/DVD/train_GT_blurred'
lmdb_path = 'trainsets/DVD/train_GT_blurred.lmdb'
img_path_list, keys = prepare_keys_dvd(folder_path)
make_lmdb_from_imgs(folder_path, lmdb_path, img_path_list, keys, multiprocessing_read=True)
def prepare_keys_dvd(folder_path):
"""Prepare image path list and keys for DVD dataset.
Args:
folder_path (str): Folder path.
Returns:
list[str]: Image path list.
list[str]: Key list.
"""
print('Reading image path list ...')
img_path_list = sorted(list(scandir(folder_path, suffix='jpg', recursive=True)))
keys = [v.split('.jpg')[0] for v in img_path_list] # example: 000/00000000
return img_path_list, keys
def create_lmdb_for_gopro():
"""Create lmdb files for GoPro dataset.
Usage:
We take two folders for example:
GT
input
Remember to modify opt configurations according to your settings.
"""
# train_sharp
folder_path = 'trainsets/GoPro/train_GT'
lmdb_path = 'trainsets/GoPro/train_GT.lmdb'
img_path_list, keys = prepare_keys_gopro(folder_path)
make_lmdb_from_imgs(folder_path, lmdb_path, img_path_list, keys, multiprocessing_read=True)
# train_sharp_bicubic
folder_path = 'trainsets/GoPro/train_GT_blurred'
lmdb_path = 'trainsets/GoPro/train_GT_blurred.lmdb'
img_path_list, keys = prepare_keys_gopro(folder_path)
make_lmdb_from_imgs(folder_path, lmdb_path, img_path_list, keys, multiprocessing_read=True)
def prepare_keys_gopro(folder_path):
"""Prepare image path list and keys for GoPro dataset.
Args:
folder_path (str): Folder path.
Returns:
list[str]: Image path list.
list[str]: Key list.
"""
print('Reading image path list ...')
img_path_list = sorted(list(scandir(folder_path, suffix='png', recursive=True)))
keys = [v.split('.png')[0] for v in img_path_list] # example: 000/00000000
return img_path_list, keys
def create_lmdb_for_davis():
"""Create lmdb files for DAVIS dataset.
Usage:
We take one folders for example:
GT
Remember to modify opt configurations according to your settings.
"""
# train_sharp
folder_path = 'trainsets/DAVIS/train_GT'
lmdb_path = 'trainsets/DAVIS/train_GT.lmdb'
img_path_list, keys = prepare_keys_davis(folder_path)
make_lmdb_from_imgs(folder_path, lmdb_path, img_path_list, keys, multiprocessing_read=True)
def prepare_keys_davis(folder_path):
"""Prepare image path list and keys for DAVIS dataset.
Args:
folder_path (str): Folder path.
Returns:
list[str]: Image path list.
list[str]: Key list.
"""
print('Reading image path list ...')
img_path_list = sorted(list(scandir(folder_path, suffix='jpg', recursive=True)))
keys = [v.split('.jpg')[0] for v in img_path_list] # example: 000/00000000
return img_path_list, keys
def create_lmdb_for_ldv():
"""Create lmdb files for LDV dataset.
Usage:
We take two folders for example:
GT
input
Remember to modify opt configurations according to your settings.
"""
# training_raw
folder_path = 'trainsets/LDV/training_raw'
lmdb_path = 'trainsets/LDV/training_raw.lmdb'
img_path_list, keys = prepare_keys_ldv(folder_path)
make_lmdb_from_imgs(folder_path, lmdb_path, img_path_list, keys, multiprocessing_read=True)
# training_fixed-QP
folder_path = 'trainsets/LDV/training_fixed-QP'
lmdb_path = 'trainsets/LDV/training_fixed-QP.lmdb'
img_path_list, keys = prepare_keys_ldv(folder_path)
make_lmdb_from_imgs(folder_path, lmdb_path, img_path_list, keys, multiprocessing_read=True)
# training_fixed-rate
folder_path = 'trainsets/LDV/training_fixed-rate'
lmdb_path = 'trainsets/LDV/training_fixed-rate.lmdb'
img_path_list, keys = prepare_keys_ldv(folder_path)
make_lmdb_from_imgs(folder_path, lmdb_path, img_path_list, keys, multiprocessing_read=True)
def prepare_keys_ldv(folder_path):
"""Prepare image path list and keys for LDV dataset.
Args:
folder_path (str): Folder path.
Returns:
list[str]: Image path list.
list[str]: Key list.
"""
print('Reading image path list ...')
img_path_list = sorted(list(scandir(folder_path, suffix='png', recursive=True)))
keys = [v.split('.png')[0] for v in img_path_list] # example: 000/00000000
return img_path_list, keys
def create_lmdb_for_reds_orig():
"""Create lmdb files for REDS_orig dataset (120 fps).
Usage:
Before run this script, please run `regroup_reds_dataset.py`.
We take one folders for example:
train_orig
Remember to modify opt configurations according to your settings.
"""
# train_sharp
folder_path = 'trainsets/REDS_orig/train_orig'
lmdb_path = 'trainsets/REDS_orig/train_orig_with_val.lmdb'
img_path_list, keys = prepare_keys_reds_orig(folder_path)
make_lmdb_from_imgs(folder_path, lmdb_path, img_path_list, keys, multiprocessing_read=True)
def prepare_keys_reds_orig(folder_path):
"""Prepare image path list and keys for REDS_orig dataset (120 fps).
Args:
folder_path (str): Folder path.
Returns:
list[str]: Image path list.
list[str]: Key list.
"""
print('Reading image path list ...')
img_path_list = sorted(list(scandir(folder_path, suffix='png', recursive=True)))
keys = [v.split('.png')[0] for v in img_path_list] # example: 000/00000000
return img_path_list, keys
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument(
'--dataset',
type=str,
help=("Options: 'DIV2K', 'REDS', 'Vimeo90K', 'Vimeo90K_BD', 'DVD', 'GoPro',"
"'DAVIS', 'LDV', 'REDS_orig' "
'You may need to modify the corresponding configurations in codes.'))
args = parser.parse_args()
dataset = args.dataset.lower()
if dataset == 'div2k':
create_lmdb_for_div2k()
elif dataset == 'reds':
create_lmdb_for_reds()
elif dataset == 'vimeo90k':
create_lmdb_for_vimeo90k()
elif dataset == 'vimeo90k_bd':
create_lmdb_for_vimeo90k_bd()
elif dataset == 'dvd':
create_lmdb_for_dvd()
elif dataset == 'gopro':
create_lmdb_for_gopro()
elif dataset == 'davis':
create_lmdb_for_davis()
elif dataset == 'ldv':
create_lmdb_for_ldv()
elif dataset == 'reds_orig':
create_lmdb_for_reds_orig()
else:
raise ValueError('Wrong dataset.')
|