pytorch-CycleGAN-and-pix2pix icon indicating copy to clipboard operation
pytorch-CycleGAN-and-pix2pix copied to clipboard

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

Open happsky opened this issue 6 years ago • 9 comments

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?

happsky avatar May 15 '18 23:05 happsky

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!

phillipi avatar May 16 '18 00:05 phillipi

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?

happsky avatar May 16 '18 12:05 happsky

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.

junyanz avatar May 23 '18 03:05 junyanz

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

Gavin666Github avatar Jun 12 '18 02:06 Gavin666Github

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

junyanz avatar Jun 16 '18 07:06 junyanz

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.

nidetaoge avatar Jul 05 '18 01:07 nidetaoge

@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?

John1231983 avatar Apr 23 '19 03:04 John1231983

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

ZHE-SAPI avatar May 17 '22 09:05 ZHE-SAPI

你好!我訓練了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.

wendellgithub0206 avatar Jun 08 '23 07:06 wendellgithub0206