Spaces:
Runtime error
Runtime error
implemented generating 16 images instead of 1
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- __pycache__/blocks.cpython-38.pyc +0 -0
- __pycache__/image_generator.cpython-38.pyc +0 -0
- __pycache__/networks_fastgan.cpython-38.pyc +0 -0
- image_generator.py +23 -21
- out/seed0008.png +0 -0
- out/seed0009.png +0 -0
- out/seed0010.png +0 -0
- out/seed0011.png +0 -0
- out/seed0012.png +0 -0
- out/seed0013.png +0 -0
- out/seed0014.png +0 -0
- out/seed0015.png +0 -0
- out/seed0016.png +0 -0
- out/seed0017.png +0 -0
- out/seed0018.png +0 -0
- out/seed0019.png +0 -0
- out/seed0020.png +0 -0
- out/seed0021.png +0 -0
- out/seed0022.png +0 -0
- out/seed0023.png +0 -0
- out/seed0024.png +0 -0
- out/seed0027.png +0 -0
- out/seed0028.png +0 -0
- out/seed0029.png +0 -0
- out/seed0030.png +0 -0
- out/seed0031.png +0 -0
- out/seed0032.png +0 -0
- out/seed0033.png +0 -0
- out/seed0034.png +0 -0
- out/seed0035.png +0 -0
- out/seed0036.png +0 -0
- out/seed0037.png +0 -0
- out/seed0038.png +0 -0
- out/seed0039.png +0 -0
- out/seed0040.png +0 -0
- out/seed0041.png +0 -0
- out/seed0042.png +0 -0
- out/seed0043.png +0 -0
- out/seed0046.png +0 -0
- out/seed0047.png +0 -0
- out/seed0048.png +0 -0
- out/seed0049.png +0 -0
- out/seed0050.png +0 -0
- out/seed0051.png +0 -0
- out/seed0052.png +0 -0
- out/seed0053.png +0 -0
- out/seed0054.png +0 -0
- out/seed0055.png +0 -0
- out/seed0056.png +0 -0
- out/seed0057.png +0 -0
__pycache__/blocks.cpython-38.pyc
CHANGED
|
Binary files a/__pycache__/blocks.cpython-38.pyc and b/__pycache__/blocks.cpython-38.pyc differ
|
|
|
__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
|
|
|
__pycache__/networks_fastgan.cpython-38.pyc
CHANGED
|
Binary files a/__pycache__/networks_fastgan.cpython-38.pyc and b/__pycache__/networks_fastgan.cpython-38.pyc differ
|
|
|
image_generator.py
CHANGED
|
@@ -18,6 +18,7 @@ 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]:
|
|
@@ -74,21 +75,8 @@ def generate_images(
|
|
| 74 |
outdir = "out",
|
| 75 |
translate = "0,0",
|
| 76 |
rotate = 0,
|
|
|
|
| 77 |
):
|
| 78 |
-
"""Generate images using pretrained network pickle.
|
| 79 |
-
|
| 80 |
-
Examples:
|
| 81 |
-
|
| 82 |
-
\b
|
| 83 |
-
# Generate an image using pre-trained AFHQv2 model ("Ours" in Figure 1, left).
|
| 84 |
-
python gen_images.py --outdir=out --trunc=1 --seeds=2 \\
|
| 85 |
-
--network=https://api.ngc.nvidia.com/v2/models/nvidia/research/stylegan3/versions/1/files/stylegan3-r-afhqv2-512x512.pkl
|
| 86 |
-
|
| 87 |
-
\b
|
| 88 |
-
# Generate uncurated images with truncation using the MetFaces-U dataset
|
| 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 = "huggan"
|
| 93 |
#inputs = gr.inputs.Radio(["Abstract Expressionism", "Impressionism", "Cubism", "Minimalism", "Pop Art", "Color Field", "Hana Hanak houses"])
|
| 94 |
model_path_dict = {
|
|
@@ -106,13 +94,13 @@ def generate_images(
|
|
| 106 |
|
| 107 |
model_path = model_owner + "/" + model_path_dict[model_path]
|
| 108 |
print(model_path)
|
| 109 |
-
seeds = parse_range(seeds)
|
| 110 |
print(seeds)
|
| 111 |
-
seeds=
|
|
|
|
|
|
|
| 112 |
device = torch.device('cuda') if torch.cuda.is_available() else torch.device('cpu')
|
| 113 |
G = MyGenerator.from_pretrained(model_path)
|
| 114 |
os.makedirs(outdir, exist_ok=True)
|
| 115 |
-
|
| 116 |
# Labels.
|
| 117 |
label = torch.zeros([1, G.c_dim], device=device)
|
| 118 |
"""
|
|
@@ -125,7 +113,11 @@ def generate_images(
|
|
| 125 |
print ('warn: --class=lbl ignored when running on an unconditional network')
|
| 126 |
"""
|
| 127 |
|
|
|
|
| 128 |
# Generate images.
|
|
|
|
|
|
|
|
|
|
| 129 |
for seed_idx, seed in enumerate(seeds):
|
| 130 |
print('Generating image for seed %d (%d/%d) ...' % (seed, seed_idx, len(seeds)))
|
| 131 |
z = torch.from_numpy(np.random.RandomState(seed).randn(1, G.z_dim)).to(device).float()
|
|
@@ -136,12 +128,22 @@ def generate_images(
|
|
| 136 |
m = make_transform(translate, rotate)
|
| 137 |
m = np.linalg.inv(m)
|
| 138 |
G.synthesis.input.transform.copy_(torch.from_numpy(m))
|
| 139 |
-
|
| 140 |
img = G(z, label, truncation_psi=truncation_psi, noise_mode=noise_mode)
|
| 141 |
img = (img.permute(0, 2, 3, 1) * 127.5 + 128).clamp(0, 255).to(torch.uint8)
|
| 142 |
-
|
| 143 |
-
#
|
| 144 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 145 |
|
| 146 |
|
| 147 |
#----------------------------------------------------------------------------
|
|
|
|
| 18 |
import torch
|
| 19 |
from networks_fastgan import MyGenerator
|
| 20 |
import random
|
| 21 |
+
import cv2
|
| 22 |
#----------------------------------------------------------------------------
|
| 23 |
|
| 24 |
def parse_range(s: Union[str, List]) -> List[int]:
|
|
|
|
| 75 |
outdir = "out",
|
| 76 |
translate = "0,0",
|
| 77 |
rotate = 0,
|
| 78 |
+
number_of_images = 16
|
| 79 |
):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 80 |
model_owner = "huggan"
|
| 81 |
#inputs = gr.inputs.Radio(["Abstract Expressionism", "Impressionism", "Cubism", "Minimalism", "Pop Art", "Color Field", "Hana Hanak houses"])
|
| 82 |
model_path_dict = {
|
|
|
|
| 94 |
|
| 95 |
model_path = model_owner + "/" + model_path_dict[model_path]
|
| 96 |
print(model_path)
|
|
|
|
| 97 |
print(seeds)
|
| 98 |
+
seeds=random.randint(1,230)
|
| 99 |
+
seeds =f"{seeds}-{seeds+number_of_images-1}"
|
| 100 |
+
seeds = parse_range(seeds)
|
| 101 |
device = torch.device('cuda') if torch.cuda.is_available() else torch.device('cpu')
|
| 102 |
G = MyGenerator.from_pretrained(model_path)
|
| 103 |
os.makedirs(outdir, exist_ok=True)
|
|
|
|
| 104 |
# Labels.
|
| 105 |
label = torch.zeros([1, G.c_dim], device=device)
|
| 106 |
"""
|
|
|
|
| 113 |
print ('warn: --class=lbl ignored when running on an unconditional network')
|
| 114 |
"""
|
| 115 |
|
| 116 |
+
print(f"z dimenzija mi je: {G.z_dim}")
|
| 117 |
# Generate images.
|
| 118 |
+
|
| 119 |
+
#imgs_row = np.array()
|
| 120 |
+
#imgs_complete = np.array()
|
| 121 |
for seed_idx, seed in enumerate(seeds):
|
| 122 |
print('Generating image for seed %d (%d/%d) ...' % (seed, seed_idx, len(seeds)))
|
| 123 |
z = torch.from_numpy(np.random.RandomState(seed).randn(1, G.z_dim)).to(device).float()
|
|
|
|
| 128 |
m = make_transform(translate, rotate)
|
| 129 |
m = np.linalg.inv(m)
|
| 130 |
G.synthesis.input.transform.copy_(torch.from_numpy(m))
|
| 131 |
+
|
| 132 |
img = G(z, label, truncation_psi=truncation_psi, noise_mode=noise_mode)
|
| 133 |
img = (img.permute(0, 2, 3, 1) * 127.5 + 128).clamp(0, 255).to(torch.uint8)
|
| 134 |
+
print(seed_idx)
|
| 135 |
+
#first image
|
| 136 |
+
if seed_idx == 0:
|
| 137 |
+
imgs_row = img[0].cpu().numpy()
|
| 138 |
+
else:
|
| 139 |
+
imgs_row = np.hstack((imgs_row, img[0].cpu().numpy()))
|
| 140 |
+
#img = PIL.Image.fromarray(img[0].cpu().numpy(), 'RGB')
|
| 141 |
+
PIL.Image.fromarray(img[0].cpu().numpy(), 'RGB').save(f'{outdir}/seed{seed:04d}.png')
|
| 142 |
+
#napravi vsplit i toe to ka
|
| 143 |
+
imgs_complete = np.vstack(np.hsplit(imgs_row, 4))
|
| 144 |
+
#cv2.imshow("lalaxd", imgs_complete)
|
| 145 |
+
#cv2.waitKey()
|
| 146 |
+
return PIL.Image.fromarray(imgs_complete, 'RGB')
|
| 147 |
|
| 148 |
|
| 149 |
#----------------------------------------------------------------------------
|
out/seed0008.png
ADDED
|
out/seed0009.png
ADDED
|
out/seed0010.png
ADDED
|
out/seed0011.png
ADDED
|
out/seed0012.png
ADDED
|
out/seed0013.png
ADDED
|
out/seed0014.png
ADDED
|
out/seed0015.png
ADDED
|
out/seed0016.png
ADDED
|
out/seed0017.png
ADDED
|
out/seed0018.png
ADDED
|
out/seed0019.png
ADDED
|
out/seed0020.png
ADDED
|
out/seed0021.png
ADDED
|
out/seed0022.png
ADDED
|
out/seed0023.png
ADDED
|
out/seed0024.png
ADDED
|
out/seed0027.png
ADDED
|
out/seed0028.png
ADDED
|
out/seed0029.png
ADDED
|
out/seed0030.png
ADDED
|
out/seed0031.png
ADDED
|
out/seed0032.png
ADDED
|
out/seed0033.png
ADDED
|
out/seed0034.png
ADDED
|
out/seed0035.png
ADDED
|
out/seed0036.png
ADDED
|
out/seed0037.png
ADDED
|
out/seed0038.png
ADDED
|
out/seed0039.png
ADDED
|
out/seed0040.png
ADDED
|
out/seed0041.png
ADDED
|
out/seed0042.png
ADDED
|
out/seed0043.png
ADDED
|
out/seed0046.png
ADDED
|
out/seed0047.png
ADDED
|
out/seed0048.png
ADDED
|
out/seed0049.png
ADDED
|
out/seed0050.png
ADDED
|
out/seed0051.png
ADDED
|
out/seed0052.png
ADDED
|
out/seed0053.png
ADDED
|
out/seed0054.png
CHANGED
|
|
out/seed0055.png
ADDED
|
out/seed0056.png
ADDED
|
out/seed0057.png
ADDED
|