|
import keras.backend as K |
|
import gradio as gr |
|
import numpy as np |
|
import random |
|
from keras.models import load_model |
|
import cv2 |
|
from PIL import Image |
|
|
|
|
|
|
|
def psnr(y_true, y_pred): |
|
return -10*K.log(K.mean(K.flatten((y_true - y_pred))**2)) / np.log(10) |
|
|
|
random.seed(0) |
|
img_width = 256 |
|
img_height = 256 |
|
|
|
model = load_model("./MyNet.h5", custom_objects={'psnr': psnr, 'val_psnr': psnr}) |
|
|
|
def sepia(inp): |
|
|
|
sepia_img = np.asarray(inp) |
|
sepia_img = sepia_img.astype('float32') |
|
sepia_img = sepia_img / 255.0 |
|
sepia_img = model.predict(sepia_img) |
|
sepia_img = sepia_img*255 |
|
sepia_img = Image.fromarray(sepia_img) |
|
sepia_img = sepia_img.reshape(img_height, img_width, 3) |
|
return sepia_img |
|
|
|
demo = gr.Interface(fn=sepia, inputs=gr.inputs.Image(256,256),outputs="image").launch() |