Comments (5)
Hi, could you please provide a minimum reproducible code to help with debug?
Notice that we may need to use different style codes for AnycostGAN and StyleGAN. If you use the style code from AnycostGAN with StyleGAN, it might reproduce weird results.
from anycost-gan.
thank! When I used style codes for StyleGAN, the bug is solved.
But I found another problem when changing the output resolution.
For StyleGAN, when use the default resolution the output image is perfect
But when chang the output resolution such as self.generator.target_res = 256 the output image go wrong.
from anycost-gan.
Could you provide a code segment to reproduce the issue?
from anycost-gan.
from glob import glob
import torch
import numpy as np
import os
from PIL import Image
import models
class FaceEditor:
def __init__(self, config, device, anycost_resolution=1024, n_style_to_change=12):
# load assets
self.device = device
self.anycost_channel = 1.0
self.anycost_resolution = anycost_resolution
self.n_style_to_change = n_style_to_change
# build the generator
self.generator = models.get_pretrained('generator', config).to(device)
self.generator.eval()
self.generator.target_res = anycost_resolution # set resolution
# self.generator.target_res = self.anycost_resolution
self.mean_latent = self.generator.mean_style(10000)
# select only a subset of the directions to use
direction_map = {
'smiling': '31_Smiling',
'young': '39_Young',
'wavy hair': '33_Wavy_Hair',
'gray hair': '17_Gray_Hair',
'blonde hair': '09_Blond_Hair',
'eyeglass': '15_Eyeglasses',
'mustache': '22_Mustache',
}
boundaries = models.get_pretrained('boundary', config)
self.direction_dict = dict()
for k, v in boundaries.items():
self.direction_dict[k] = v.view(1, 1, -1)
def generate_image(self, save_path, input_kwargs):
def image_to_np(x):
assert x.shape[0] == 1
x = x.squeeze(0).permute(1, 2, 0)
x = (x + 1) * 0.5 # 0-1
x = (x * 255).cpu().numpy().astype('uint8')
return x
with torch.no_grad():
out = self.generator(**input_kwargs)[0].clamp(-1, 1)
out = image_to_np(out)
out = np.ascontiguousarray(out)
img_pil = Image.fromarray(out)
img_pil.save(save_path)
def edit(self, latent_code_path, attr_sliders, force_full_g=False):
latent_code = torch.from_numpy(np.load(os.path.join(latent_code_path))).view(1, -1, 512).to(self.device)
# input kwargs for the generator
edited_code = latent_code.clone()
for direction_name in attr_sliders.keys():
edited_code[:, :self.n_style_to_change] = edited_code[:, :self.n_style_to_change] \
+ attr_sliders[direction_name] * self.direction_dict[
direction_name].to(self.device)
edited_code = edited_code.to(self.device)
return latent_code, edited_code
if __name__ == '__main__':
gan_config = 'stylegan2-ffhq-config-f'
fe = FaceEditor(config=gan_config, anycost_resolution=512, device='cuda:0')
# fe = FaceEditor(config=gan_config, device='cuda:0')
attr_sliders = {
'31_Smiling': 0.2
}
latent_path = "demo.npy"
ori, edit = fe.edit(latent_code_path=latent_path, attr_sliders=attr_sliders)
ori_kwargs = {'styles': ori, 'noise': None, 'randomize_noise': False, 'input_is_style': True}
edit_kwargs = {'styles': edit, 'noise': None, 'randomize_noise': False, 'input_is_style': True}
fe.generate_image(save_path="origin.png", input_kwargs=ori_kwargs)
fe.generate_image(save_path="edit.png", input_kwargs=edit_kwargs)
demo.npy is here : https://drive.google.com/file/d/1cx_6epZjIH9uoADo744ySQQan15dL4Fa/view?usp=sharing
this is the output image
when changing anycost_resolution to 1024 the image turn to
from anycost-gan.
Hi, sorry for the late reply. You are using the original StyleGAN2 instead of AnycostGAN.
You need to replace gan_config = 'stylegan2-ffhq-config-f'
with gan_config = 'anycost-ffhq-config-f'
.
I tested it and it works normally, so I will close the issue for now. But feel free to reopen if you encounter other problems.
from anycost-gan.
Related Issues (20)
- Custom image editing HOT 3
- How to compute MACs and flops HOT 1
- Any plan to support s space manipulation? HOT 2
- how to save , when runned python demo.py , edited face picture HOT 2
- Default parameters for project.py do not recreate projected latents in assets/demo/projected_latents HOT 1
- checkpoint for mult-resolution training HOT 5
- 生成图全是灰色 HOT 5
- Using this tool for another LSUN dataset + model HOT 5
- Recommendations on speeding up tools/project.py HOT 1
- in extract_edit_directions.py HOT 1
- using win run demo.py need cuda but cant using force-native=1 HOT 8
- Could you please provide pre-trained boundaries of 'stylegan2-ffhq-config-f'? HOT 1
- Colab Error Invalid Syntax keys_list.append(f'{int(cfg['macs'] * 100. / full_macs)}%') HOT 1
- Error on loading pretrained model HOT 1
- is this a bug? HOT 4
- Color difference in generated image for stylegan2-ffhq-config-f model HOT 1
- Using My Face
- Share the pretrained anycost Discriminator
- Need help editing my own uploaded images
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from anycost-gan.