Johannes Kolbe
commited on
Commit
·
3b72cdb
1
Parent(s):
2a4fbc6
slim readme, remove assets
Browse filesmore lfs inits
added header to readme, more ignore
lfs track gif
small changes
- .gitattributes +29 -0
- .gitignore +29 -0
- app.py +123 -0
- docs/SeFa.ipynb +257 -0
- models/model_zoo.py +310 -0
- requirements.txt +192 -0
.gitattributes
CHANGED
@@ -26,3 +26,32 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
26 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
27 |
*.zstandard filter=lfs diff=lfs merge=lfs -text
|
28 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
27 |
*.zstandard filter=lfs diff=lfs merge=lfs -text
|
28 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
29 |
+
*.gif filter=lfs diff=lfs merge=lfs -text
|
30 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
31 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
32 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
33 |
+
*.bin.* filter=lfs diff=lfs merge=lfs -text
|
34 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
35 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
36 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
37 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
38 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
39 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
40 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
41 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
42 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
43 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
44 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
45 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
46 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
47 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
48 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
49 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
50 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
51 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
52 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
53 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
54 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
55 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
56 |
+
*.zstandard filter=lfs diff=lfs merge=lfs -text
|
57 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
.gitignore
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
__pycache__/
|
2 |
+
*.py[cod]
|
3 |
+
|
4 |
+
/.vscode/
|
5 |
+
/.idea/
|
6 |
+
*.sw[pon]
|
7 |
+
|
8 |
+
/checkpoints/
|
9 |
+
/results/
|
10 |
+
*.jpg
|
11 |
+
*.png
|
12 |
+
*.jpeg
|
13 |
+
*.gif
|
14 |
+
*.avi
|
15 |
+
*.mp4
|
16 |
+
|
17 |
+
*.npy
|
18 |
+
*.json
|
19 |
+
*.log
|
20 |
+
*.html
|
21 |
+
*.tar
|
22 |
+
*.zip
|
23 |
+
events.*
|
24 |
+
|
25 |
+
*.pth
|
26 |
+
*.pkl
|
27 |
+
*.h5
|
28 |
+
*.dat
|
29 |
+
/docs/
|
app.py
ADDED
@@ -0,0 +1,123 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# python 3.7
|
2 |
+
"""Demo."""
|
3 |
+
|
4 |
+
import numpy as np
|
5 |
+
import torch
|
6 |
+
import streamlit as st
|
7 |
+
import SessionState
|
8 |
+
|
9 |
+
from models import parse_gan_type
|
10 |
+
from utils import to_tensor
|
11 |
+
from utils import postprocess
|
12 |
+
from utils import load_generator
|
13 |
+
from utils import factorize_weight
|
14 |
+
|
15 |
+
|
16 |
+
@st.cache(allow_output_mutation=True, show_spinner=False)
|
17 |
+
def get_model(model_name):
|
18 |
+
"""Gets model by name."""
|
19 |
+
return load_generator(model_name)
|
20 |
+
|
21 |
+
|
22 |
+
@st.cache(allow_output_mutation=True, show_spinner=False)
|
23 |
+
def factorize_model(model, layer_idx):
|
24 |
+
"""Factorizes semantics from target layers of the given model."""
|
25 |
+
return factorize_weight(model, layer_idx)
|
26 |
+
|
27 |
+
|
28 |
+
def sample(model, gan_type, num=1):
|
29 |
+
"""Samples latent codes."""
|
30 |
+
codes = torch.randn(num, model.z_space_dim).cuda()
|
31 |
+
if gan_type == 'pggan':
|
32 |
+
codes = model.layer0.pixel_norm(codes)
|
33 |
+
elif gan_type == 'stylegan':
|
34 |
+
codes = model.mapping(codes)['w']
|
35 |
+
codes = model.truncation(codes,
|
36 |
+
trunc_psi=0.7,
|
37 |
+
trunc_layers=8)
|
38 |
+
elif gan_type == 'stylegan2':
|
39 |
+
codes = model.mapping(codes)['w']
|
40 |
+
codes = model.truncation(codes,
|
41 |
+
trunc_psi=0.5,
|
42 |
+
trunc_layers=18)
|
43 |
+
codes = codes.detach().cpu().numpy()
|
44 |
+
return codes
|
45 |
+
|
46 |
+
|
47 |
+
@st.cache(allow_output_mutation=True, show_spinner=False)
|
48 |
+
def synthesize(model, gan_type, code):
|
49 |
+
"""Synthesizes an image with the give code."""
|
50 |
+
if gan_type == 'pggan':
|
51 |
+
image = model(to_tensor(code))['image']
|
52 |
+
elif gan_type in ['stylegan', 'stylegan2']:
|
53 |
+
image = model.synthesis(to_tensor(code))['image']
|
54 |
+
image = postprocess(image)[0]
|
55 |
+
return image
|
56 |
+
|
57 |
+
|
58 |
+
"""Main function (loop for StreamLit)."""
|
59 |
+
st.title('Closed-Form Factorization of Latent Semantics in GANs')
|
60 |
+
st.sidebar.title('Options')
|
61 |
+
reset = st.sidebar.button('Reset')
|
62 |
+
|
63 |
+
model_name = st.sidebar.selectbox(
|
64 |
+
'Model to Interpret',
|
65 |
+
['stylegan_animeface512', 'stylegan_car512', 'stylegan_cat256',
|
66 |
+
'pggan_celebahq1024'])
|
67 |
+
|
68 |
+
model = get_model(model_name)
|
69 |
+
gan_type = parse_gan_type(model)
|
70 |
+
layer_idx = st.sidebar.selectbox(
|
71 |
+
'Layers to Interpret',
|
72 |
+
['all', '0-1', '2-5', '6-13'])
|
73 |
+
layers, boundaries, eigen_values = factorize_model(model, layer_idx)
|
74 |
+
|
75 |
+
num_semantics = st.sidebar.number_input(
|
76 |
+
'Number of semantics', value=10, min_value=0, max_value=None, step=1)
|
77 |
+
steps = {sem_idx: 0 for sem_idx in range(num_semantics)}
|
78 |
+
if gan_type == 'pggan':
|
79 |
+
max_step = 5.0
|
80 |
+
elif gan_type == 'stylegan':
|
81 |
+
max_step = 2.0
|
82 |
+
elif gan_type == 'stylegan2':
|
83 |
+
max_step = 15.0
|
84 |
+
for sem_idx in steps:
|
85 |
+
eigen_value = eigen_values[sem_idx]
|
86 |
+
steps[sem_idx] = st.sidebar.slider(
|
87 |
+
f'Semantic {sem_idx:03d} (eigen value: {eigen_value:.3f})',
|
88 |
+
value=0.0,
|
89 |
+
min_value=-max_step,
|
90 |
+
max_value=max_step,
|
91 |
+
step=0.04 * max_step if not reset else 0.0)
|
92 |
+
|
93 |
+
image_placeholder = st.empty()
|
94 |
+
button_placeholder = st.empty()
|
95 |
+
|
96 |
+
try:
|
97 |
+
base_codes = np.load(f'latent_codes/{model_name}_latents.npy')
|
98 |
+
except FileNotFoundError:
|
99 |
+
base_codes = sample(model, gan_type)
|
100 |
+
|
101 |
+
state = SessionState.get(model_name=model_name,
|
102 |
+
code_idx=0,
|
103 |
+
codes=base_codes[0:1])
|
104 |
+
if state.model_name != model_name:
|
105 |
+
state.model_name = model_name
|
106 |
+
state.code_idx = 0
|
107 |
+
state.codes = base_codes[0:1]
|
108 |
+
|
109 |
+
if button_placeholder.button('Random', key=0):
|
110 |
+
state.code_idx += 1
|
111 |
+
if state.code_idx < base_codes.shape[0]:
|
112 |
+
state.codes = base_codes[state.code_idx][np.newaxis]
|
113 |
+
else:
|
114 |
+
state.codes = sample(model, gan_type)
|
115 |
+
|
116 |
+
code = state.codes.copy()
|
117 |
+
for sem_idx, step in steps.items():
|
118 |
+
if gan_type == 'pggan':
|
119 |
+
code += boundaries[sem_idx:sem_idx + 1] * step
|
120 |
+
elif gan_type in ['stylegan', 'stylegan2']:
|
121 |
+
code[:, layers, :] += boundaries[sem_idx:sem_idx + 1] * step
|
122 |
+
image = synthesize(model, gan_type, code)
|
123 |
+
image_placeholder.image(image / 255.0)
|
docs/SeFa.ipynb
ADDED
@@ -0,0 +1,257 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "markdown",
|
5 |
+
"metadata": {
|
6 |
+
"id": "qJDJLE3v0HNr"
|
7 |
+
},
|
8 |
+
"source": [
|
9 |
+
"# Fetch Codebase"
|
10 |
+
]
|
11 |
+
},
|
12 |
+
{
|
13 |
+
"cell_type": "code",
|
14 |
+
"execution_count": 2,
|
15 |
+
"metadata": {
|
16 |
+
"cellView": "form",
|
17 |
+
"id": "JqiWKjpFa0ov"
|
18 |
+
},
|
19 |
+
"outputs": [
|
20 |
+
{
|
21 |
+
"ename": "FileNotFoundError",
|
22 |
+
"evalue": "[Errno 2] No such file or directory: '/content'",
|
23 |
+
"output_type": "error",
|
24 |
+
"traceback": [
|
25 |
+
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
|
26 |
+
"\u001b[0;31mFileNotFoundError\u001b[0m Traceback (most recent call last)",
|
27 |
+
"\u001b[1;32m/home/johannes/Projects/Vision/sefa/docs/SeFa.ipynb Cell 2'\u001b[0m in \u001b[0;36m<cell line: 3>\u001b[0;34m()\u001b[0m\n\u001b[1;32m <a href='vscode-notebook-cell:/home/johannes/Projects/Vision/sefa/docs/SeFa.ipynb#ch0000001?line=0'>1</a>\u001b[0m \u001b[39m#@title\u001b[39;00m\n\u001b[1;32m <a href='vscode-notebook-cell:/home/johannes/Projects/Vision/sefa/docs/SeFa.ipynb#ch0000001?line=1'>2</a>\u001b[0m \u001b[39mimport\u001b[39;00m \u001b[39mos\u001b[39;00m\n\u001b[0;32m----> <a href='vscode-notebook-cell:/home/johannes/Projects/Vision/sefa/docs/SeFa.ipynb#ch0000001?line=2'>3</a>\u001b[0m os\u001b[39m.\u001b[39;49mchdir(\u001b[39m'\u001b[39;49m\u001b[39m/content\u001b[39;49m\u001b[39m'\u001b[39;49m)\n\u001b[1;32m <a href='vscode-notebook-cell:/home/johannes/Projects/Vision/sefa/docs/SeFa.ipynb#ch0000001?line=3'>4</a>\u001b[0m CODE_DIR \u001b[39m=\u001b[39m \u001b[39m'\u001b[39m\u001b[39msefa\u001b[39m\u001b[39m'\u001b[39m\n\u001b[1;32m <a href='vscode-notebook-cell:/home/johannes/Projects/Vision/sefa/docs/SeFa.ipynb#ch0000001?line=4'>5</a>\u001b[0m \u001b[39m#!git clone https://github.com/genforce/sefa.git $CODE_DIR\u001b[39;00m\n",
|
28 |
+
"\u001b[0;31mFileNotFoundError\u001b[0m: [Errno 2] No such file or directory: '/content'"
|
29 |
+
]
|
30 |
+
}
|
31 |
+
],
|
32 |
+
"source": [
|
33 |
+
"#@title\n",
|
34 |
+
"import os\n",
|
35 |
+
"CODE_DIR = 'sefa'\n",
|
36 |
+
"#!git clone https://github.com/genforce/sefa.git $CODE_DIR\n",
|
37 |
+
"os.chdir(f'..')"
|
38 |
+
]
|
39 |
+
},
|
40 |
+
{
|
41 |
+
"cell_type": "markdown",
|
42 |
+
"metadata": {
|
43 |
+
"id": "hQ_IXBZr8YcJ"
|
44 |
+
},
|
45 |
+
"source": [
|
46 |
+
"# Define Utility Functions"
|
47 |
+
]
|
48 |
+
},
|
49 |
+
{
|
50 |
+
"cell_type": "code",
|
51 |
+
"execution_count": 1,
|
52 |
+
"metadata": {
|
53 |
+
"cellView": "form",
|
54 |
+
"id": "ijKTlG5GeTd3"
|
55 |
+
},
|
56 |
+
"outputs": [
|
57 |
+
{
|
58 |
+
"ename": "ModuleNotFoundError",
|
59 |
+
"evalue": "No module named 'models'",
|
60 |
+
"output_type": "error",
|
61 |
+
"traceback": [
|
62 |
+
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
|
63 |
+
"\u001b[0;31mModuleNotFoundError\u001b[0m Traceback (most recent call last)",
|
64 |
+
"\u001b[1;32m/home/johannes/Projects/Vision/sefa/docs/SeFa.ipynb Cell 4'\u001b[0m in \u001b[0;36m<cell line: 11>\u001b[0;34m()\u001b[0m\n\u001b[1;32m <a href='vscode-notebook-cell:/home/johannes/Projects/Vision/sefa/docs/SeFa.ipynb#ch0000003?line=6'>7</a>\u001b[0m \u001b[39mimport\u001b[39;00m \u001b[39mPIL\u001b[39;00m\u001b[39m.\u001b[39;00m\u001b[39mImage\u001b[39;00m\n\u001b[1;32m <a href='vscode-notebook-cell:/home/johannes/Projects/Vision/sefa/docs/SeFa.ipynb#ch0000003?line=8'>9</a>\u001b[0m \u001b[39mimport\u001b[39;00m \u001b[39mtorch\u001b[39;00m\n\u001b[0;32m---> <a href='vscode-notebook-cell:/home/johannes/Projects/Vision/sefa/docs/SeFa.ipynb#ch0000003?line=10'>11</a>\u001b[0m \u001b[39mfrom\u001b[39;00m \u001b[39mmodels\u001b[39;00m \u001b[39mimport\u001b[39;00m parse_gan_type\n\u001b[1;32m <a href='vscode-notebook-cell:/home/johannes/Projects/Vision/sefa/docs/SeFa.ipynb#ch0000003?line=11'>12</a>\u001b[0m \u001b[39mfrom\u001b[39;00m \u001b[39mutils\u001b[39;00m \u001b[39mimport\u001b[39;00m to_tensor\n\u001b[1;32m <a href='vscode-notebook-cell:/home/johannes/Projects/Vision/sefa/docs/SeFa.ipynb#ch0000003?line=12'>13</a>\u001b[0m \u001b[39mfrom\u001b[39;00m \u001b[39mutils\u001b[39;00m \u001b[39mimport\u001b[39;00m postprocess\n",
|
65 |
+
"\u001b[0;31mModuleNotFoundError\u001b[0m: No module named 'models'"
|
66 |
+
]
|
67 |
+
}
|
68 |
+
],
|
69 |
+
"source": [
|
70 |
+
"#@title\n",
|
71 |
+
"import os.path\n",
|
72 |
+
"import io\n",
|
73 |
+
"import IPython.display\n",
|
74 |
+
"import numpy as np\n",
|
75 |
+
"import cv2\n",
|
76 |
+
"import PIL.Image\n",
|
77 |
+
"\n",
|
78 |
+
"import torch\n",
|
79 |
+
"\n",
|
80 |
+
"from models import parse_gan_type\n",
|
81 |
+
"from utils import to_tensor\n",
|
82 |
+
"from utils import postprocess\n",
|
83 |
+
"from utils import load_generator\n",
|
84 |
+
"from utils import factorize_weight\n",
|
85 |
+
"\n",
|
86 |
+
"\n",
|
87 |
+
"def sample(generator, gan_type, num=1, seed=0):\n",
|
88 |
+
" \"\"\"Samples latent codes.\"\"\"\n",
|
89 |
+
" torch.manual_seed(seed)\n",
|
90 |
+
" codes = torch.randn(num, generator.z_space_dim).cuda()\n",
|
91 |
+
" if gan_type == 'pggan':\n",
|
92 |
+
" codes = generator.layer0.pixel_norm(codes)\n",
|
93 |
+
" elif gan_type == 'stylegan':\n",
|
94 |
+
" codes = generator.mapping(codes)['w']\n",
|
95 |
+
" codes = generator.truncation(codes, trunc_psi=0.7, trunc_layers=8)\n",
|
96 |
+
" elif gan_type == 'stylegan2':\n",
|
97 |
+
" codes = generator.mapping(codes)['w']\n",
|
98 |
+
" codes = generator.truncation(codes, trunc_psi=0.5, trunc_layers=18)\n",
|
99 |
+
" codes = codes.detach().cpu().numpy()\n",
|
100 |
+
" return codes\n",
|
101 |
+
"\n",
|
102 |
+
"\n",
|
103 |
+
"def synthesize(generator, gan_type, codes):\n",
|
104 |
+
" \"\"\"Synthesizes images with the give codes.\"\"\"\n",
|
105 |
+
" if gan_type == 'pggan':\n",
|
106 |
+
" images = generator(to_tensor(codes))['image']\n",
|
107 |
+
" elif gan_type in ['stylegan', 'stylegan2']:\n",
|
108 |
+
" images = generator.synthesis(to_tensor(codes))['image']\n",
|
109 |
+
" images = postprocess(images)\n",
|
110 |
+
" return images\n",
|
111 |
+
"\n",
|
112 |
+
"\n",
|
113 |
+
"def imshow(images, col, viz_size=256):\n",
|
114 |
+
" \"\"\"Shows images in one figure.\"\"\"\n",
|
115 |
+
" num, height, width, channels = images.shape\n",
|
116 |
+
" assert num % col == 0\n",
|
117 |
+
" row = num // col\n",
|
118 |
+
"\n",
|
119 |
+
" fused_image = np.zeros((viz_size * row, viz_size * col, channels), dtype=np.uint8)\n",
|
120 |
+
"\n",
|
121 |
+
" for idx, image in enumerate(images):\n",
|
122 |
+
" i, j = divmod(idx, col)\n",
|
123 |
+
" y = i * viz_size\n",
|
124 |
+
" x = j * viz_size\n",
|
125 |
+
" if height != viz_size or width != viz_size:\n",
|
126 |
+
" image = cv2.resize(image, (viz_size, viz_size))\n",
|
127 |
+
" fused_image[y:y + viz_size, x:x + viz_size] = image\n",
|
128 |
+
"\n",
|
129 |
+
" fused_image = np.asarray(fused_image, dtype=np.uint8)\n",
|
130 |
+
" data = io.BytesIO()\n",
|
131 |
+
" PIL.Image.fromarray(fused_image).save(data, 'jpeg')\n",
|
132 |
+
" im_data = data.getvalue()\n",
|
133 |
+
" disp = IPython.display.display(IPython.display.Image(im_data))\n",
|
134 |
+
" return disp"
|
135 |
+
]
|
136 |
+
},
|
137 |
+
{
|
138 |
+
"cell_type": "markdown",
|
139 |
+
"metadata": {
|
140 |
+
"id": "Q7gkmrVW8eR1"
|
141 |
+
},
|
142 |
+
"source": [
|
143 |
+
"# Select a Model"
|
144 |
+
]
|
145 |
+
},
|
146 |
+
{
|
147 |
+
"cell_type": "code",
|
148 |
+
"execution_count": null,
|
149 |
+
"metadata": {
|
150 |
+
"id": "NoWI4fPQ6Gnf"
|
151 |
+
},
|
152 |
+
"outputs": [],
|
153 |
+
"source": [
|
154 |
+
"#@title { display-mode: \"form\", run: \"auto\" }\n",
|
155 |
+
"model_name = \"stylegan_animeface512\" #@param ['stylegan_animeface512', 'stylegan_car512', 'stylegan_cat256', 'pggan_celebahq1024', 'stylegan_bedroom256']\n",
|
156 |
+
"\n",
|
157 |
+
"generator = load_generator(model_name)\n",
|
158 |
+
"gan_type = parse_gan_type(generator)"
|
159 |
+
]
|
160 |
+
},
|
161 |
+
{
|
162 |
+
"cell_type": "markdown",
|
163 |
+
"metadata": {
|
164 |
+
"id": "zDStH1O5t1KC"
|
165 |
+
},
|
166 |
+
"source": [
|
167 |
+
"# Sample Latent Codes"
|
168 |
+
]
|
169 |
+
},
|
170 |
+
{
|
171 |
+
"cell_type": "code",
|
172 |
+
"execution_count": null,
|
173 |
+
"metadata": {
|
174 |
+
"id": "qlRGKZbJt9hA"
|
175 |
+
},
|
176 |
+
"outputs": [],
|
177 |
+
"source": [
|
178 |
+
"#@title { display-mode: \"form\", run: \"auto\" }\n",
|
179 |
+
"\n",
|
180 |
+
"num_samples = 3 #@param {type:\"slider\", min:1, max:8, step:1}\n",
|
181 |
+
"noise_seed = 0 #@param {type:\"slider\", min:0, max:1000, step:1}\n",
|
182 |
+
"\n",
|
183 |
+
"codes = sample(generator, gan_type, num_samples, noise_seed)\n",
|
184 |
+
"images = synthesize(generator, gan_type, codes)\n",
|
185 |
+
"imshow(images, col=num_samples)"
|
186 |
+
]
|
187 |
+
},
|
188 |
+
{
|
189 |
+
"cell_type": "markdown",
|
190 |
+
"metadata": {
|
191 |
+
"id": "MmRPN3xz8jCH"
|
192 |
+
},
|
193 |
+
"source": [
|
194 |
+
"# Factorize & Edit"
|
195 |
+
]
|
196 |
+
},
|
197 |
+
{
|
198 |
+
"cell_type": "code",
|
199 |
+
"execution_count": null,
|
200 |
+
"metadata": {
|
201 |
+
"id": "ccONBF60mVir"
|
202 |
+
},
|
203 |
+
"outputs": [],
|
204 |
+
"source": [
|
205 |
+
"#@title { display-mode: \"form\", run: \"auto\" }\n",
|
206 |
+
"\n",
|
207 |
+
"layer_idx = \"0-1\" #@param ['all', '0-1', '2-5', '6-13']\n",
|
208 |
+
"semantic_1 = 0 #@param {type:\"slider\", min:-3.0, max:3.0, step:0.1}\n",
|
209 |
+
"semantic_2 = 0 #@param {type:\"slider\", min:-3.0, max:3.0, step:0.1}\n",
|
210 |
+
"semantic_3 = 0 #@param {type:\"slider\", min:-3.0, max:3.0, step:0.1}\n",
|
211 |
+
"semantic_4 = 0 #@param {type:\"slider\", min:-3.0, max:3.0, step:0.1}\n",
|
212 |
+
"semantic_5 = 0 #@param {type:\"slider\", min:-3.0, max:3.0, step:0.1}\n",
|
213 |
+
"\n",
|
214 |
+
"# Fast implementation to factorize the weight by SeFa.\n",
|
215 |
+
"layers, boundaries, _ = factorize_weight(generator, layer_idx)\n",
|
216 |
+
"\n",
|
217 |
+
"new_codes = codes.copy()\n",
|
218 |
+
"for sem_idx in range(5):\n",
|
219 |
+
" boundary = boundaries[sem_idx:sem_idx + 1]\n",
|
220 |
+
" step = eval(f'semantic_{sem_idx + 1}')\n",
|
221 |
+
" if gan_type == 'pggan':\n",
|
222 |
+
" new_codes += boundary * step\n",
|
223 |
+
" elif gan_type in ['stylegan', 'stylegan2']:\n",
|
224 |
+
" new_codes[:, layers, :] += boundary * step\n",
|
225 |
+
"new_images = synthesize(generator, gan_type, new_codes)\n",
|
226 |
+
"imshow(new_images, col=num_samples)"
|
227 |
+
]
|
228 |
+
}
|
229 |
+
],
|
230 |
+
"metadata": {
|
231 |
+
"accelerator": "GPU",
|
232 |
+
"colab": {
|
233 |
+
"collapsed_sections": [],
|
234 |
+
"name": "SeFa",
|
235 |
+
"provenance": [],
|
236 |
+
"toc_visible": true
|
237 |
+
},
|
238 |
+
"kernelspec": {
|
239 |
+
"display_name": "Python 3",
|
240 |
+
"name": "python3"
|
241 |
+
},
|
242 |
+
"language_info": {
|
243 |
+
"codemirror_mode": {
|
244 |
+
"name": "ipython",
|
245 |
+
"version": 3
|
246 |
+
},
|
247 |
+
"file_extension": ".py",
|
248 |
+
"mimetype": "text/x-python",
|
249 |
+
"name": "python",
|
250 |
+
"nbconvert_exporter": "python",
|
251 |
+
"pygments_lexer": "ipython3",
|
252 |
+
"version": "3.9.9"
|
253 |
+
}
|
254 |
+
},
|
255 |
+
"nbformat": 4,
|
256 |
+
"nbformat_minor": 0
|
257 |
+
}
|
models/model_zoo.py
ADDED
@@ -0,0 +1,310 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# python3.7
|
2 |
+
"""Model zoo."""
|
3 |
+
|
4 |
+
# pylint: disable=line-too-long
|
5 |
+
|
6 |
+
MODEL_ZOO = {
|
7 |
+
# PGGAN official.
|
8 |
+
'pggan_celebahq1024': dict(
|
9 |
+
gan_type='pggan',
|
10 |
+
resolution=1024,
|
11 |
+
url='https://mycuhk-my.sharepoint.com/:u:/g/personal/1155082926_link_cuhk_edu_hk/EW_3jQ6E7xlKvCSHYrbmkQQBAB8tgIv5W5evdT6-GuXiWw?e=gRifVa&download=1',
|
12 |
+
),
|
13 |
+
'pggan_bedroom256': dict(
|
14 |
+
gan_type='pggan',
|
15 |
+
resolution=256,
|
16 |
+
url='https://mycuhk-my.sharepoint.com/:u:/g/personal/1155082926_link_cuhk_edu_hk/EUZQWGz2GT5Bh_GJLalP63IBvCsXDTOxDFIC_ZBsmoEacA?e=VNXiDb&download=1',
|
17 |
+
),
|
18 |
+
'pggan_livingroom256': dict(
|
19 |
+
gan_type='pggan',
|
20 |
+
resolution=256,
|
21 |
+
url='https://mycuhk-my.sharepoint.com/:u:/g/personal/1155082926_link_cuhk_edu_hk/Efzh6qQv6QtCm0YN1lulH-YByqdE3AqlI-E6US_hXMuiig?e=ppdyB2&download=1',
|
22 |
+
),
|
23 |
+
'pggan_diningroom256': dict(
|
24 |
+
gan_type='pggan',
|
25 |
+
resolution=256,
|
26 |
+
url='https://mycuhk-my.sharepoint.com/:u:/g/personal/1155082926_link_cuhk_edu_hk/EcLb3_hGUkdClompZo27xk0BNmotgbFqdIeu-ZOGJsBMRg?e=xjYpN3&download=1',
|
27 |
+
),
|
28 |
+
'pggan_kitchen256': dict(
|
29 |
+
gan_type='pggan',
|
30 |
+
resolution=256,
|
31 |
+
url='https://mycuhk-my.sharepoint.com/:u:/g/personal/1155082926_link_cuhk_edu_hk/ESCyg6hpNn1LlHVX_un1wLsBZAORUNkW9MO2kU1X5kafAQ?e=09TbGC&download=1',
|
32 |
+
),
|
33 |
+
'pggan_church256': dict(
|
34 |
+
gan_type='pggan',
|
35 |
+
resolution=256,
|
36 |
+
url='https://mycuhk-my.sharepoint.com/:u:/g/personal/1155082926_link_cuhk_edu_hk/EQ8cKujs2TVGjCL_j6bsnk8BqD9REF2ME2lBnpbTPsqIvA?e=zH55fT&download=1',
|
37 |
+
),
|
38 |
+
'pggan_tower256': dict(
|
39 |
+
gan_type='pggan',
|
40 |
+
resolution=256,
|
41 |
+
url='https://mycuhk-my.sharepoint.com/:u:/g/personal/1155082926_link_cuhk_edu_hk/EeyBJvgRVGJClKr1KKYDF_cBT1FDepRU1-GLqYNh8W9-fQ?e=nrpa5N&download=1',
|
42 |
+
),
|
43 |
+
'pggan_bridge256': dict(
|
44 |
+
gan_type='pggan',
|
45 |
+
resolution=256,
|
46 |
+
url='https://mycuhk-my.sharepoint.com/:u:/g/personal/1155082926_link_cuhk_edu_hk/EZ2QScfPy19PiDERLJQ3gPMBP4WmvZHwhNFLzfaP2YD8hQ?e=bef1U9&download=1',
|
47 |
+
),
|
48 |
+
'pggan_restaurant256': dict(
|
49 |
+
gan_type='pggan',
|
50 |
+
resolution=256,
|
51 |
+
url='https://mycuhk-my.sharepoint.com/:u:/g/personal/1155082926_link_cuhk_edu_hk/ERvJ4pz8jgtMrcuJXUfcOQEBDugZ099_TetCQs-9-ILCVg?e=qYsVdQ&download=1',
|
52 |
+
),
|
53 |
+
'pggan_classroom256': dict(
|
54 |
+
gan_type='pggan',
|
55 |
+
resolution=256,
|
56 |
+
url='https://mycuhk-my.sharepoint.com/:u:/g/personal/1155082926_link_cuhk_edu_hk/EUU9SCOPUxhMoUS4Ceo9kl0BQkVK7d69lA-JeOP-zOWvXw?e=YIB4no&download=1',
|
57 |
+
),
|
58 |
+
'pggan_conferenceroom256': dict(
|
59 |
+
gan_type='pggan',
|
60 |
+
resolution=256,
|
61 |
+
url='https://mycuhk-my.sharepoint.com/:u:/g/personal/1155082926_link_cuhk_edu_hk/EX8AF0_6NoJAl5vKFewHWnsBk0r4PK4WsqsMrJyj84TrqQ?e=oNQIZS&download=1',
|
62 |
+
),
|
63 |
+
'pggan_person256': dict(
|
64 |
+
gan_type='pggan',
|
65 |
+
resolution=256,
|
66 |
+
url='https://mycuhk-my.sharepoint.com/:u:/g/personal/1155082926_link_cuhk_edu_hk/EWu4SqR42YpCoqsVJOcM2cMBcdfXA0j5wZ2hno9X0R9ydQ?e=KuDRns&download=1',
|
67 |
+
),
|
68 |
+
'pggan_cat256': dict(
|
69 |
+
gan_type='pggan',
|
70 |
+
resolution=256,
|
71 |
+
url='https://mycuhk-my.sharepoint.com/:u:/g/personal/1155082926_link_cuhk_edu_hk/EQdveyUNOMtAue52n6BxoHoB6Yup5-PTvBDmyfUn7Un4Hw?e=7acGbT&download=1',
|
72 |
+
),
|
73 |
+
'pggan_dog256': dict(
|
74 |
+
gan_type='pggan',
|
75 |
+
resolution=256,
|
76 |
+
url='https://mycuhk-my.sharepoint.com/:u:/g/personal/1155082926_link_cuhk_edu_hk/ESaKyXA5fGlOvXJYDDFbT2kB9c0HlXh9n_wnyhiP05nhow?e=d4aKDV&download=1',
|
77 |
+
),
|
78 |
+
'pggan_bird256': dict(
|
79 |
+
gan_type='pggan',
|
80 |
+
resolution=256,
|
81 |
+
url='https://mycuhk-my.sharepoint.com/:u:/g/personal/1155082926_link_cuhk_edu_hk/Ef2p4Pd3AKVCmSm00YikCIABhylh2dLPaFjPfPVn3RiTXA?e=9bRitp&download=1',
|
82 |
+
),
|
83 |
+
'pggan_horse256': dict(
|
84 |
+
gan_type='pggan',
|
85 |
+
resolution=256,
|
86 |
+
url='https://mycuhk-my.sharepoint.com/:u:/g/personal/1155082926_link_cuhk_edu_hk/EXwCPdv6XqJFtuvFFoswRScBmLJbhKzaC5D_iovl1GFOTw?e=WDdD77&download=1',
|
87 |
+
),
|
88 |
+
'pggan_sheep256': dict(
|
89 |
+
gan_type='pggan',
|
90 |
+
resolution=256,
|
91 |
+
url='https://mycuhk-my.sharepoint.com/:u:/g/personal/1155082926_link_cuhk_edu_hk/ER6J5EKjAUNFtm9VwLf-uUsBZ5dnqxeKsPxY9ijiPtMhcQ?e=OKtfva&download=1',
|
92 |
+
),
|
93 |
+
'pggan_cow256': dict(
|
94 |
+
gan_type='pggan',
|
95 |
+
resolution=256,
|
96 |
+
url='https://mycuhk-my.sharepoint.com/:u:/g/personal/1155082926_link_cuhk_edu_hk/ERZLxw7N7xJPm72FyePTbpcByzrr0pH-Fg7qyLt5tYGXwQ?e=ovIPCl&download=1',
|
97 |
+
),
|
98 |
+
'pggan_car256': dict(
|
99 |
+
gan_type='pggan',
|
100 |
+
resolution=256,
|
101 |
+
url='https://mycuhk-my.sharepoint.com/:u:/g/personal/1155082926_link_cuhk_edu_hk/EfGc2we47aFDtAY1548pRvsByIju-uXRbkZEFpJotuPKZw?e=DQqVj8&download=1',
|
102 |
+
),
|
103 |
+
'pggan_bicycle256': dict(
|
104 |
+
gan_type='pggan',
|
105 |
+
resolution=256,
|
106 |
+
url='https://mycuhk-my.sharepoint.com/:u:/g/personal/1155082926_link_cuhk_edu_hk/Ed1dN_FgwmdBgeNWhaRUry8BgwT88-n2ppicSDPx-f7f_Q?e=bxTxnf&download=1',
|
107 |
+
),
|
108 |
+
'pggan_motorbike256': dict(
|
109 |
+
gan_type='pggan',
|
110 |
+
resolution=256,
|
111 |
+
url='https://mycuhk-my.sharepoint.com/:u:/g/personal/1155082926_link_cuhk_edu_hk/EV3yQdeJXIdPjZbMO0mp2-MBJbKuuBdypzBL4gnedO57Dw?e=tXdvtD&download=1',
|
112 |
+
),
|
113 |
+
'pggan_bus256': dict(
|
114 |
+
gan_type='pggan',
|
115 |
+
resolution=256,
|
116 |
+
url='https://mycuhk-my.sharepoint.com/:u:/g/personal/1155082926_link_cuhk_edu_hk/Ed7-OYLnq0RCqRlM8qK8wZ8B87dz_NUxIKBrvyFUwRCEbg?e=VP5bmX&download=1',
|
117 |
+
),
|
118 |
+
'pggan_train256': dict(
|
119 |
+
gan_type='pggan',
|
120 |
+
resolution=256,
|
121 |
+
url='https://mycuhk-my.sharepoint.com/:u:/g/personal/1155082926_link_cuhk_edu_hk/EedE2cozKOVAkhvbdLd4SfwBknFW8vWZnKiqgeIBbAvCCA?e=BrLpTl&download=1',
|
122 |
+
),
|
123 |
+
'pggan_boat256': dict(
|
124 |
+
gan_type='pggan',
|
125 |
+
resolution=256,
|
126 |
+
url='https://mycuhk-my.sharepoint.com/:u:/g/personal/1155082926_link_cuhk_edu_hk/Eb39waqQFr9Bp4wO0rC5NHwB0Vz2NGCuqbRPucguBIkDrg?e=lddSyL&download=1',
|
127 |
+
),
|
128 |
+
'pggan_airplane256': dict(
|
129 |
+
gan_type='pggan',
|
130 |
+
resolution=256,
|
131 |
+
url='https://mycuhk-my.sharepoint.com/:u:/g/personal/1155082926_link_cuhk_edu_hk/Ee6FzIx3KjNDhxrS5mDvpCEB3iQ7TgErmKhbwbV-eF07iw?e=xflPXa&download=1',
|
132 |
+
),
|
133 |
+
'pggan_bottle256': dict(
|
134 |
+
gan_type='pggan',
|
135 |
+
resolution=256,
|
136 |
+
url='https://mycuhk-my.sharepoint.com/:u:/g/personal/1155082926_link_cuhk_edu_hk/EWhoy2AFCTZGtEG1UoayWjcB9Kdc_wreJ8p4RlBB93nbNg?e=DMZceU&download=1',
|
137 |
+
),
|
138 |
+
'pggan_chair256': dict(
|
139 |
+
gan_type='pggan',
|
140 |
+
resolution=256,
|
141 |
+
url='https://mycuhk-my.sharepoint.com/:u:/g/personal/1155082926_link_cuhk_edu_hk/EbQRTfwdostBhXG30Uacn7ABsEUFa-tEW3oxiM5zDYQbRw?e=FkB7T0&download=1',
|
142 |
+
),
|
143 |
+
'pggan_pottedplant256': dict(
|
144 |
+
gan_type='pggan',
|
145 |
+
resolution=256,
|
146 |
+
url='https://mycuhk-my.sharepoint.com/:u:/g/personal/1155082926_link_cuhk_edu_hk/EWg7hnoGATBOuJvXWr4m7CQBJL9o7nqnD6nOMRhtH2SKXg?e=Zi3hjD&download=1',
|
147 |
+
),
|
148 |
+
'pggan_tvmonitor256': dict(
|
149 |
+
gan_type='pggan',
|
150 |
+
resolution=256,
|
151 |
+
url='https://mycuhk-my.sharepoint.com/:u:/g/personal/1155082926_link_cuhk_edu_hk/EVXwttoJVtBMuhHNDdK3cMwBdMiZARJV38PMTsL6whnFlA?e=RbG0ru&download=1',
|
152 |
+
),
|
153 |
+
'pggan_diningtable256': dict(
|
154 |
+
gan_type='pggan',
|
155 |
+
resolution=256,
|
156 |
+
url='https://mycuhk-my.sharepoint.com/:u:/g/personal/1155082926_link_cuhk_edu_hk/EXVzBkbmTCVImMtuHLCTBeMBXZmv0RWyx5KXQQAe7-7D5w?e=6RYSnm&download=1',
|
157 |
+
),
|
158 |
+
'pggan_sofa256': dict(
|
159 |
+
gan_type='pggan',
|
160 |
+
resolution=256,
|
161 |
+
url='https://mycuhk-my.sharepoint.com/:u:/g/personal/1155082926_link_cuhk_edu_hk/EaADQYDXwY9NrzbiUFcRYRgBOu1GdJMG8YgNZZmbNjbn-Q?e=DqKrXG&download=1',
|
162 |
+
),
|
163 |
+
|
164 |
+
# StyleGAN official.
|
165 |
+
'stylegan_ffhq1024': dict(
|
166 |
+
gan_type='stylegan',
|
167 |
+
resolution=1024,
|
168 |
+
url='https://mycuhk-my.sharepoint.com/:u:/g/personal/1155082926_link_cuhk_edu_hk/EdfMxgb0hU9BoXwiR3dqYDEBowCSEF1IcsW3n4kwfoZ9OQ?e=VwIV58&download=1',
|
169 |
+
),
|
170 |
+
'stylegan_celebahq1024': dict(
|
171 |
+
gan_type='stylegan',
|
172 |
+
resolution=1024,
|
173 |
+
url='https://mycuhk-my.sharepoint.com/:u:/g/personal/1155082926_link_cuhk_edu_hk/EcCdXHddE7FOvyfmqeOyc9ABqVuWh8PQYFnV6JM1CXvFig?e=1nUYZ5&download=1',
|
174 |
+
),
|
175 |
+
'stylegan_bedroom256': dict(
|
176 |
+
gan_type='stylegan',
|
177 |
+
resolution=256,
|
178 |
+
url='https://mycuhk-my.sharepoint.com/:u:/g/personal/1155082926_link_cuhk_edu_hk/Ea6RBPddjcRNoFMXm8AyEBcBUHdlRNtjtclNKFe89amjBw?e=Og8Vff&download=1',
|
179 |
+
),
|
180 |
+
'stylegan_cat256': dict(
|
181 |
+
gan_type='stylegan',
|
182 |
+
resolution=256,
|
183 |
+
url='https://mycuhk-my.sharepoint.com/:u:/g/personal/1155082926_link_cuhk_edu_hk/EVjX8u9HuehLip3z0hRfIHcB7QtoFkTB7NiRDb8nrKOl2w?e=lHcp1B&download=1',
|
184 |
+
),
|
185 |
+
'stylegan_car512': dict(
|
186 |
+
gan_type='stylegan',
|
187 |
+
resolution=512,
|
188 |
+
url='https://mycuhk-my.sharepoint.com/:u:/g/personal/1155082926_link_cuhk_edu_hk/EcRJNNzzUzJGjI2X53S9HjkBhXkKT5JRd6Q3IIhCY1AyRw?e=FvMRNj&download=1',
|
189 |
+
),
|
190 |
+
|
191 |
+
# StyleGAN ours.
|
192 |
+
'stylegan_celeba_partial256': dict(
|
193 |
+
gan_type='stylegan',
|
194 |
+
resolution=256,
|
195 |
+
url='https://mycuhk-my.sharepoint.com/:u:/g/personal/1155082926_link_cuhk_edu_hk/ET2etKNzMS9JmHj5j60fqMcBRJfQfYNvqUrujaIXxCvKDQ?e=QReLE6&download=1',
|
196 |
+
),
|
197 |
+
'stylegan_ffhq256': dict(
|
198 |
+
gan_type='stylegan',
|
199 |
+
resolution=256,
|
200 |
+
url='https://mycuhk-my.sharepoint.com/:u:/g/personal/1155082926_link_cuhk_edu_hk/ES-NAUCC2qdHg87BftvlBiQBVpbJ8-005Q4TNr5KrOxQEw?e=00AnWt&download=1',
|
201 |
+
),
|
202 |
+
'stylegan_ffhq512': dict(
|
203 |
+
gan_type='stylegan',
|
204 |
+
resolution=512,
|
205 |
+
url='https://mycuhk-my.sharepoint.com/:u:/g/personal/1155082926_link_cuhk_edu_hk/EZYrrwOiEgVOg-PfGv7QTegBzFQ9yq2v7o1WxNq5JJ9KNA?e=SZU8PI&download=1',
|
206 |
+
),
|
207 |
+
'stylegan_livingroom256': dict(
|
208 |
+
gan_type='stylegan',
|
209 |
+
resolution=256,
|
210 |
+
url='https://mycuhk-my.sharepoint.com/:u:/g/personal/1155082926_link_cuhk_edu_hk/EfFCYLHjqbFDmjOvCCFJgDcBZ1QYgETfZJxp4ZTHjLxZBg?e=InVd0n&download=1',
|
211 |
+
),
|
212 |
+
'stylegan_diningroom256': dict(
|
213 |
+
gan_type='stylegan',
|
214 |
+
resolution=256,
|
215 |
+
url='https://mycuhk-my.sharepoint.com/:u:/g/personal/1155082926_link_cuhk_edu_hk/ERsUza_hSFRIm4iZCag7P0kBQ9EIdfQKByw4QYt_ay97lg?e=Cimh7S&download=1',
|
216 |
+
),
|
217 |
+
'stylegan_kitchen256': dict(
|
218 |
+
gan_type='stylegan',
|
219 |
+
resolution=256,
|
220 |
+
url='https://mycuhk-my.sharepoint.com/:u:/g/personal/1155082926_link_cuhk_edu_hk/ERcYvoingQNKix35lUs0vUkBQQkAZMp1rtDxjwNlOJAoaA?e=a1Tcwr&download=1',
|
221 |
+
),
|
222 |
+
'stylegan_apartment256': dict(
|
223 |
+
gan_type='stylegan',
|
224 |
+
resolution=256,
|
225 |
+
url='https://mycuhk-my.sharepoint.com/:u:/g/personal/1155082926_link_cuhk_edu_hk/EfurPNSB2BRFtXdqGkmDD6YBwyKN8YK2v7nKwnJQdsbf6A?e=w3oYa4&download=1',
|
226 |
+
),
|
227 |
+
'stylegan_church256': dict(
|
228 |
+
gan_type='stylegan',
|
229 |
+
resolution=256,
|
230 |
+
url='https://mycuhk-my.sharepoint.com/:u:/g/personal/1155082926_link_cuhk_edu_hk/ETMgG1_d06tAlbUkJD1qA9IBaLZ9zJKPkG2kO-4jxhVV5w?e=Dbkb7o&download=1',
|
231 |
+
),
|
232 |
+
'stylegan_tower256': dict(
|
233 |
+
gan_type='stylegan',
|
234 |
+
resolution=256,
|
235 |
+
url='https://mycuhk-my.sharepoint.com/:u:/g/personal/1155082926_link_cuhk_edu_hk/Ebm9QMgqB2VDqyIE5rFhreEBgZ_RyKcRf8bQ333K453u3w?e=if8sDj&download=1',
|
236 |
+
),
|
237 |
+
'stylegan_bridge256': dict(
|
238 |
+
gan_type='stylegan',
|
239 |
+
resolution=256,
|
240 |
+
url='https://mycuhk-my.sharepoint.com/:u:/g/personal/1155082926_link_cuhk_edu_hk/Ed9QM6OP9sVHnazSp4cqPSEBb-ALfBPXRxP1hD7FsTYh8w?e=3vv06p&download=1',
|
241 |
+
),
|
242 |
+
'stylegan_restaurant256': dict(
|
243 |
+
gan_type='stylegan',
|
244 |
+
resolution=256,
|
245 |
+
url='https://mycuhk-my.sharepoint.com/:u:/g/personal/1155082926_link_cuhk_edu_hk/ESDhYr01WtlEvBNFrVpFezcB2l9lF1rBYuHFoeNpBr5B7A?e=uFWFNh&download=1',
|
246 |
+
),
|
247 |
+
'stylegan_classroom256': dict(
|
248 |
+
gan_type='stylegan',
|
249 |
+
resolution=256,
|
250 |
+
url='https://mycuhk-my.sharepoint.com/:u:/g/personal/1155082926_link_cuhk_edu_hk/EbWnI3oto9NPk-lxwZlWqPQB2atWpGiTWMIT59MzF9ij9Q?e=KvcNBg&download=1',
|
251 |
+
),
|
252 |
+
'stylegan_conferenceroom256': dict(
|
253 |
+
gan_type='stylegan',
|
254 |
+
resolution=256,
|
255 |
+
url='https://mycuhk-my.sharepoint.com/:u:/g/personal/1155082926_link_cuhk_edu_hk/Eb1gVi3pGa9PgJ4XYYu_6yABQZ0ZcGDak4FEHaTHaeYFzw?e=0BeE8t&download=1',
|
256 |
+
),
|
257 |
+
|
258 |
+
# StyleGAN third-party.
|
259 |
+
'stylegan_animeface512': dict(
|
260 |
+
gan_type='stylegan',
|
261 |
+
resolution=512,
|
262 |
+
url='https://mycuhk-my.sharepoint.com/:u:/g/personal/1155082926_link_cuhk_edu_hk/EWDWflY6lBpGgX0CGQpd2Z4B5wTEVamTOA9JRYne7zdCvA?e=tOzgYA&download=1',
|
263 |
+
),
|
264 |
+
'stylegan_animeportrait512': dict(
|
265 |
+
gan_type='stylegan',
|
266 |
+
resolution=512,
|
267 |
+
url='https://mycuhk-my.sharepoint.com/:u:/g/personal/1155082926_link_cuhk_edu_hk/EXBvhTBi-v5NsnQtrxhFEKsBin4xg-Dud9Jr62AEwFTIxg?e=bMGK7r&download=1',
|
268 |
+
),
|
269 |
+
'stylegan_artface512': dict(
|
270 |
+
gan_type='stylegan',
|
271 |
+
resolution=512,
|
272 |
+
url='https://mycuhk-my.sharepoint.com/:u:/g/personal/1155082926_link_cuhk_edu_hk/Eca0OiGqhyZMmoPbKahSBWQBWvcAH4q2CE3zdZJflp2jkQ?e=h4rWAm&download=1',
|
273 |
+
),
|
274 |
+
|
275 |
+
# StyleGAN2 official.
|
276 |
+
'stylegan2_ffhq1024': dict(
|
277 |
+
gan_type='stylegan2',
|
278 |
+
resolution=1024,
|
279 |
+
url='https://mycuhk-my.sharepoint.com/:u:/g/personal/1155082926_link_cuhk_edu_hk/EX0DNWiBvl5FuOQTF4oMPBYBNSalcxTK0AbLwBn9Y3vfgg?e=Q0sZit&download=1',
|
280 |
+
),
|
281 |
+
'stylegan2_church256': dict(
|
282 |
+
gan_type='stylegan2',
|
283 |
+
resolution=256,
|
284 |
+
url='https://mycuhk-my.sharepoint.com/:u:/g/personal/1155082926_link_cuhk_edu_hk/EQzDtJUdQ4ROunMGn2sZouEBmNeFX4QWvxjermVE5cZvNA?e=tQ7r9r&download=1',
|
285 |
+
),
|
286 |
+
'stylegan2_cat256': dict(
|
287 |
+
gan_type='stylegan2',
|
288 |
+
resolution=256,
|
289 |
+
url='https://mycuhk-my.sharepoint.com/:u:/g/personal/1155082926_link_cuhk_edu_hk/EUKXeBwUUbZJr6kup7PW4ekBx2-vmTp8FjcGb10v8bgJxQ?e=nkerMF&download=1',
|
290 |
+
),
|
291 |
+
'stylegan2_horse256': dict(
|
292 |
+
gan_type='stylegan2',
|
293 |
+
resolution=256,
|
294 |
+
url='https://mycuhk-my.sharepoint.com/:u:/g/personal/1155082926_link_cuhk_edu_hk/EconoT6tb69OuAIqfXRtGlsBZz4vBx01UmmFO-JAS356Jg?e=bcSCC4&download=1',
|
295 |
+
),
|
296 |
+
'stylegan2_car512': dict(
|
297 |
+
gan_type='stylegan2',
|
298 |
+
resolution=512,
|
299 |
+
url='https://mycuhk-my.sharepoint.com/:u:/g/personal/1155082926_link_cuhk_edu_hk/EYSnUsxU8KJFuMHhZm-JLWoB0nHxdlbrLHNZ_Qkoe3b9LA?e=Ycjp5A&download=1',
|
300 |
+
),
|
301 |
+
|
302 |
+
#huggingface models
|
303 |
+
'akhaliq/OneshotCLIP-stylegan2-ffhq' : dict(
|
304 |
+
gan_type='stylegan2',
|
305 |
+
resolution=512,
|
306 |
+
url='akhaliq/OneshotCLIP-stylegan2-ffhq',
|
307 |
+
)
|
308 |
+
}
|
309 |
+
|
310 |
+
# pylint: enable=line-too-long
|
requirements.txt
ADDED
@@ -0,0 +1,192 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
absl-py==0.11.0
|
2 |
+
aiohttp==3.8.1
|
3 |
+
aiosignal==1.2.0
|
4 |
+
altair==4.1.0
|
5 |
+
argcomplete==1.12.3
|
6 |
+
argon2-cffi==21.3.0
|
7 |
+
argon2-cffi-bindings==21.2.0
|
8 |
+
asn1crypto==0.24.0
|
9 |
+
astor==0.8.1
|
10 |
+
async-generator==1.10
|
11 |
+
async-timeout==4.0.2
|
12 |
+
asynctest==0.13.0
|
13 |
+
attrs==21.4.0
|
14 |
+
aws-error-utils==1.3.0
|
15 |
+
aws-sso-lib==1.10.0
|
16 |
+
aws-sso-util==4.27.0
|
17 |
+
awscli==1.18.69
|
18 |
+
backcall==0.2.0
|
19 |
+
backports.entry-points-selectable==1.1.0
|
20 |
+
backports.zoneinfo==0.2.1
|
21 |
+
bleach==4.1.0
|
22 |
+
blinker==1.4
|
23 |
+
boto3==1.21.20
|
24 |
+
botocore==1.24.20
|
25 |
+
Brlapi==0.6.6
|
26 |
+
cached-property==1.5.2
|
27 |
+
cachetools==4.2.4
|
28 |
+
certifi==2018.1.18
|
29 |
+
cffi==1.15.0
|
30 |
+
chardet==3.0.4
|
31 |
+
charset-normalizer==2.0.12
|
32 |
+
click==7.1.2
|
33 |
+
colorama==0.3.7
|
34 |
+
cryptography==2.1.4
|
35 |
+
cupshelpers==1.0
|
36 |
+
dataclasses==0.8
|
37 |
+
-e git+https://github.com/huggingface/datasets@d922b19be8e82cd33e5270b8a87312a161799649#egg=datasets
|
38 |
+
decorator==5.1.1
|
39 |
+
defer==1.0.6
|
40 |
+
defusedxml==0.7.1
|
41 |
+
dill==0.3.4
|
42 |
+
distlib==0.3.3
|
43 |
+
distro-info===0.18ubuntu0.18.04.1
|
44 |
+
docutils==0.14
|
45 |
+
entrypoints==0.4
|
46 |
+
filelock==3.3.2
|
47 |
+
frozenlist==1.2.0
|
48 |
+
fsspec==2022.1.0
|
49 |
+
gast==0.4.0
|
50 |
+
gitdb==4.0.9
|
51 |
+
GitPython==3.1.18
|
52 |
+
google-pasta==0.2.0
|
53 |
+
grpcio==1.36.0rc1
|
54 |
+
h5py==3.1.0
|
55 |
+
httplib2==0.9.2
|
56 |
+
huggingface-hub==0.4.0
|
57 |
+
idna==2.6
|
58 |
+
idna-ssl==1.1.0
|
59 |
+
imageio==2.9.0
|
60 |
+
importlib-metadata==4.8.1
|
61 |
+
importlib-resources==5.4.0
|
62 |
+
ipykernel==5.5.6
|
63 |
+
ipython==7.16.3
|
64 |
+
ipython-genutils==0.2.0
|
65 |
+
ipywidgets==7.7.0
|
66 |
+
ISR==2.2.0
|
67 |
+
jedi==0.17.2
|
68 |
+
Jinja2==3.0.3
|
69 |
+
jmespath==0.9.3
|
70 |
+
jsonschema==3.2.0
|
71 |
+
jupyter-client==7.1.2
|
72 |
+
jupyter-core==4.9.2
|
73 |
+
jupyterlab-pygments==0.1.2
|
74 |
+
jupyterlab-widgets==1.1.0
|
75 |
+
Keras-Applications==1.0.8
|
76 |
+
Keras-Preprocessing==1.1.2
|
77 |
+
keyring==10.6.0
|
78 |
+
keyrings.alt==3.0
|
79 |
+
language-selector==0.1
|
80 |
+
launchpadlib==1.10.6
|
81 |
+
lazr.restfulclient==0.13.5
|
82 |
+
lazr.uri==1.0.3
|
83 |
+
louis==3.5.0
|
84 |
+
macaroonbakery==1.1.3
|
85 |
+
Mako==1.0.7
|
86 |
+
Markdown==3.3.3
|
87 |
+
MarkupSafe==2.0.1
|
88 |
+
meld==3.18.0
|
89 |
+
mistune==0.8.4
|
90 |
+
multidict==5.2.0
|
91 |
+
multiprocess==0.70.12.2
|
92 |
+
nbclient==0.5.9
|
93 |
+
nbconvert==6.0.7
|
94 |
+
nbformat==5.1.3
|
95 |
+
nest-asyncio==1.5.5
|
96 |
+
netifaces==0.10.4
|
97 |
+
notebook==6.4.10
|
98 |
+
numpy==1.19.5
|
99 |
+
oauth==1.0.1
|
100 |
+
olefile==0.45.1
|
101 |
+
packaging==21.2
|
102 |
+
pandas==1.1.5
|
103 |
+
pandocfilters==1.5.0
|
104 |
+
parso==0.7.1
|
105 |
+
pexpect==4.2.1
|
106 |
+
pickleshare==0.7.5
|
107 |
+
Pillow==8.4.0
|
108 |
+
pipenv==2021.11.23
|
109 |
+
pipx==0.16.4
|
110 |
+
platformdirs==2.4.0
|
111 |
+
prometheus-client==0.14.1
|
112 |
+
prompt-toolkit==3.0.29
|
113 |
+
protobuf==4.0.0rc2
|
114 |
+
ptyprocess==0.7.0
|
115 |
+
pyaml==20.4.0
|
116 |
+
pyarrow==6.0.1
|
117 |
+
pyasn1==0.4.2
|
118 |
+
pycairo==1.16.2
|
119 |
+
pycparser==2.21
|
120 |
+
pycrypto==2.6.1
|
121 |
+
pycups==1.9.73
|
122 |
+
pydeck==0.6.2
|
123 |
+
Pygments==2.11.2
|
124 |
+
PyGObject==3.26.1
|
125 |
+
pymacaroons==0.13.0
|
126 |
+
Pympler==1.0.1
|
127 |
+
PyNaCl==1.1.2
|
128 |
+
pyparsing==2.4.7
|
129 |
+
pyRFC3339==1.0
|
130 |
+
pyrsistent==0.18.0
|
131 |
+
python-apt==1.6.5+ubuntu0.7
|
132 |
+
python-dateutil==2.8.2
|
133 |
+
python-debian==0.1.32
|
134 |
+
pytz==2018.3
|
135 |
+
pytz-deprecation-shim==0.1.0.post0
|
136 |
+
pyxdg==0.25
|
137 |
+
PyYAML==5.4.1
|
138 |
+
pyzmq==22.3.0
|
139 |
+
reportlab==3.4.0
|
140 |
+
requests==2.27.1
|
141 |
+
requests-unixsocket==0.1.5
|
142 |
+
responses==0.17.0
|
143 |
+
roman==2.0.0
|
144 |
+
rsa==3.4.2
|
145 |
+
s3transfer==0.5.2
|
146 |
+
screen-resolution-extra==0.0.0
|
147 |
+
SecretStorage==2.3.1
|
148 |
+
semver==2.13.0
|
149 |
+
Send2Trash==1.8.0
|
150 |
+
simplejson==3.13.2
|
151 |
+
six==1.16.0
|
152 |
+
smmap==5.0.0
|
153 |
+
streamlit==1.8.1
|
154 |
+
system-service==0.3
|
155 |
+
systemd-python==234
|
156 |
+
tb-nightly==1.14.0a20190603
|
157 |
+
tensorflow==2.0.0b1
|
158 |
+
termcolor==1.1.0
|
159 |
+
terminado==0.12.1
|
160 |
+
testpath==0.6.0
|
161 |
+
tf-estimator-nightly==1.14.0.dev2019060501
|
162 |
+
toml==0.10.2
|
163 |
+
toolz==0.11.2
|
164 |
+
tornado==6.1
|
165 |
+
tqdm==4.63.0
|
166 |
+
traitlets==4.3.3
|
167 |
+
typing-extensions==3.10.0.2
|
168 |
+
tzdata==2022.1
|
169 |
+
tzlocal==4.2
|
170 |
+
ubuntu-advantage-tools==27.4
|
171 |
+
ubuntu-drivers-common==0.0.0
|
172 |
+
ufw==0.36
|
173 |
+
unattended-upgrades==0.1
|
174 |
+
urllib3==1.26.8
|
175 |
+
usb-creator==0.3.3
|
176 |
+
userpath==1.7.0
|
177 |
+
validators==0.18.2
|
178 |
+
vboxapi==1.0
|
179 |
+
virtualenv==20.10.0
|
180 |
+
virtualenv-clone==0.5.7
|
181 |
+
wadllib==1.3.2
|
182 |
+
watchdog==2.1.7
|
183 |
+
wcwidth==0.2.5
|
184 |
+
webencodings==0.5.1
|
185 |
+
Werkzeug==2.0.0rc1
|
186 |
+
widgetsnbextension==3.6.0
|
187 |
+
wrapt==1.12.1
|
188 |
+
xkit==0.0.0
|
189 |
+
xxhash==3.0.0
|
190 |
+
yarl==1.7.2
|
191 |
+
zipp==3.6.0
|
192 |
+
zope.interface==4.3.2
|