rahulved commited on
Commit ·
de1822e
1
Parent(s): a4b9d42
Changed network snapshot
Browse files- app.py +10 -5
- network-snapshot.pkl +1 -1
app.py
CHANGED
|
@@ -13,13 +13,18 @@ import os
|
|
| 13 |
|
| 14 |
network_pkl_a = 'stylegan3-r-afhqv2-512x512.pkl'
|
| 15 |
network_pkl_d = 'network-snapshot.pkl'
|
|
|
|
|
|
|
|
|
|
| 16 |
with open(network_pkl_d, 'rb') as f:
|
| 17 |
-
G_d = pickle.load(f)['G_ema'].cpu() # torch.nn.Module
|
| 18 |
|
| 19 |
with open(network_pkl_a, 'rb') as f:
|
| 20 |
-
G_a = pickle.load(f)['G_ema'].cpu() # torch.nn.Module
|
| 21 |
|
| 22 |
cl_text = os.getenv('SHOW_TEXT')
|
|
|
|
|
|
|
| 23 |
|
| 24 |
def gen_image(text):
|
| 25 |
text = text.strip().lower()
|
|
@@ -29,13 +34,13 @@ def gen_image(text):
|
|
| 29 |
return gen_image_helper(G_a)
|
| 30 |
|
| 31 |
def gen_image_helper(model):
|
| 32 |
-
z = torch.randn([1, model.z_dim]).cpu() # latent codes
|
| 33 |
c = None # class labels (not used in this example)
|
| 34 |
img = model(z, c)
|
| 35 |
img = (img.permute(0, 2, 3, 1) * 127.5 + 128).clamp(0, 255).to(torch.uint8)
|
| 36 |
#um = torch..nn.Upsample(scale_factor=2, mode='bilinear')
|
| 37 |
#img=um(img)
|
| 38 |
-
image=PIL.Image.fromarray(img[0].cpu().numpy(), 'RGB')
|
| 39 |
transform = transforms.Resize((image.height * 2, image.width * 2), interpolation=transforms.InterpolationMode.BILINEAR)
|
| 40 |
upscaled_image = transform(image)
|
| 41 |
return upscaled_image
|
|
@@ -46,7 +51,7 @@ demo = gr.Interface(
|
|
| 46 |
inputs=gr.Textbox(lines=2, placeholder="Prompt here..."),
|
| 47 |
outputs=gr.Image(type="pil"),
|
| 48 |
title="Text to Image Generator",
|
| 49 |
-
description="Enter text to generate an image
|
| 50 |
)
|
| 51 |
|
| 52 |
if __name__ == "__main__":
|
|
|
|
| 13 |
|
| 14 |
network_pkl_a = 'stylegan3-r-afhqv2-512x512.pkl'
|
| 15 |
network_pkl_d = 'network-snapshot.pkl'
|
| 16 |
+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 17 |
+
print("Device = ",device)
|
| 18 |
+
|
| 19 |
with open(network_pkl_d, 'rb') as f:
|
| 20 |
+
G_d = pickle.load(f)['G_ema'].to(device) #.cpu() # torch.nn.Module
|
| 21 |
|
| 22 |
with open(network_pkl_a, 'rb') as f:
|
| 23 |
+
G_a = pickle.load(f)['G_ema'].to(device) #.cpu() # torch.nn.Module
|
| 24 |
|
| 25 |
cl_text = os.getenv('SHOW_TEXT')
|
| 26 |
+
|
| 27 |
+
|
| 28 |
|
| 29 |
def gen_image(text):
|
| 30 |
text = text.strip().lower()
|
|
|
|
| 34 |
return gen_image_helper(G_a)
|
| 35 |
|
| 36 |
def gen_image_helper(model):
|
| 37 |
+
z = torch.randn([1, model.z_dim]).to(device) #.cpu() # latent codes
|
| 38 |
c = None # class labels (not used in this example)
|
| 39 |
img = model(z, c)
|
| 40 |
img = (img.permute(0, 2, 3, 1) * 127.5 + 128).clamp(0, 255).to(torch.uint8)
|
| 41 |
#um = torch..nn.Upsample(scale_factor=2, mode='bilinear')
|
| 42 |
#img=um(img)
|
| 43 |
+
image=PIL.Image.fromarray(img[0].cpu().numpy(), 'RGB') #.cpu()
|
| 44 |
transform = transforms.Resize((image.height * 2, image.width * 2), interpolation=transforms.InterpolationMode.BILINEAR)
|
| 45 |
upscaled_image = transform(image)
|
| 46 |
return upscaled_image
|
|
|
|
| 51 |
inputs=gr.Textbox(lines=2, placeholder="Prompt here..."),
|
| 52 |
outputs=gr.Image(type="pil"),
|
| 53 |
title="Text to Image Generator",
|
| 54 |
+
description="Enter any text to generate an image of an animal"
|
| 55 |
)
|
| 56 |
|
| 57 |
if __name__ == "__main__":
|
network-snapshot.pkl
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
size 266257697
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:bac188ab58ff51bc7f13ce98b811cde06eed9b428658f9ea99a472ef548b9662
|
| 3 |
size 266257697
|