CycleGAN问题

https://github.com/junyanz/pytorch-CycleGAN-and-pix2pix/blob/master/docs/tips.md#trainingtest-tips

Preprocessing

Images can be resized and cropped in different ways using--preprocess option. The default option'resize_and_crop'resizes the image to be of size(opt.load_size, opt.load_size)and does a random cropof size(opt.crop_size, opt.crop_size).'crop'skips the resizing step and only performs random cropping.'scale_width'resizes the image to have width opt.crop_sizewhile keeping the aspectratio.'scale_width_and_crop'first resizes the image to have widthopt.load_sizeand then does random cropping of size(opt.crop_size, opt.crop_size).'none'tries to skip all these preprocessing steps.However, if the image size is not a multiple of some number depending on the number of downsamplings of the generator, you will get an error because the size of the output image may be different from the size of the input image. Therefore,'none' option still tries to adjust the image size to be a multiple of 4.You might need a bigger adjustment if you change the generator architecture. Please see data/base_datset.py do see how all these were implemented.

Fine-tuning/resume training

To fine-tune a pre-trained model, or resume the previous training, use the--continue_trainflag. The program will then load the model based one poch. By default, the program will initialize the epoch count as 1. Set--epoch_countto specify a different starting epoch count.

About image size

Since the generator architecture in CycleGAN involves a series of downsampling / upsampling operations, the size of the input and output image may not match if the input image size is not a multiple of 4. As a result, you may get a runtime error because theL1 identity loss cannot be enforced with images of different size. Therefore, we slightly resize the image to become multiples of 4even with--preprocess none option. For the same reason,--crop_sizeneeds to be a multiple of 4.

Training/Testing with high res images

CycleGAN is quite memory-intensive as four networks (two generators and two discriminators) need to be loaded on one GPU, so a large image cannot be entirely loaded. In this case, we recommend training with cropped images. For example, to generate 1024pxresults, you can train with--preprocess scale_width_and_crop--load_size 1024 --crop_size 360, and test with--preprocess scale_width --crop_size 1024. This way makes sure the training and test will be at the same scale. At test time, you can afford higher resolution because you don’t need to load all networks.

About loss curve

Unfortunately, the loss curve does not reveal much information in training GANs, and CycleGAN is no exception. To check whether the training has converged or not, we recommend periodically generating a few samples and looking at them.

About batch size

For all experiments in the paper, we set the batch size to be 1.If there is room for memory, you can use higher batch size with batch norm or instance norm. (Note that the default batch norm does not work well with multi-GPU training. You may consider using synchronized batch norm instead). But please be aware that it can impact the training. In particular, even with Instance Normalization, different batch sizes can lead to different results. Moreover, increasing--crop_size may be a good alternative to increasing the batch size.

https://github.com/junyanz/pytorch-CycleGAN-and-pix2pix/blob/master/docs/qa.md#frequently-asked-questions

ValueError: empty range for randrange()

Similar error messages include "Connection Refused Error: [Errno111] Connection refused"

It is related to data augmentation step. It often happens when you use--preprocess crop. The program will crop random crop_size x crop_size patches out of the input training images. But if some of your image sizes (e.g.,256x384) are smaller than the crop_size(e.g., 512), you will get this error. A simple fix will be to use other data augmentation methods such as resize_and_cropor scale_width_and_crop.Our program will automatically resize the images according to load_size before applycrop_size x crop_sizecropping. Make sure thatload_size >=crop_size.

Can I continue/resume my training?

You can use the option--continue_train. Also set--epoch_countto specify a different starting epoch count. See more discussion in [training/test tips](https://github.com/junyanz/pytorch-CycleGAN-and-pix2pix/blob/master/docs/tips.md#training test-tips.

Multi-GPU Training 

You can use Multi-GPU training by setting--gpu_ids(e.g.,--gpu_ids 0,1,2,3for the first four GPUs on your machine.) To fully utilize all the GPUs, you need to increase your batch size. Try--batch_size 4,--batch_size 16, or even a larger batch_size. Each GPU will process batch_size/#GPUs images. The optimal batch size depends on the number of GPUs you have, GPU memory per GPU, and there solution of your training images.

We also recommend that you use the instance normalization for multi-GPU training by setting--norm instance. The current batch normalization might not work for multi-GPUs as the batch norm parameters are not shared across different GPUs. Advanced users can try synchronized batch norm.

Can I run the model on CPU? 

Yes, you can set--gpu_ids -1. See training/test tips for more details.

Out of memory

CycleGAN is more memory-intensive than pix2pix as it requires two generators and two discriminators. If you would like to produce high-resolution images, you can do the following. During training, train CycleGAN on cropped images of the training set. Please be careful not to change the aspect ratio or the scale of the original image, as this can lead to the training/test gap. You can usually do this by using--preprocess crop option, or--preprocess scale_width_and_crop.

Then at test time, you can load only one generator to produce the results in a single direction. This greatly saves GPU memory as you are not loading the discriminators and the other generator in the opposite direction. You can probably take the whole image as input. You can do this using--model test --dataroot [path to the directory that contains your test images (e.g., ./datasets/horse2zebra/trainA)] --model_suffix _A --preprocess none . You can use either--preprocess none or--preprocess scale_width --crop_size [your_desired_image_width]. Please see the model_suffix and preprocess for more details.

What is the identity loss? 

We use the identity loss for our photo to painting application. The identity loss can regularize the generator to be close to an identity mapping when fed with real samples from the target domain. If something already looks like from the target domain, you should preserve the image without making additional changes. The generator trained with this loss will often be more conservative for unknown content. Please see more details in Sec 5.2 ''Photo generation from paintings'' and Figure 12 in the CycleGAN paper. The loss was first proposed in the Equation 6 of the prior work [Taigman et al., 2017].

The color gets inverted from the beginning of training 

The authors also observe that the generator unnecessarily inverts the color of the input image early in training, and then never learns to undo the inversion. In this case, you can try two things.

First, try using identity loss--lambda_identity 1.0or--lambda_identity 0.1. We observe thatthe identity loss makes the generator to be more conservative and make fewer unnecessary changes. However, because of this, the change may not be as dramatic.

Second, try smaller variance when initializing weights by changing--init_gain. We observe that smaller variancein weight initialization results in less color inversion.

pix2pix/CycleGAN has no random noise

The current pix2pix/CycleGAN model does not take z as input. In both pix2pix and CycleGAN, we tried to add z to the generator: e.g., adding z to a latent state, concatenating with a latent state, applying dropout, etc., but often found the output did not vary significantly as a function of z. Conditional GANs do not need noise as long as the input is sufficiently complex so that the input can kind of play the role of noise. Without noise, the mapping is deterministic. Please check out the following papers that show ways of getting z to actually have a substantial effect: e.g.,BicycleGAN, AugmentedCycleGAN, MUNIT, DRIT,etc.

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 213,417评论 6 492
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 90,921评论 3 387
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 158,850评论 0 349
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 56,945评论 1 285
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 66,069评论 6 385
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 50,188评论 1 291
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 39,239评论 3 412
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 37,994评论 0 268
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 44,409评论 1 304
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 36,735评论 2 327
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 38,898评论 1 341
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 34,578评论 4 336
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 40,205评论 3 317
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 30,916评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,156评论 1 267
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 46,722评论 2 363
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 43,781评论 2 351