Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import torch
|
2 |
+
import matplotlib.pyplot as plt
|
3 |
+
import torchvision
|
4 |
+
import gradio as gr
|
5 |
+
use_gpu = True if torch.cuda.is_available() else False
|
6 |
+
|
7 |
+
model = torch.hub.load('facebookresearch/pytorch_GAN_zoo:hub',
|
8 |
+
'PGAN', model_name='celebAHQ-512',
|
9 |
+
pretrained=True, useGPU=use_gpu)
|
10 |
+
|
11 |
+
|
12 |
+
|
13 |
+
def pggan(num_images):
|
14 |
+
noise, _ = model.buildNoiseData(int(num_images))
|
15 |
+
with torch.no_grad():
|
16 |
+
generated_images = model.test(noise)
|
17 |
+
|
18 |
+
grid = torchvision.utils.make_grid(generated_images.clamp(min=-1, max=1), scale_each=True, normalize=True)
|
19 |
+
plt.axis("off")
|
20 |
+
plt.imshow(grid.permute(1, 2, 0).cpu().numpy())
|
21 |
+
return plt
|
22 |
+
|
23 |
+
|
24 |
+
inputs = gr.inputs.Number(label="number of images")
|
25 |
+
outputs = gr.outputs.Image(label="Output Image")
|
26 |
+
|
27 |
+
title = "Progressive Growing of GANs"
|
28 |
+
description = "Gradio demo for Progressive Growing of GANs (PGAN). To use it, simply add the number of images to generate or click on the examples. Read more below."
|
29 |
+
article = "<p style='text-align: center'><a href='https://arxiv.org/abs/1710.10196'>Progressive Growing of GANs for Improved Quality, Stability, and Variation</a> | <a href='https://github.com/facebookresearch/pytorch_GAN_zoo/blob/master/models/progressive_gan.py'>Github Repo</a></p>"
|
30 |
+
examples = [
|
31 |
+
[1],
|
32 |
+
[2],
|
33 |
+
[3],
|
34 |
+
[4]
|
35 |
+
]
|
36 |
+
|
37 |
+
|
38 |
+
gr.Interface(pggan, inputs, outputs, title=title, description=description, article=article, analytics_enabled=False, examples=examples).launch(debug=True)
|