-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to do style mixing quickly? #6
Comments
Hi, using our code, you can also do style mixing. However, you unfortunately used the wrong script for this. Hope this helps! |
Thank you for your suggestions. This is what I tried but my results look almost the same as the input image with only slight color changes if I swap the latent layers. My results look like one image overlay on top of another if I swap the noise layers. Please kindly let me know what I may have missed. In networks/encoder/autoencoder.py, I changed to the following. reconstructed_x, latent = self.decoder([latent_codes.latent], input_is_latent=self.is_wplus(latent_codes), noise=latent_codes.noise, return_latents=True)
return reconstructed_x, latent, latent_codes.noise My changes in def reconstruct(path, config, device, autoencoder):
input_image = Path(path)
data_loader = build_data_loader(input_image, config, config['absolute'], shuffle_off=True, dataset_class=DemoDataset)
image = next(iter(data_loader))
image = {k: v.to(device) for k,v in image.items()}
return autoencoder(image['input_image'])
content_image, content_latent, content_noise = reconstruct(args.content_image, config, args.device, autoencoder)
style_image, style_latent, style_noise = reconstruct(args.style_image, config, args.device, autoencoder)
for layer_id in args.styles:
content_latent[:, layer_id, :] = style_latent[:, layer_id, :]
image, _ = autoencoder.decoder(
[content_latent], input_is_latent=True, noise=content_noise, return_latents=True
)
image = Image.fromarray(make_image(image.squeeze(0)))
image.save('out.png') |
Your changes look good so far. Right now, you are running into a fundamental problem with our approach. If you train an autoencoder without any special care, the latent code will be degraded to plain color encoding, the heavy lifting for reconstruction is done by the noise inputs (as we have shown in the paper). However, there are two possible solutions that you can try (I'm not 100% sure they will work):
|
I am trying to do style mixing between two images using
file_based_simple_style_transfer.py
with the following command, but it takes a couple of minutes to optimize and the artifacts are noticeable in the results. Reducing thelatent-step
or thenoise-step
makes the results worse.python file_based_simple_style_transfer.py --content img1.png --style img2.png --mixing-index -1 --destination . --config trained_model/ffhq_stylegan_2_w_plus/2020-09-05T16:09:10.557656/config/config.json --latent-step 5000 --noise-step 3000
The official StyleGAN implementation can do style mixing by swapping some layers of the
w
variables and I tried to do the same by swapping some layers of the noise variables of two images. All I got are two images overlaying on top of each other.How should I do style mixing with a good balance between performance and fidelity?
The text was updated successfully, but these errors were encountered: