675
« on: 2019-01-12 19:04:15 »
Yes it's with basicSR.
Some usefull informations
1)don't install nor use lmdb, it's a pain to install with python (on my windows at least) and it takes lots of ressources (and even in my classic no ssd drive, there's no benefits)
2)edit and use the extract_subimgs_single.py script for HQ set generation from your HQ sources
3)generate the LQ set with the imagemagik command : "convert.exe -filter box -resize 25%% #input# #output#"
4)Be sure all your HQ and LQ picture use the same color depth and setting (for that i use the imagemagik command : "convert.exe #inptut# -define png:format=png24 #inpt#" , it ensure that all the png are compressed the same way and it's auto overwriting the source).
5)Make a set of verification of about 10% of the total pictures (for LQ anb HQ)
6)edit the train_ESRGAN.json with your folders and to avoid a out of memory error :
, "n_workers": 4
, "batch_size": 8
I also set a "save_checkpoint_freq": 5000 to be able to stop/resume the training easily
for reference here's my edited python files (all the other files are as in the git without modification and i use python 3.6 and not anaconda):
extract_subimgs_single.py
import os
import os.path
import sys
from multiprocessing import Pool
import numpy as np
import cv2
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from utils.progress_bar import ProgressBar
def main():
"""A multi-thread tool to crop sub imags."""
input_folder = "E:/ESRGANModel/ff7sources/"
save_folder = "E:/ESRGANModel/dataset/ff7hq/"
n_thread = 20
crop_sz = 480
step = 240
thres_sz = 48
compression_level = 0 # 3 is the default value in cv2
# CV_IMWRITE_PNG_COMPRESSION from 0 to 9. A higher value means a smaller size and longer
# compression time. If read raw images during training, use 0 for faster IO speed.
if not os.path.exists(save_folder):
os.makedirs(save_folder)
print('mkdir [{:s}] ...'.format(save_folder))
else:
print('Folder [{:s}] already exists. Exit...'.format(save_folder))
sys.exit(1)
img_list = []
for root, _, file_list in sorted(os.walk(input_folder)):
path = [os.path.join(root, x) for x in file_list] # assume only images in the input_folder
img_list.extend(path)
def update(arg):
pbar.update(arg)
pbar = ProgressBar(len(img_list))
pool = Pool(n_thread)
for path in img_list:
pool.apply_async(worker,
args=(path, save_folder, crop_sz, step, thres_sz, compression_level),
callback=update)
pool.close()
pool.join()
print('All subprocesses done.')
def worker(path, save_folder, crop_sz, step, thres_sz, compression_level):
img_name = os.path.basename(path)
img = cv2.imread(path, cv2.IMREAD_UNCHANGED)
n_channels = len(img.shape)
if n_channels == 2:
h, w = img.shape
elif n_channels == 3:
h, w, c = img.shape
else:
raise ValueError('Wrong image shape - {}'.format(n_channels))
h_space = np.arange(0, h - crop_sz + 1, step)
if h - (h_space[-1] + crop_sz) > thres_sz:
h_space = np.append(h_space, h - crop_sz)
w_space = np.arange(0, w - crop_sz + 1, step)
if w - (w_space[-1] + crop_sz) > thres_sz:
w_space = np.append(w_space, w - crop_sz)
index = 0
for x in h_space:
for y in w_space:
index += 1
if n_channels == 2:
crop_img = img[x:x + crop_sz, y:y + crop_sz]
else:
crop_img = img[x:x + crop_sz, y:y + crop_sz, :]
crop_img = np.ascontiguousarray(crop_img)
# var = np.var(crop_img / 255)
# if var > 0.008:
# print(img_name, index_str, var)
cv2.imwrite(
os.path.join(save_folder, img_name.replace('.png', '_s{:03d}.png'.format(index))),
crop_img, [cv2.IMWRITE_PNG_COMPRESSION, compression_level])
return 'Processing {:s} ...'.format(img_name)
if __name__ == '__main__':
main()
train_ESRGAN.json
{
"name": "RRDB_ESRGAN_x4_FF7" // please remove "debug_" during training
, "use_tb_logger": true
, "model":"srragan"
, "scale": 4
, "gpu_ids": [0]
, "datasets": {
"train": {
"name": "FF7"
, "mode": "LRHR"
, "dataroot_HR": "E:/ESRGANModel/Dataset/ff7hq"
, "dataroot_LR": "E:/ESRGANModel/Dataset/ff7lq"
, "subset_file": null
, "use_shuffle": true
, "n_workers": 4
, "batch_size": 8
, "HR_size": 128
, "use_flip": true
, "use_rot": true
}
, "val": {
"name": "val_set14_part"
, "mode": "LRHR"
, "dataroot_HR": "E:/ESRGANModel/Dataset/ff7hqval"
, "dataroot_LR": "E:/ESRGANModel/Dataset/ff7lqval"
}
}
, "path": {
"root": "E:/ESRGANModel/InWorks"
// , "resume_state": "E:/ESRGANModel/InWorks/experiments/RRDB_ESRGAN_x4_FF7/training_state/15000.state" //<=edit and uncomment to resume training
, "pretrain_model_G": "../experiments/pretrained_models/RRDB_PSNR_x4.pth"
}
, "network_G": {
"which_model_G": "RRDB_net" // RRDB_net | sr_resnet
, "norm_type": null
, "mode": "CNA"
, "nf": 64
, "nb": 23
, "in_nc": 3
, "out_nc": 3
, "gc": 32
, "group": 1
}
, "network_D": {
"which_model_D": "discriminator_vgg_128"
, "norm_type": "batch"
, "act_type": "leakyrelu"
, "mode": "CNA"
, "nf": 64
, "in_nc": 3
}
, "train": {
"lr_G": 1e-4
, "weight_decay_G": 0
, "beta1_G": 0.9
, "lr_D": 1e-4
, "weight_decay_D": 0
, "beta1_D": 0.9
, "lr_scheme": "MultiStepLR"
, "lr_steps": [50000, 100000, 200000, 300000]
, "lr_gamma": 0.5
, "pixel_criterion": "l1"
, "pixel_weight": 1e-2
, "feature_criterion": "l1"
, "feature_weight": 1
, "gan_type": "vanilla"
, "gan_weight": 5e-3
//for wgan-gp
// , "D_update_ratio": 1
// , "D_init_iters": 0
// , "gp_weigth": 10
, "manual_seed": 0
, "niter": 5e5
, "val_freq": 5e3
}
, "logger": {
"print_freq": 200
, "save_checkpoint_freq": 5000 //5e3
}
}