yupikopi commited on
Commit
dcf8cc9
·
1 Parent(s): 90ddf19

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -32
app.py CHANGED
@@ -1,46 +1,28 @@
1
  import keras.backend as K
2
  import gradio as gr
3
  import numpy as np
 
 
 
 
4
 
5
  def psnr(y_true, y_pred):
6
  return -10*K.log(K.mean(K.flatten((y_true - y_pred))**2)) / np.log(10)
7
 
 
 
 
8
 
9
- from keras.models import load_model
10
  model = load_model("./MyNet.h5", custom_objects={'psnr': psnr, 'val_psnr': psnr})
11
 
12
- # ラップする関数
13
- #def sepia(input_img):
14
- # sepia_img = np.asarray(input_img)
15
- # sepia_img = sepia_img.astype('float32')
16
- # sepia_img = sepia_img / 255.0
17
- # sepia_img = model.predict(sepia_img)
18
- # return sepia_img
19
-
20
  def sepia(inp):
21
- #inp = inp.reshape((-1, 256, 256, 3))
22
- inpu = np.array(inp)
23
- #inp = inp.astype('float32')
24
- inpu = inpu / 255.0
25
- sepia_img = model.predict(inpu)
26
- #sepia_img = sepia_img.reshape(256, 256)
27
  sepia_img = sepia_img*255
 
28
  return sepia_img
29
 
30
-
31
-
32
- # シンプルなUIを作成
33
- demo = gr.Interface(fn=sepia, inputs=gr.inputs.Image(256,256),outputs="image").launch()
34
-
35
-
36
- #image = gr.inputs.Image(shape=(256,256))
37
- #image = np.asarray(image)
38
- #image = image.astype('float32')
39
- #image = image / 255.0
40
- #decoded_imgs = model.predict(image)
41
-
42
- #decoded_imgs.reshape(256,256,3)
43
- #prediction=model.predict(img_4d)[0]
44
-
45
-
46
- #gr.Interface(inputs=image, outputs=decoded_imgs,interpretation='default').launch(debug='True')
 
1
  import keras.backend as K
2
  import gradio as gr
3
  import numpy as np
4
+ import random
5
+ from keras.models import load_model
6
+ import cv2
7
+
8
 
9
  def psnr(y_true, y_pred):
10
  return -10*K.log(K.mean(K.flatten((y_true - y_pred))**2)) / np.log(10)
11
 
12
+ random.seed(0) # 乱数の種を0にして,乱数を一様にする.
13
+ img_width = 256 # 画像の横画素数
14
+ img_height = 256 # 画像の縦画素数
15
 
 
16
  model = load_model("./MyNet.h5", custom_objects={'psnr': psnr, 'val_psnr': psnr})
17
 
 
 
 
 
 
 
 
 
18
  def sepia(inp):
19
+ sepia_img = cv2.imread(inp)
20
+ sepia_img = np.asarray(sepia_img)
21
+ sepia_img = sepia_img.astype('float32')
22
+ sepia_img = sepia_img / 255.0
23
+ sepia_img = model.predict(sepia_img)
 
24
  sepia_img = sepia_img*255
25
+ sepia_img = sepia_img.reshape(img_height, img_width, 3)
26
  return sepia_img
27
 
28
+ demo = gr.Interface(fn=sepia, inputs=gr.inputs.Image(256,256),outputs="image").launch()