stylegan2-pytorch icon indicating copy to clipboard operation
stylegan2-pytorch copied to clipboard

conditional implementation

Open PieraRiccio opened this issue 4 years ago • 15 comments

Hi, did you also implement a conditional implementation, so that I can pass files with labels, as in the original TensorFlow implementation?

PieraRiccio avatar Dec 20 '20 10:12 PieraRiccio

@PieraRiccio Hey Piera! I haven't implemented the conditional part yet

I would have to think about how this could work as a CLI before moving forward. Perhaps I could ask for the labels as some standard data format that matches the filename of the images, and then have an extra flag for passing in the labels file

lucidrains avatar Dec 20 '20 18:12 lucidrains

@lucidrains Hi. :) Thank you for your answer. I think that a usual modality to do that is to retrieve the labels from subfolders of the main images folder. What do you think about this?

In order to run conditional training in the official TF implementation, I used the code shared in this issue, maybe it can be helpful: https://github.com/NVlabs/stylegan2-ada/issues/22

PieraRiccio avatar Dec 21 '20 10:12 PieraRiccio

Sure, that works! How do you have your files -> label organized at the moment?

lucidrains avatar Dec 21 '20 18:12 lucidrains

I have a main folder and 4 sub-folders (which correspond to the 4 labels) :)

PieraRiccio avatar Dec 21 '20 19:12 PieraRiccio

@PieraRiccio oh that may work! let me think about it before executing on the code

lucidrains avatar Dec 21 '20 23:12 lucidrains

@PieraRiccio so I looked over the official code, and it seems like labels are consumed by the generator and discriminator in the following way

in both G and D, the label id is first projected to the feature map size and normalized

in the generator, it is concatenated to the latent vector before being passed through the mapping network

in the discriminator, it seems to be also passed through a separate mapping network https://github.com/NVlabs/stylegan2-ada/blob/main/training/networks.py#L520, but the number of layers is defaulted to 0, so I'm not sure if it is being used. in the end, it is multiplied with the image embedding just before the output https://github.com/NVlabs/stylegan2-ada/blob/main/training/networks.py#L619

lucidrains avatar Dec 22 '20 21:12 lucidrains

@lucidrains cc @PieraRiccio I have a very dirty attempt at the conditional logic https://github.com/foobar8675/stylegan2-pytorch/tree/dev, running on cifar100 right now.

matthewchung74 avatar Jan 04 '21 00:01 matthewchung74

@foobar8675 Amazing Matthew! :100: :100:

lucidrains avatar Jan 04 '21 18:01 lucidrains

@foobar8675 Thank you! :)

PieraRiccio avatar Jan 04 '21 20:01 PieraRiccio

I've been trying to run on cifar100, which was probably not realistic (only 600 images / class) . starting again with cifar10 like the nvidia guys did. not sure how much it matters, but am running with these flags.

python -m stylegan2_pytorch.cli --results_dir /tmp --models_dir /tmp 
--aug-prob 0.25 
--aug-types [translation,cutout,color] 
--dataset-aug-prob .5  
--trunc-psi 0.75 
--top-k-training 
--attn-layers [1,2] 
--batch-size 16
--data ../datasets/cifar10/train/ --name cifar10 

step 8884, with 2 rows manually annotated: 8

(48 hrs later) i stopped the training after 4 days. it didn't seem to be any better than what was posted above.

matthewchung74 avatar Jan 06 '21 01:01 matthewchung74

@foobar8675 Given the small number of images for each label, have you also tried using adaptive discriminator augmentation? :)

PieraRiccio avatar Jan 14 '21 22:01 PieraRiccio

@PieraRiccio thanks for the suggestion. I have not, but I do have augmentation set to .25. My understanding, which might be wrong, is that ADA will kick in with augmentation if it senses augmentation is needed and otherwise not augment. since I have augmentation always set, I'm not sure if it would help?

However, I might be misunderstanding. Do you have any thoughts?

matthewchung74 avatar Jan 14 '21 23:01 matthewchung74

@matthewchung74 This: https://github.com/lucidrains/stylegan2-pytorch/issues/194#issuecomment-753704441 looks very cool, exactly what I need... but the link no longer works. Is this still available anywhere? Thanks.

BrentOGara avatar Apr 15 '21 07:04 BrentOGara

@BrentOGara unfortunately, i deleted that repo, since it wasn't quite as good as what I wanted. if you are looking for a conditional stylegan2, nvidia's implementation supports it. https://github.com/NVlabs/stylegan2-ada-pytorch

matthewchung74 avatar Apr 15 '21 17:04 matthewchung74

@matthewchung74 Thank you for the link, I'll see if I can figure it out. I'm still very new to this field.

BrentOGara avatar Apr 18 '21 03:04 BrentOGara