harskish / ganspace

Discovering Interpretable GAN Controls [NeurIPS 2020]
Apache License 2.0
1.78k stars 264 forks source link

Added colab example #7

Closed sdtblck closed 4 years ago

sdtblck commented 4 years ago

Added an example colab notebook exploring stylegan2 networks using ganspace results for those of us without beefy GPUs.

woctezuma commented 4 years ago

I would suggest to suppress some outputs, typically the very long logs, because it makes it more cumbersome than necessary to read the notebook: I have to scroll a lot.

harskish commented 4 years ago

Thank you @sdtblck for the contribution! A few comments:

Using the pytorch models is super easy:

from models import get_model

model = get_model('StyleGAN2', 'ffhq', torch.device('cuda'), use_w=True)
w = model.sample_latent(1, seed=seed).cpu().numpy()
w = [w]*model.get_max_latents() # one per layer

# Edit
for l in range(start, end):
    w[l] = w[l] + lat_comp[idx]*lat_std[idx]*delta

out = model.sample_np(w)

I'd be happy to merge once these things are fixed. Let me know if you have questions or need assistance!

sdtblck commented 4 years ago

Hey!

Thanks for the feedback. I put the notebook together very quickly just for personal use, hence the roughness. The exploration does look much simpler in pytorch I just wasn't at all familiar with the interface, so thanks for that snippet of code.

sdtblck commented 4 years ago

This should work!

No need to mess with conda/environment files at all in the end

harskish commented 4 years ago

I've modified the notebook to use (start, end) instead of (start, start + n_layers), since that matches the rest of the codebase better.

There's one more thing I still want to fix: the layer ranges of named edits are currently not stored, which means that the final widget where saved edits are used might not work as intended.

sdtblck commented 4 years ago

Ok, quite a simple fix - just added the layer ranges to the named directions dict. This should work fine. It would be nice also to have a slider controlling each direction, but I'm not handy enough with the ipnyb widgets to get that to work, and it's probably better to do that on your GUI anyway.

harskish commented 4 years ago

Awesome, looks good. Thanks a lot for your contribution Sid, will merge this now!