junyanz / pytorch-CycleGAN-and-pix2pix

Image-to-Image Translation in PyTorch
Other
23.05k stars 6.31k forks source link

Single Style? #519

Open 3DTOPO opened 5 years ago

3DTOPO commented 5 years ago

Given that trainA images are a mix of monkeys and ape faces, and trainB consisting of images of human faces: I have found that the type (eg either monkey or ape) that was used when the checkpoint is created will be the only type of image that can be generated with that checkpoint. For instance, if a monkey image was used creating the checkpoint, then that checkpoint will only generate monkeys (and vice versa).

Or if I have a red and blue painting and a green and orange painting in trainA, only one style will be used. So all images generated will either be green and orange or red and blue.

Based on say the Monet example, I thought that it was based on all Monet's styles used for training. But it seems that only the style that is used when the checkpoint was created is actually used.

I'm confused! Is there any way that all styles used for training are used for generation? Any insight would be greatly appreciated!

junyanz commented 5 years ago

CycleGAN should learn to use the style of all the images. The gradient you can get from one training sample during one iteration is small. It is possible that CycleGAN only learns one style (monkey or ape) as it is a one-to-one mapping. A side note: the visualization images saved in the visdom or HTML may not be the last training image unless you save images every iteration.

3DTOPO commented 5 years ago

Thanks for the information!

To see what was going on, I trained 4 distinctly different styles (say one green/white, red/white, blue/white, black/white) to 1,200 different images. I let it run for 200 epochs.

But when I run the test on the Generator model, only one of the four distinct styles will be generated. If the last style image used for training was green/white, then only the green/white style will be generated.

After training for over a hundred epochs, I test a generator model by doing the following:

cp ./checkpoints/fourStyles/latest_net_G_B.pth ./checkpoints/fourStyles/latest_net_G.pth python3 test.py --dataroot ./datasets/ae_photos/outA --name fourStyles --model test --load_size 512 --crop_size 512 --preprocess scale_width --no_dropout

Is that the correct way to test a model that has weights for all of the styles it is trained for? Thanks again!

junyanz commented 5 years ago

Yes. To make the latest_net_G.pth the latest model, you need to save your model every iteration.