from sys import argv, stderr from LRNN import gen_model def die(msg): print(msg, file=stderr) exit(1) os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' np.random.seed(0x5EED) if len(argv) < 4: die('Usage: {} [model path] [output path] [Gaussian noise variance]'.format(argv[0])) model = gen_model((None, None, 3), 'parallel') model.load_weights(argv[1]) datadir = './data/test-denoise' filenames = os.listdir(datadir) outputdir = argv[2] if not os.path.exists(outputdir): os.makedirs(outputdir) gauss_var = float(argv[3]) for filename in filenames: pathname = os.path.join(datadir, filename) img = skimage.io.imread(pathname) r, c = img.shape[:2]
if patch.ndim == 2: patch = skimage.color.gray2rgb(patch) images[n_sample] = patch filter_images[n_sample] = denoise_bilateral( patch, sigma_color=0.1, sigma_spatial=2, multichannel=True) n_sample = n_sample + 1 yield (images[:n_sample], filter_images[:n_sample]) os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' np.random.seed(0x5EED) model = gen_model((96, 96, 3), 'cascade') model.compile(optimizer='Adamax', loss=Keras.losses.mse) # Keras.utils.plot_model(model, to_file='model.png') batch_size = 32 patchsize = 96 n_epoch = 30 datadir = './data/train2014' pathnames = [os.path.join(datadir, f) for f in os.listdir(datadir)] n_sample = len(pathnames) steps_per_epoch = int((n_sample + batch_size - 1) / batch_size) steps_per_epoch = 500 n_epoch = 300000 valdir = './data/test2014'
from LRNN import gen_model def die(msg): print(msg, file=stderr) exit(1) os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' np.random.seed(0x5EED) if len(argv) < 3: die('Usage: {} [model path] [output path]'.format(argv[0])) model = gen_model((None, None, 3), 'cascade') model.load_weights(argv[1]) datadir = './data/test-denoise' filenames = os.listdir(datadir) outputdir = argv[2] if not os.path.exists(outputdir): os.makedirs(outputdir) for filename in filenames: pathname = os.path.join(datadir, filename) img = skimage.io.imread(pathname) r, c = img.shape[:2] if (r % 16 != 0) or (c % 16 != 0): print('Image dimension is not 16-divisible: ' + filename)
for _ in range(4): patch = gen_patch(img, patchsize) patch = skimage.util.img_as_float(patch) if patch.ndim == 2: patch = skimage.color.gray2rgb(patch) images[n_sample] = patch gauss_var = (0.01 + 0.09 * np.random.random())**2 noisy_images[n_sample] = random_noise(patch, var=gauss_var) n_sample = n_sample + 1 yield (noisy_images[:n_sample], images[:n_sample]) os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' np.random.seed(0x5EED) model = gen_model((96, 96, 3), 'parallel') model.compile(optimizer='Adamax', loss=Keras.losses.mse) # Keras.utils.plot_model(model, to_file='model.png') batch_size = 32 patchsize = 96 n_epoch = 30 datadir = './data/train2014' pathnames = [os.path.join(datadir, f) for f in os.listdir(datadir)] n_sample = len(pathnames) steps_per_epoch = int((n_sample + batch_size - 1) / batch_size) steps_per_epoch = 100 n_epoch = 300000 valdir = './data/test2014'
if len(argv) < 2: raise ValueError("Usage: {} [cascade | parallel] [start iter]".format(argv[0])) if len(argv) > 2: start_from_iter = int(argv[2]) if start_from_iter <= 0: raise ValueError("start_from_iter should be larger than 0") os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' np.random.seed(0x5EED) batch_size = 32 patchsize = 96 n_epoch = 30 model = gen_model((patchsize, patchsize, 4), argv[1]) model.compile(optimizer='Adamax', loss=Keras.losses.mse) # Keras.utils.plot_model(model, to_file='model.png') datadir = './data/train2014' pathnames = [os.path.join(datadir, f) for f in os.listdir(datadir)] n_sample = len(pathnames) steps_per_epoch=200 n_epoch=300000 valdir = './data/test2014' valnames = [os.path.join(valdir, f) for f in os.listdir(valdir)] outputdir = './model-color' if not os.path.exists(outputdir): os.makedirs(outputdir)
def degrade(img, p): r, c = img.shape[:2] mask = np.random.choice([True, False], size=(r, c), p=[1-p, p]) out = img.copy() out[mask] = 0 return out os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' np.random.seed(0x5EED) if len(argv) < 4: die('Usage: {} [model path] [output path] [cascade | parallel]'.format(argv[0])) model = gen_model((None, None, 4), argv[3]) model.load_weights(argv[1]) datadir = './data/test-denoise' filenames = os.listdir(datadir) outputdir = argv[2] if not os.path.exists(outputdir): os.makedirs(outputdir) for filename in filenames: pathname = os.path.join(datadir, filename) img = skimage.io.imread(pathname) r, c = img.shape[:2] if (r % 16 != 0) or (c % 16 != 0): print('Image dimension is not 16-divisible: ' + filename)