Spaces:
Runtime error
Runtime error
version 0.1 commit
Browse files- __pycache__/image_generator.cpython-38.pyc +0 -0
- app.py +6 -5
- image_generator.py +33 -20
- out/seed0054.png +0 -0
__pycache__/image_generator.cpython-38.pyc
CHANGED
Binary files a/__pycache__/image_generator.cpython-38.pyc and b/__pycache__/image_generator.cpython-38.pyc differ
|
|
app.py
CHANGED
@@ -10,13 +10,14 @@ from image_generator import generate_images
|
|
10 |
|
11 |
def image_generation(model, number_of_images=1):
|
12 |
G = MyGenerator.from_pretrained("Cropinky/projected_gan_impressionism")
|
13 |
-
generate_images()
|
14 |
-
return f"generating {number_of_images} images from {model}"
|
|
|
15 |
if __name__ == "__main__":
|
16 |
|
17 |
-
inputs = gr.inputs.Radio(["Abstract Expressionism", "Impressionism", "Cubism", "
|
18 |
-
|
19 |
-
outputs = "text"
|
20 |
title = "Projected GAN for painting generation"
|
21 |
description = "Choose your artistic direction "
|
22 |
article = "<p style='text-align: center'><a href='https://github.com/autonomousvision/projected_gan'>Official projected GAN github repo + paper</a></p>"
|
|
|
10 |
|
11 |
def image_generation(model, number_of_images=1):
|
12 |
G = MyGenerator.from_pretrained("Cropinky/projected_gan_impressionism")
|
13 |
+
img = generate_images(model)
|
14 |
+
#return f"generating {number_of_images} images from {model}"
|
15 |
+
return img
|
16 |
if __name__ == "__main__":
|
17 |
|
18 |
+
inputs = gr.inputs.Radio(["Abstract Expressionism", "Impressionism", "Cubism", "Pop Art", "Color Field", "Hana Hanak houses"])
|
19 |
+
outputs = gr.outputs.Image(label="Generated Image", type="pil")
|
20 |
+
#outputs = "text"
|
21 |
title = "Projected GAN for painting generation"
|
22 |
description = "Choose your artistic direction "
|
23 |
article = "<p style='text-align: center'><a href='https://github.com/autonomousvision/projected_gan'>Official projected GAN github repo + paper</a></p>"
|
image_generator.py
CHANGED
@@ -8,15 +8,16 @@
|
|
8 |
|
9 |
"""Generate images using pretrained network pickle."""
|
10 |
|
|
|
11 |
import os
|
|
|
12 |
import re
|
13 |
from typing import List, Optional, Tuple, Union
|
14 |
-
import click
|
15 |
import numpy as np
|
16 |
import PIL.Image
|
17 |
import torch
|
18 |
from networks_fastgan import MyGenerator
|
19 |
-
|
20 |
#----------------------------------------------------------------------------
|
21 |
|
22 |
def parse_range(s: Union[str, List]) -> List[int]:
|
@@ -65,22 +66,14 @@ def make_transform(translate: Tuple[float,float], angle: float):
|
|
65 |
|
66 |
#----------------------------------------------------------------------------
|
67 |
|
68 |
-
@click.command()
|
69 |
-
@click.option('--seeds', type=parse_range, help='List of random seeds (e.g., \'0,1,4-6\')', default="10-11", required=True)
|
70 |
-
@click.option('--trunc', 'truncation_psi', type=float, help='Truncation psi', default=1, show_default=True)
|
71 |
-
@click.option('--class', 'class_idx', type=int, help='Class label (unconditional if not specified)')
|
72 |
-
@click.option('--noise-mode', help='Noise mode', type=click.Choice(['const', 'random', 'none']), default='const', show_default=True)
|
73 |
-
@click.option('--translate', help='Translate XY-coordinate (e.g. \'0.3,1\')', type=parse_vec2, default='0,0', show_default=True, metavar='VEC2')
|
74 |
-
@click.option('--rotate', help='Rotation angle in degrees', type=float, default=0, show_default=True, metavar='ANGLE')
|
75 |
-
@click.option('--outdir', help='Where to save the output images', type=str, default="out", required=True, metavar='DIR')
|
76 |
def generate_images(
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
):
|
85 |
"""Generate images using pretrained network pickle.
|
86 |
|
@@ -96,13 +89,30 @@ def generate_images(
|
|
96 |
python gen_images.py --outdir=out --trunc=0.7 --seeds=600-605 \\
|
97 |
--network=https://api.ngc.nvidia.com/v2/models/nvidia/research/stylegan3/versions/1/files/stylegan3-t-metfacesu-1024x1024.pkl
|
98 |
"""
|
99 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
100 |
device = torch.device('cuda') if torch.cuda.is_available() else torch.device('cpu')
|
101 |
-
G = MyGenerator.from_pretrained(
|
102 |
os.makedirs(outdir, exist_ok=True)
|
103 |
|
104 |
# Labels.
|
105 |
label = torch.zeros([1, G.c_dim], device=device)
|
|
|
106 |
if G.c_dim != 0:
|
107 |
if class_idx is None:
|
108 |
raise click.ClickException('Must specify class label with --class when using a conditional network')
|
@@ -110,6 +120,7 @@ def generate_images(
|
|
110 |
else:
|
111 |
if class_idx is not None:
|
112 |
print ('warn: --class=lbl ignored when running on an unconditional network')
|
|
|
113 |
|
114 |
# Generate images.
|
115 |
for seed_idx, seed in enumerate(seeds):
|
@@ -125,7 +136,9 @@ def generate_images(
|
|
125 |
|
126 |
img = G(z, label, truncation_psi=truncation_psi, noise_mode=noise_mode)
|
127 |
img = (img.permute(0, 2, 3, 1) * 127.5 + 128).clamp(0, 255).to(torch.uint8)
|
128 |
-
PIL.Image.fromarray(img[0].cpu().numpy(), 'RGB')
|
|
|
|
|
129 |
|
130 |
|
131 |
#----------------------------------------------------------------------------
|
|
|
8 |
|
9 |
"""Generate images using pretrained network pickle."""
|
10 |
|
11 |
+
from ast import parse
|
12 |
import os
|
13 |
+
from pyexpat import model
|
14 |
import re
|
15 |
from typing import List, Optional, Tuple, Union
|
|
|
16 |
import numpy as np
|
17 |
import PIL.Image
|
18 |
import torch
|
19 |
from networks_fastgan import MyGenerator
|
20 |
+
import random
|
21 |
#----------------------------------------------------------------------------
|
22 |
|
23 |
def parse_range(s: Union[str, List]) -> List[int]:
|
|
|
66 |
|
67 |
#----------------------------------------------------------------------------
|
68 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
69 |
def generate_images(
|
70 |
+
model_path,
|
71 |
+
seeds = "10-12",
|
72 |
+
truncation_psi = 1.0,
|
73 |
+
noise_mode = "const",
|
74 |
+
outdir = "out",
|
75 |
+
translate = "0,0",
|
76 |
+
rotate = 0,
|
77 |
):
|
78 |
"""Generate images using pretrained network pickle.
|
79 |
|
|
|
89 |
python gen_images.py --outdir=out --trunc=0.7 --seeds=600-605 \\
|
90 |
--network=https://api.ngc.nvidia.com/v2/models/nvidia/research/stylegan3/versions/1/files/stylegan3-t-metfacesu-1024x1024.pkl
|
91 |
"""
|
92 |
+
model_owner = "Cropinky"
|
93 |
+
#inputs = gr.inputs.Radio(["Abstract Expressionism", "Impressionism", "Cubism", "Minimalism", "Pop Art", "Color Field", "Hana Hanak houses"])
|
94 |
+
model_path_dict = {
|
95 |
+
'Impressionism' : 'projected_gan_impressionism',
|
96 |
+
'Cubism' : 'projected_gan_cubism',
|
97 |
+
'Abstract Expressionism' : 'projected_gan_abstract_expressionism',
|
98 |
+
'Pop Art' : 'projected_gan_pop_art',
|
99 |
+
'Minimalism' : 'projected_gan_minimalism',
|
100 |
+
'Color Field' : 'projected_gan_color_field',
|
101 |
+
'Hana Hanak houses' : 'projected_gana_hana'
|
102 |
+
}
|
103 |
+
|
104 |
+
model_path = model_owner + "/" + model_path_dict[model_path]
|
105 |
+
print(model_path)
|
106 |
+
seeds = parse_range(seeds)
|
107 |
+
print(seeds)
|
108 |
+
seeds=[random.randint(1,99)]
|
109 |
device = torch.device('cuda') if torch.cuda.is_available() else torch.device('cpu')
|
110 |
+
G = MyGenerator.from_pretrained(model_path)
|
111 |
os.makedirs(outdir, exist_ok=True)
|
112 |
|
113 |
# Labels.
|
114 |
label = torch.zeros([1, G.c_dim], device=device)
|
115 |
+
"""
|
116 |
if G.c_dim != 0:
|
117 |
if class_idx is None:
|
118 |
raise click.ClickException('Must specify class label with --class when using a conditional network')
|
|
|
120 |
else:
|
121 |
if class_idx is not None:
|
122 |
print ('warn: --class=lbl ignored when running on an unconditional network')
|
123 |
+
"""
|
124 |
|
125 |
# Generate images.
|
126 |
for seed_idx, seed in enumerate(seeds):
|
|
|
136 |
|
137 |
img = G(z, label, truncation_psi=truncation_psi, noise_mode=noise_mode)
|
138 |
img = (img.permute(0, 2, 3, 1) * 127.5 + 128).clamp(0, 255).to(torch.uint8)
|
139 |
+
img = PIL.Image.fromarray(img[0].cpu().numpy(), 'RGB')
|
140 |
+
#PIL.Image.fromarray(img[0].cpu().numpy(), 'RGB').save(f'{outdir}/seed{seed:04d}.png')
|
141 |
+
return img
|
142 |
|
143 |
|
144 |
#----------------------------------------------------------------------------
|
out/seed0054.png
ADDED
![]() |