from keras.layers import Input, MaxPool2D, Deconvolution2D, Convolution2D, Add, Dense, AveragePooling2D, UpSampling2D, Reshape, Flatten, Subtract, Concatenate from keras.optimizers import Adam from keras.callbacks import LearningRateScheduler from keras import backend as k from keras.utils import multi_gpu_model import tensorflow as tf from keras.utils import plot_model from subpixel import Subpixel from PIL import Image import cv2 folder = '../Data' CHANNEL = 3 DATA = DATA(folder=folder) out_patch_size = DATA.patch_size inp_patch_size = int(out_patch_size / 2) DATA.load_data(folder=folder) print("Training data Y:", DATA.training_patches_Y.shape) print("Training data X:", DATA.training_patches_2x.shape) print(" Max data: ", DATA.training_patches_2x.max()) def PSNRLossnp(y_true, y_pred): return 10 * np.log(255 * 2 / (np.mean(np.square(y_pred - y_true)))) def SSIM(y_true, y_pred):
from keras.layers import Input, MaxPool2D, Deconvolution2D, Convolution2D, Add, Dense, AveragePooling2D, UpSampling2D, Reshape, Flatten, Subtract, Concatenate, Lambda from keras.optimizers import Adam from keras.callbacks import LearningRateScheduler from keras import backend as k from keras.applications import vgg16 from keras.utils import multi_gpu_model from keras.applications.imagenet_utils import preprocess_input import tensorflow as tf from keras.utils import plot_model from subpixel import Subpixel from PIL import Image import cv2 CHANNEL = 3 DATA = DATA(folder=folder, patch_size=int(scale * 32)) out_patch_size = DATA.patch_size inp_patch_size = int(out_patch_size / scale) if not test_only: DATA.load_data(folder=folder) if scale == 2: x = DATA.training_patches_2x elif scale == 4: x = DATA.training_patches_4x elif scale == 8: x = DATA.training_patches_8x def PSNRLossnp(y_true, y_pred): return 10 * np.log(255 * 2 / (np.mean(np.square(y_pred - y_true))))
from keras.optimizers import Adam from keras.callbacks import LearningRateScheduler from keras import backend as k from keras.utils import multi_gpu_model import tensorflow as tf from keras.utils import plot_model from subpixel import Subpixel from PIL import Image import cv2 folder = '../BSDS200 processed' CHANNEL = 3 DATA = DATA(folder = folder) out_patch_size = DATA.patch_size inp_patch_size = int(out_patch_size/ 2) DATA.load_data(folder=folder) print("Training data Y:" , DATA.training_patches_Y.shape) print("Training data X:" , DATA.training_patches_2x.shape) def PSNRLossnp(y_true,y_pred): return 10* np.log(255*2 / np.mean(np.square(y_pred - y_true))) def SSIM( y_true,y_pred): u_true = k.mean(y_true) u_pred = k.mean(y_pred)
# if j > epochs: # break def predict(self, p): p = p / 255 g = self.get_model().predict(np.array(p)) g[0] = np.array(g[0] * 255, np.uint8) g[1] = np.array(g[1] * 255, np.uint8) g[2] = np.array(g[2] * 255, np.uint8) return g if __name__ == '__main__': CHANNEL = 3 out_patch_size = 128 inp_patch_size = 16 DATA = DATA(folder=folder, patch_size=out_patch_size) if not test_only: DATA.load_data(folder=folder) x = DATA.training_patches_8x x2 = DATA.training_patches_4x x4 = DATA.training_patches_2x x8 = DATA.training_patches_Y net = SRResnet(lr=learning_rate, chk=chk, test=test_only, content_lambda=content_lambda, mse_lambda=mse_lambda, adv_lambda=adv_lambda, patch_size=inp_patch_size, visualize=not test_only)