junyanz / pytorch-CycleGAN-and-pix2pix

Image-to-Image Translation in PyTorch
Other
22.88k stars 6.3k forks source link

How batchSize affect the quality of the generated image on pix2pix? #272

Open happsky opened 6 years ago

happsky commented 6 years ago

I have about 220,000 image pairs, do you have any suggestions to set batchSize, number of GPU, number of epoch and so on for training. I'm worrying about larger batchSize (such as 72) may degrade the quality of the generated image, is this right?

phillipi commented 6 years ago

In my experience the important thing is to have the test setting exactly match the train setting. One way to do this is to use the same batch size at both train and test. Another way would be instance norm. Or “virtual batch norm”. Or anneal the contribution of the current iter's stats to zero, etc. As long as train and test conditions are iid, you will likely be in good shape!

happsky commented 6 years ago

Thanks for your quick reply @phillipi and I have another question that when I training on pix2pix, the loss_D_fake, loss_D_real and loss_G_GAN are equal to 0, is this a normal phenomenon and why does this happen?

junyanz commented 6 years ago

This is not normal. Could you first try to train a pix2pix model on a given dataset (e.g. facades) and then try to adapt it to your own dataset? Also try batchSize=1 first.

Gavin666Github commented 6 years ago

Have anyone come accross this phenomenon? size of my training datasets is 20000 pairs my configuration with params: --batchSize 64 --no_html --nThreads 16 --niter 800 --niter_decay 8000 --epoch_count 729 --gpu_ids 0,1,3 --continue_train

loss like this ,and the generated images sometimes looks terrible image

How can I adjust some parameters to repair these problems?many thanks

junyanz commented 6 years ago

hmm, it's hard to tell without seeing the data and tasks. Could you try batchSize 1 with 1 GPU?

nidetaoge commented 6 years ago

I have faced the same phenomenon. When discriminator loss goes down to 0 and repeats periodically, the results of the generator look terrible. And in this case L1 loss doesn't go down all the time. I faced this when I added another branch or another loss, like perceptural loss or adding another branch to make FC and regression loss. Though this added loss looks normal, it seems D easily judges the generated outputs when loss goes to 0, no matter what namda I give it to FC_weight to match l1_weight and gan_weight. Look like this, the first is the normal loss, the second is when I add FC loss. 1 Fig1.

2 Fig2.

John1231983 commented 5 years ago

@nidetaoge : I also have same problem when add other loss. The D loss goes to zero and the generator loss goes up. How do you solve the issue?

ZHE-SAPI commented 2 years ago

Hello! I trained for 40 epochs, batch_size=1, but the loss function of the generator does not seem to converge, why is this? Can you please provide some advice, thanks

wendellgithub0206 commented 1 year ago

你好!我訓練了40個epochs,batch_size=1,但是生成器的損失函數好像沒有收斂,這是為什麼呢?能否請您提供一些建議,謝謝

-For the generator, its Loss drops rapidly, and it is likely that the discriminator is too weak, causing thegenerator to easily "fool" the discriminator. -For the discriminator, the Loss drops quickly, which means that the discriminator is very strong, and thestrong discriminator means that the image generated by the generator is not realistic enough, which makesit easy for the discriminator to distinguish, resulting in a rapid loss of loss. -In other words, whether it is a discriminator or a generator. The level of loss does not represent the quality ofthe generator. For a good GAN network, its GAN Loss is often fluctuating.