秋山翔 commited on
Commit
bc8701f
1 Parent(s): adf5cfd

TEST: render debug with image

Browse files
Files changed (1) hide show
  1. app.py +32 -36
app.py CHANGED
@@ -16,42 +16,40 @@ STYLE = "shinkai_makoto"
16
  MODEL_PATH = "models"
17
  COLOUR_MODEL = "RGB"
18
 
19
- # model = Transformer()
20
- # model.load_state_dict(torch.load(os.path.join(MODEL_PATH, f"{STYLE}.pth")))
21
- # model.eval()
22
 
23
- # disable_gpu = torch.cuda.is_available()
24
 
25
 
26
  def inference(img):
27
- # # load image
28
- # input_image = img.convert(COLOUR_MODEL)
29
- # input_image = np.asarray(input_image)
30
- # # RGB -> BGR
31
- # input_image = input_image[:, :, [2, 1, 0]]
32
- # input_image = transforms.ToTensor()(input_image).unsqueeze(0)
33
- # # preprocess, (-1, 1)
34
- # input_image = -1 + 2 * input_image
35
-
36
- # if disable_gpu:
37
- # input_image = Variable(input_image).float()
38
- # else:
39
- # input_image = Variable(input_image).cuda()
40
-
41
- # # forward
42
- # output_image = model(input_image)
43
- # output_image = output_image[0]
44
- # # BGR -> RGB
45
- # output_image = output_image[[2, 1, 0], :, :]
46
- # output_image = output_image.data.cpu().float() * 0.5 + 0.5
47
-
48
- # return output_image
49
-
50
- return ""
51
-
52
-
53
- title = "AnimeBackgroundGAN"
54
- description = "CartoonGAN from [Chen et.al](http://openaccess.thecvf.com/content_cvpr_2018/CameraReady/2205.pdf) based on [Yijunmaverick's implementation](https://github.com/Yijunmaverick/CartoonGAN-Test-Pytorch-Torch)"
55
  article = "<p style='text-align: center'><a href='https://github.com/venture-anime/cartoongan-pytorch' target='_blank'>Github Repo</a></p> <center><img src='https://visitor-badge.glitch.me/badge?page_id=akiyamasho' alt='visitor badge'></center></p>"
56
 
57
  examples = [
@@ -62,10 +60,8 @@ examples = [
62
 
63
  gr.Interface(
64
  fn=inference,
65
- inputs=gr.inputs.Textbox(
66
- lines=1, placeholder=None, default="", label=None
67
- ),
68
- outputs=gr.outputs.Textbox(type="auto", label=None),
69
  title=title,
70
  description=description,
71
  article=None,
 
16
  MODEL_PATH = "models"
17
  COLOUR_MODEL = "RGB"
18
 
19
+ model = Transformer()
20
+ model.load_state_dict(torch.load(os.path.join(MODEL_PATH, f"{STYLE}.pth")))
21
+ model.eval()
22
 
23
+ disable_gpu = torch.cuda.is_available()
24
 
25
 
26
  def inference(img):
27
+ # load image
28
+ input_image = img.convert(COLOUR_MODEL)
29
+ input_image = np.asarray(input_image)
30
+ # RGB -> BGR
31
+ input_image = input_image[:, :, [2, 1, 0]]
32
+ input_image = transforms.ToTensor()(input_image).unsqueeze(0)
33
+ # preprocess, (-1, 1)
34
+ input_image = -1 + 2 * input_image
35
+
36
+ if disable_gpu:
37
+ input_image = Variable(input_image).float()
38
+ else:
39
+ input_image = Variable(input_image).cuda()
40
+
41
+ # forward
42
+ output_image = model(input_image)
43
+ output_image = output_image[0]
44
+ # BGR -> RGB
45
+ output_image = output_image[[2, 1, 0], :, :]
46
+ output_image = output_image.data.cpu().float() * 0.5 + 0.5
47
+
48
+ return output_image
49
+
50
+
51
+ title = "Anime Background GAN"
52
+ description = "<a href='http://openaccess.thecvf.com/content_cvpr_2018/CameraReady/2205.pdf' target='_blank'>CartoonGAN from Chen et.al</a> based on <a href='https://github.com/Yijunmaverick/CartoonGAN-Test-Pytorch-Torch' target='_blank'>Yijunmaverick's implementation</a>."
 
 
53
  article = "<p style='text-align: center'><a href='https://github.com/venture-anime/cartoongan-pytorch' target='_blank'>Github Repo</a></p> <center><img src='https://visitor-badge.glitch.me/badge?page_id=akiyamasho' alt='visitor badge'></center></p>"
54
 
55
  examples = [
 
60
 
61
  gr.Interface(
62
  fn=inference,
63
+ inputs=[gr.inputs.Image(type="pil")],
64
+ outputs=gr.outputs.Image(type="pil"),
 
 
65
  title=title,
66
  description=description,
67
  article=None,