-
Notifications
You must be signed in to change notification settings - Fork 44
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
Lacking documentation on how to create the average latent file #19
Comments
You can take a look at issue #10 where there is more explanation of the more difficult parts to understand in relation to these configuration files. However, it is certain that in my opinion, it would be a good idea to have an official document about them. Note that you will need to code some parts by yourself in order to get the "avg_latent_stylegan1.npy", "latent_stylegan1.npy" files and the converted weights file (Tensorflow to PyTorch) of the pre-trained StyleGAN (if you have trained your own StyleGAN) (see issu #1). (At least for now, there is no file related to all of these parts on this Github). |
@PoissonChasseur, agreed that documentation on how to do these pieces, "avg_latent_stylegan1.npy" and "latent_stylegan1.npy", would be good. I trained my own StyleGAN using https://github.com/NVlabs/stylegan2-ada-pytorch, and it's not clear to me how I would go about getting or creating "avg_latent_stylegan1.npy" and "latent_stylegan1.npy". @PoissonChasseur, if you have any further advice---I already read issue #10 and #1---or experience, please do share. Otherwise, I hope NVIDIA will be able to improve the docs. |
So from what was described in issue #10 and what I also used in my case with a StyleGAN V1 (this should also be valid for the StyleGAN V2, but I haven't read the research yet nor the code on the StyleGAN2-Ada):
Note that if your initial issue with deciding to choose StyleGAN2-Ada is the convertion of the file of the pre-trained StyleGAN between Tensorfkow and PyTorch, I had no issues related to this via the link provided in issue #1 . But it is certain that the use of a better version of the StyleGAN will also add other elements to be adjusted in the code (for example, the fact that the DatasetGAN works with the features of the StyleGAN and not with the output images = the name and position of the layers to use will probably change). Anyway, I'll be interested to see the final code related to all of this once that's done, as probably a lot of other people :). I hope that all my explanations will help you on certain points. |
@PoissonChasseur, this is very helpful! I'm going to have to re-read what you wrote another 10 or 20 times, and then do more digging through the architecture. I'll probably reply later today with more questions. Hopefully someone from NVIDIA will want to answer these questions. Practically speaking, I still don't know how to generate "avg_latent_stylegan1.npy" and "latent_stylegan1.npy" from any of the StyleGAN repos. It'd be very helpful to have working code/examples/documentation that shows how to generate these files from at least one of the four StyleGAN repos (shown below).
|
Overall, at least in the case of StyleGAN V1 ( https://github.com/NVlabs/stylegan ) which I used and by also using the same notation as in the code of the "train_interpreter.py" file from this Github:
I hope you are now better able to implement your own implementation of all of these parts. If you haven't already, I strongly suggest that you read the StyleGAN V1 paper first, then read and understand all the code in the "train_interpreter.py" file on this Github, before you start implementing all of these steps. |
Hello, I am also trying my hand at training StyleGAN/DatasetGAN for a custom dataset I have and wanted to share something. I don't know if it's the correct way to do it but it seems to have worked out quite fine for me. I think you can obtain the average latent code from a trained StyleGAN by doing a forward pass on any sample (i.e. random latent code) and getting what's stored in the appropriate variable as Edit: I only worked on StyleGAN, so I don't know if what I said translates to StyleGANv2 as well.
|
@PoissonChasseur, that's helpful. Can you please elaborate more about bullet 1 - 3 of step 2? Example code would be helpful. |
@ericchansen : For step 2, bullet 1 and 3, like I said in step 1, you can look at what is done in this link: https://github.com/lernapparat/lernapparat/blob/master/style_gan/pytorch_style_gan.ipynb (manually copy and paste the link if it does not go to the corresponding page) If you compare the code in this reference with the one used in the DatasetGAN, you will see that most of the code related to the different layers is exactly the same. So, you can simply start from cell 11 ("In [11]:") and call on the StyleGAN layer classes which are defined in the DatasetGAN files (no need to copy and paste those defined in this reference to make it work and is also preferable to do so at my sense at this point). This reference also explains directly how to use the pre-trained StyleGAN to generate images using random "latent_code". Extracting the part of the StyleGAN related to the "mapping network" (g_mapping) (see cell 11) should also be pretty clear there, as they also build the 3 main parts of the StyleGAN which you will need after that for the DatasetGAN. |
To re-iterate the issue, this repo is currently missing documentation on two required input files. In the configuration files (https://github.com/nv-tlabs/datasetGAN_release/tree/master/datasetGAN/experiments), they're called "average_latent" and "annotation_image_latent_path". There is no documentation or example code on how to create these files. Here's my solution. I think that anyone should be able to use this code to create "average_latent" and "annotation_image_latent_path" for their own datasets. For the imports in this piece of code to "play nice", put it into the "utils" directory.
Also, since my code uses a logging configuration file, here's an example of that file.
@arieling or other folks from NVIDIA, is this the correct approach? Someday, I'll open up a PR with this and updates to the README to include the missing steps. |
For those out there who are wondering how they can use DatasetGAN with their own datasets, PR #21 should help. I still think that
before we close this issue. |
Hi, thank you for pointing this out. We update the doc in the section "Create your own model" to explain the npy cache files. |
For your specific confusion about average_latent.npy. This is used for sampling truncation. We dump the average latent code to .npy file mainly for academic reproduction reasons. For your convenience, we implemented a simple function in https://github.com/nv-tlabs/datasetGAN_release/blob/master/datasetGAN/make_training_data.py#L81 to dump the average latent. Please refer to StyleGAN V1 ( https://github.com/NVlabs/stylegan ) code and paper [1] for more details [1] A Style-Based Generator Architecture for Generative Adversarial Networks, Tero Karras, Samuli Laine, Timo Aila |
Good enough! |
The example configuration files (https://github.com/nv-tlabs/datasetGAN_release/tree/master/datasetGAN/experiments), ex. "cat_16.json" or "car_20.json", contain a field named "average_latent" and "annotation_image_latent_path". Both of these fields are paths to .npy files.
This repo does not describe how these files are generated. Even after one trains a StyleGAN model, one cannot then use DatasetGAN without these files. Please provide documentation on how to create this file for a custom dataset.
I imagine that you'd want to provide examples using your up-to-date repos, ex. https://github.com/NVlabs/stylegan2-ada-pytorch and/or https://github.com/NVlabs/stylegan2-ada.
The text was updated successfully, but these errors were encountered: