stylegan-web
stylegan-web copied to clipboard
Enhancement - Feature load / save / find latent_representations / augmentation
https://github.com/jasonlbx13/FaceHack/blob/b4beda81354806a13efe3c992d819fc6a9f83d65/face_gan/main.py
Given an existing star / celebrity load / save
this code could be put into a pipeline / for subparsers maybe it may have to look like photoshop layers (will raise another ticket)
def augmentation(args):
os.makedirs(args.dst_dir+'/augmentation', exist_ok=True)
print('Loading networks from "{}"...'.format(args.network_pkl))
tflib.init_tf()
with open(args.network_pkl, "rb") as f:
generator_network, discriminator_network, Gs_network = pickle.load(f)
Gs_syn_kwargs = dnnlib.EasyDict()
Gs_syn_kwargs.output_transform = dict(func=tflib.convert_images_to_uint8, nchw_to_nhwc=True)
Gs_syn_kwargs.randomize_noise = False
Gs_syn_kwargs.minibatch_size = 1
pic = np.load(args.src_dir)
for i in tqdm(range(int(args.num))):
scale1 = random.uniform(-float(args.smile_range), float(args.smile_range))
scale2 = random.uniform(-float(args.age_range), float(args.age_range))
scale3 = random.uniform(-float(args.angleh_range), float(args.angleh_range))
scale4 = random.uniform(-float(args.anglep_range), float(args.anglep_range))
scale5 = random.uniform(-float(args.angry_range), float(args.angry_range))
scale6 = random.uniform(-float(args.sad_range), float(args.sad_range))
scale7 = random.uniform(-float(args.eye_range), float(args.eye_range))
latent_vector = pic[np.newaxis, :]
new_latent_vector = latent_vector.copy()
new_latent_vector[0][:8] = (latent_vector[0] + scale1 * smile_drt + scale2 * age_drt
+ scale3 * angleh_drt + scale4 * anglep_drt
+ scale5 * angry_drt + scale6 * sad_drt
+ scale7 * eye_drt)[:8]
img = Gs_network.components.synthesis.run(new_latent_vector, **Gs_syn_kwargs)
img = PIL.Image.fromarray(img[0])
img.save('{}/augmentation/{}.png'.format(args.dst_dir, str(i).zfill(4)))
This FaceHack's website seems very ambitious, interesting. I will pay attention on them. Thank you.