NVlabs / stylegan2-ada-pytorch

StyleGAN2-ADA - Official PyTorch implementation
https://arxiv.org/abs/2006.06676
Other
4.12k stars 1.17k forks source link

Conditional GAN- How to do it in stylegan2 #111

Open yuki4ghub15 opened 3 years ago

yuki4ghub15 commented 3 years ago

Hello, How to train stylegan2 with conditional mode. that is, in addition to training samples (set A), the style of the GAN generated image will be controlled by reference images (Set B). So style of GAN simulated image (Set C) will be based on Set B. What does this argument do, and how to prepare the labels, --cond=1 enables class-conditional training (requires a dataset with labels).

thanks in advance to your help.

hkhailee commented 3 years ago

I also am wondering the same thing. If someone has a labeled dataset with conditions such as eye color: green dataset, blue dataset, brown dataset. Can the style gan with the --cond argument be given to learn this? Any direction is some direction.

PDillis commented 3 years ago

You need to use the dataset_tool.py script to convert your conditional dataset into a zip file before running the training. To prepare your dataset to be conditional, you will need to have a dataset.json file inside your directory with your images, and in it, you will have the paths and label of each image. A small example is as follows (I separate each class in their respective subdirectory, but this isn't necessary, you just need the path to the image):

{
    "labels":
        [
            ["folder1/1.jpg", 0], ["folder1/2.jpg", 0], ["folder1/3.jpg", 0], 
            ["folder2/4.jpg", 1], ["folder2/5.jpg", 1], ["folder2/6.jpg", 1], 
            ["folder3/7.jpg", 2], ["folder3/8.jpg", 2], ["folder3/9.jpg", 2], 
        ]
}

The classes are quite simple, just an integer, so I'm sure you can first separate each subdirectory by classes and then use a small script to get these lists of path/class pairs. With this, once you start training, a new dataset.json file will be created inside the zip file that dataset_tool.py creates, but the names/paths of the images will be of course altered, so the above will become:

{
    "labels": 
        [
            ["00000/img00000000.png", 0], ["00000/img00000001.png", 0], ["00000/img00000002.png", 0],     
            ["00000/img00000003.png", 1], ["00000/img00000004.png", 1], ["00000/img00000005.png", 1],     
            ["00000/img00000006.png", 2], ["00000/img00000007.png", 2], ["00000/img00000008.png", 2]
        ]
}

(not necessarily ordered of course, it depends on how you load the data, but I hope this helps). Check the docstring in the dataset_tool.py script if you have more doubts.

JulianPinzaru commented 3 years ago

I can post the script I made to create that dataset.json with labels. Please let me know.

zjgt commented 3 years ago

I can post the script I made to create that dataset.json with labels. Please let me know.

Yes, please.

jazz-ai commented 3 years ago

I can post the script I made to create that dataset.json with labels. Please let me know.

@JulianPinzaru Can you please post the script to create dataset.json file with labels?

JulianPinzaru commented 3 years ago

@jazz-ai Sure, I will do it today. Sorry @SamTransformer I didn't remember to do it

JulianPinzaru commented 3 years ago

@jazz-ai , @SamTransformer , here you go https://github.com/JulianPinzaru/stylegan2-ada-pytorch-multiclass-labels Please remember to leave me a star on the repo, thanks :)

zjgt commented 3 years ago

Awesome, thanks!

On Tue, Oct 5, 2021 at 6:51 PM JulianPinzaru @.***> wrote:

@jazz-ai https://github.com/jazz-ai , @SamTransformer https://github.com/SamTransformer , here you go https://github.com/JulianPinzaru/stylegan2-ada-pytorch-multiclass-labels Please remember to leave me a star on the repo, thanks :)

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/NVlabs/stylegan2-ada-pytorch/issues/111#issuecomment-934973719, or unsubscribe https://github.com/notifications/unsubscribe-auth/AQSBAG6KOD4RX26JB75RFLTUFN6OJANCNFSM45AHJNPA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

jazz-ai commented 3 years ago

@jazz-ai , @SamTransformer , here you go https://github.com/JulianPinzaru/stylegan2-ada-pytorch-multiclass-labels Please remember to leave me a star on the repo, thanks :)

Perfect, thanks @JulianPinzaru

dongyun-kim-arch commented 2 years ago

@PDillis Hello! Thanks for your explanation! I am trying to train multi-label conditional stylegan, using multiple conditions such as 'haircolor', 'gender', 'age'. Thus, my dataset.json looks like

{ "labels": [ ["folder1/1.jpg", [2, 1, 30]], ["folder1/2.jpg", [7, 1, 40]], ["folder1/3.jpg", [9, 1, 70]], ["folder2/4.jpg", [5, 0, 32]], ["folder2/5.jpg", [12, 1, 33], ["folder2/6.jpg", [13, 0, 12]], ["folder3/7.jpg", [1, 0, 12]], ["folder3/8.jpg", [2, 9, 64]], ["folder3/9.jpg", [2, 1, 8]], ] }

But, when I train the model, it said Error: --cond=True requires labels specified in dataset.json. I am guessing there are some problems with these multiple labeling.... but couldn't know where I am wrong. Could you point out what should I do make it work?

Thanks!

RyanRogersMicrosoft commented 1 year ago

@dongyun-kim-arch Did you ever get this multi-label conditional stylegan label issue resolved?

Gokul14092001 commented 1 year ago

@PDillis Hello! Thanks for your explanation! I am trying to train multi-label conditional stylegan, using multiple conditions such as 'haircolor', 'gender', 'age'. Thus, my dataset.json looks like

{ "labels": [ ["folder1/1.jpg", [2, 1, 30]], ["folder1/2.jpg", [7, 1, 40]], ["folder1/3.jpg", [9, 1, 70]], ["folder2/4.jpg", [5, 0, 32]], ["folder2/5.jpg", [12, 1, 33], ["folder2/6.jpg", [13, 0, 12]], ["folder3/7.jpg", [1, 0, 12]], ["folder3/8.jpg", [2, 9, 64]], ["folder3/9.jpg", [2, 1, 8]], ] }

But, when I train the model, it said Error: --cond=True requires labels specified in dataset.json. I am guessing there are some problems with these multiple labeling.... but couldn't know where I am wrong. Could you point out what should I do make it work?

Thanks!

have you solved this? please let me know how to do this?

Zhangzh721 commented 12 months ago

How does the label enter the network when Cond=ture is opened? Does stylegan2 belong to conditional gan or non conditional gan at this time?