bad commited on
Commit
d867d78
1 Parent(s): 95a2725

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -0
app.py CHANGED
@@ -1,6 +1,7 @@
1
  import cv2
2
  import numpy as np
3
  import paddle
 
4
  from Generater import Generater
5
  import gradio as gr
6
 
@@ -16,10 +17,16 @@ def style_transfer(content_img,style_img):
16
  g_input = content_img.astype('float32') / 127.5 - 1 # 归一化
17
  g_input = g_input[np.newaxis, ...].transpose(0, 3, 1, 2) # NHWC -> NCHW
18
  g_input = paddle.to_tensor(g_input) # numpy -> tensor
 
 
 
19
 
20
  g_input_s = style_img.astype('float32') / 127.5 - 1 # 归一化
21
  g_input_s = g_input_s[np.newaxis, ...].transpose(0, 3, 1, 2) # NHWC -> NCHW
22
  g_input_s = paddle.to_tensor(g_input_s) # numpy -> tensor
 
 
 
23
 
24
  i = paddle.to_tensor([1.])
25
  g_output = generator(g_input,g_input_s,i)
 
1
  import cv2
2
  import numpy as np
3
  import paddle
4
+ import paddle.nn.functional as F
5
  from Generater import Generater
6
  import gradio as gr
7
 
 
17
  g_input = content_img.astype('float32') / 127.5 - 1 # 归一化
18
  g_input = g_input[np.newaxis, ...].transpose(0, 3, 1, 2) # NHWC -> NCHW
19
  g_input = paddle.to_tensor(g_input) # numpy -> tensor
20
+ h,w = g_input.shape[-2:]
21
+ p = max([h,w])
22
+ g_input = F.interpolate(g_input,scale_factor=(256/p))
23
 
24
  g_input_s = style_img.astype('float32') / 127.5 - 1 # 归一化
25
  g_input_s = g_input_s[np.newaxis, ...].transpose(0, 3, 1, 2) # NHWC -> NCHW
26
  g_input_s = paddle.to_tensor(g_input_s) # numpy -> tensor
27
+ h,w = g_input_s.shape[-2:]
28
+ p = max([h,w])
29
+ g_input_s = F.interpolate(g_input_s,scale_factor=(256/p))
30
 
31
  i = paddle.to_tensor([1.])
32
  g_output = generator(g_input,g_input_s,i)