felixrosberg commited on
Commit
4021817
β€’
1 Parent(s): 04e62ee

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -2
app.py CHANGED
@@ -39,6 +39,14 @@ G = load_model("g_model_c_hq/generator_t_28.h5", custom_objects={"AdaIN": AdaIN,
39
  "AdaptiveAttention": AdaptiveAttention,
40
  "InstanceNormalization": InstanceNormalization})
41
 
 
 
 
 
 
 
 
 
42
  blend_mask_base = np.zeros(shape=(256, 256, 1))
43
  blend_mask_base[80:246, 32:224] = 1
44
  blend_mask_base = gaussian_filter(blend_mask_base, sigma=7)
@@ -84,12 +92,15 @@ def run_inference(target, source, slider, settings):
84
  im_aligned = cv2.warpAffine(im, M, (256, 256), borderValue=0.0)
85
 
86
  if "anonymize" in settings:
87
- source_z = ArcFace.predict(np.expand_dims(tf.image.resize(im_aligned, [112, 112]) / 255.0, axis=0))
88
  anon_ratio = int(512 * (slider / 100))
89
  anon_vector = np.ones(shape=(1, 512))
90
  anon_vector[:, :anon_ratio] = -1
91
  np.random.shuffle(anon_vector)
92
- source_z *= anon_vector
 
 
 
93
 
94
  # face swap
95
  changed_face_cage = G.predict([np.expand_dims((im_aligned - 127.5) / 127.5, axis=0),
 
39
  "AdaptiveAttention": AdaptiveAttention,
40
  "InstanceNormalization": InstanceNormalization})
41
 
42
+ permuter_repo = Repository(local_dir="identity_permuter", clone_from="felixrosberg/identitypermuter",
43
+ private=True, use_auth_token=token, git_user="felixrosberg")
44
+
45
+ from identity_permuter.id_permuter import identity_permuter
46
+ IDP = identity_permuter(emb_size=32, min_arg=False)
47
+ IDP.load_weights("identity_permuter/id_permuter.h5")
48
+
49
+
50
  blend_mask_base = np.zeros(shape=(256, 256, 1))
51
  blend_mask_base[80:246, 32:224] = 1
52
  blend_mask_base = gaussian_filter(blend_mask_base, sigma=7)
 
92
  im_aligned = cv2.warpAffine(im, M, (256, 256), borderValue=0.0)
93
 
94
  if "anonymize" in settings:
95
+ """source_z = ArcFace.predict(np.expand_dims(tf.image.resize(im_aligned, [112, 112]) / 255.0, axis=0))
96
  anon_ratio = int(512 * (slider / 100))
97
  anon_vector = np.ones(shape=(1, 512))
98
  anon_vector[:, :anon_ratio] = -1
99
  np.random.shuffle(anon_vector)
100
+ source_z *= anon_vector"""
101
+
102
+ source_z = ArcFace.predict(np.expand_dims(tf.image.resize(im_aligned, [112, 112]) / 255.0, axis=0))
103
+ source_z = IDP.predict(source_z)
104
 
105
  # face swap
106
  changed_face_cage = G.predict([np.expand_dims((im_aligned - 127.5) / 127.5, axis=0),