File size: 933 Bytes
fdc5e11 90b13c8 eee0150 dcf8cc9 62062d9 dcf8cc9 eee0150 fdc5e11 dcf8cc9 6b600ef 4ac0de6 fdc5e11 e6f39bd cc5377e dcf8cc9 90ddf19 62062d9 fc0fac4 318c3ac cc5377e |
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 |
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) # 乱数の種を0にして,乱数を一様にする.
img_width = 256 # 画像の横画素数
img_height = 256 # 画像の縦画素数
model = load_model("./MyNet.h5", custom_objects={'psnr': psnr, 'val_psnr': psnr})
def sepia(inp):
#sepia_img = cv2.imread(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() |