adirik commited on
Commit
4069116
1 Parent(s): 9cf1e91

add precomputed directions

Browse files
README.md DELETED
@@ -1,13 +0,0 @@
1
- ---
2
- title: StyleMC Demo
3
- emoji: 🏢
4
- colorFrom: gray
5
- colorTo: pink
6
- sdk: gradio
7
- sdk_version: 3.14.0
8
- app_file: app.py
9
- pinned: false
10
- license: apache-2.0
11
- ---
12
-
13
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app.py CHANGED
@@ -1,3 +1,4 @@
 
1
  import gradio as gr
2
  import legacy
3
  import dnnlib
@@ -14,6 +15,7 @@ landmarks_path = "./pretrained/shape_predictor_68_face_landmarks.dat"
14
  e4e_embedder = psp_wrapper.psp_encoder(psp_encoder_path, landmarks_path)
15
  G_ffhq_path = "./pretrained/ffhq.pkl"
16
  G_metfaces_path = "./pretrained/metfaces.pkl"
 
17
 
18
  device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
19
 
@@ -34,6 +36,14 @@ FOOTER = 'This space is built by <a href = "https://github.com/catlab-team">Catl
34
  direction_map = {}
35
  direction_list = []
36
 
 
 
 
 
 
 
 
 
37
  def add_direction(prompt, stylegan_type, id_loss_w):
38
  new_dir_name = prompt+" "+stylegan_type+" w_id_loss"+str(id_loss_w)
39
  if (prompt != None) and (new_dir_name not in direction_list):
@@ -41,7 +51,7 @@ def add_direction(prompt, stylegan_type, id_loss_w):
41
  direction = find_direction.find_direction(G_dict[stylegan_type], prompt)
42
  print(f"new direction calculated with {stylegan_type} and id loss weight = {id_loss_w}")
43
  direction_list.append(new_dir_name)
44
- direction_map[new_dir_name]={"direction":direction, "stylegan_type":stylegan_type}
45
 
46
  return gr.Radio.update(choices=direction_list, value=None, visible=True)
47
 
 
1
+ import os
2
  import gradio as gr
3
  import legacy
4
  import dnnlib
 
15
  e4e_embedder = psp_wrapper.psp_encoder(psp_encoder_path, landmarks_path)
16
  G_ffhq_path = "./pretrained/ffhq.pkl"
17
  G_metfaces_path = "./pretrained/metfaces.pkl"
18
+ direction_folder = "./assets/directions/"
19
 
20
  device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
21
 
 
36
  direction_map = {}
37
  direction_list = []
38
 
39
+ directions = [f for f in os.listdir(direction_folder) if f.endswith(".npz")]
40
+ for d in directions:
41
+ with np.load(direction_folder + d) as data:
42
+ dir_name = f.split(".npz")[0]
43
+ direction_list.append(data["s"])
44
+ direction_map[dir_name] = {"direction": data["s"], "stylegan_type": "FFHQ"}
45
+
46
+
47
  def add_direction(prompt, stylegan_type, id_loss_w):
48
  new_dir_name = prompt+" "+stylegan_type+" w_id_loss"+str(id_loss_w)
49
  if (prompt != None) and (new_dir_name not in direction_list):
 
51
  direction = find_direction.find_direction(G_dict[stylegan_type], prompt)
52
  print(f"new direction calculated with {stylegan_type} and id loss weight = {id_loss_w}")
53
  direction_list.append(new_dir_name)
54
+ direction_map[new_dir_name] = {"direction":direction, "stylegan_type":stylegan_type}
55
 
56
  return gr.Radio.update(choices=direction_list, value=None, visible=True)
57
 
.DS_Store → assets/.DS_Store RENAMED
Binary files a/.DS_Store and b/assets/.DS_Store differ
 
assets/directions/.DS_Store ADDED
Binary file (6.15 kB). View file
 
assets/directions/photo_of_a_face_with_beard.npz ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4e1b9a508339550ca0d479ac09db76d600db173e8fec6a40b7b82c240b8889c6
3
+ size 53504
assets/directions/photo_of_a_face_with_blonde_hair.npz ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8cbf362827734953aa1b67bee79928b53d98342a439165c73926c65189be3389
3
+ size 53504
assets/directions/photo_of_a_face_with_curly_hair.npz ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:827407ced6a64889d368f0acabb94d24ee88be3efe77848e77b771db7e65e6ac
3
+ size 53504
assets/directions/photo_of_a_face_with_long_hair.npz ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:737ce411fadf60d40f5384007fbd556335f3800b8a7b006e459adbfbb90f462a
3
+ size 53504
assets/directions/photo_of_a_frowning_face.npz ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:23d7248ac893c249eb44d11bbe79f91ad469049a20ade43cfba3e55cdad02283
3
+ size 53504
assets/directions/photo_of_a_happy_face.npz ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5b3990c63d44e52cbe8d73f40f07a0b1dbb9d309cbac032427d316698d4fa94e
3
+ size 53504
assets/directions/photo_of_a_relieved_face.npz ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e0bcde1467755880f0df47839031f10c82eb93b0ecf03e8e217360c396001cad
3
+ size 53504
assets/directions/photo_of_a_tanned_skin_face.npz ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:56613c2f6a3844681370e1939f20dea62b339a78c4a48380f27244e196e23dd1
3
+ size 53504
assets/directions/photo_of_an_excited_face.npz ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c4d7b528ac1e3c9391a826470b61dfa8e0db8a44adcd9b52a8ab027c37c4259d
3
+ size 53504
pretrained/.DS_Store CHANGED
Binary files a/pretrained/.DS_Store and b/pretrained/.DS_Store differ