pix2pix学习系列(1):预训练模型测试pix2pix

pix2pix学习系列(1):预训练模型测试pix2pix

参考文献:

[Pytorch系列-66]:生成对抗网络GAN - 图像生成开源项目pytorch-CycleGAN-and-pix2pix - 使用预训练模型测试pix2pix模型

运行环境

win 10

1、代码下载

Github

2、下载pix2pix数据集

  • 通过URL手工下载:地址

pix2pix学习系列(1):预训练模型测试pix2pix_第1张图片

  • 存放路径:pytorch-CycleGAN-and-pix2pix\datasets
  • pix2pix学习系列(1):预训练模型测试pix2pix_第2张图片

3、下载预训练模型

  • 下载链接
    pix2pix学习系列(1):预训练模型测试pix2pix_第3张图片
  • 存放路径
    需要把模型的名称改为latest_net_G.pth,并存放在./checkpoints/facades_label2photo_pretrained目录中。
    存放路径

4. 使用Anaconda进行调试

  • 打开Anaconda Prompt (Anaconda3)
    pix2pix学习系列(1):预训练模型测试pix2pix_第4张图片

  • 激活环境
    activate yolov5_tpz

  • 切换到d盘
    输入: d:
    pix2pix学习系列(1):预训练模型测试pix2pix_第5张图片

  • 切换到 D:\tpz\the-third-paper\pytorch-CycleGAN-and-pix2pix-master
    输入: cd D:\tpz\the-third-paper\pytorch-CycleGAN-and-pix2pix-master
    pix2pix学习系列(1):预训练模型测试pix2pix_第6张图片

  • 运行命令
    输入:
    python test.py --dataroot ./datasets/facades --direction BtoA --model pix2pix --name facades_label2photo_pretrained

  • 运行效果

----------------- Options ---------------
             aspect_ratio: 1.0
               batch_size: 1
          checkpoints_dir: ./checkpoints
                crop_size: 256
                 dataroot: ./datasets/facades                   [default: None]
             dataset_mode: aligned
                direction: BtoA                                 [default: AtoB]
          display_winsize: 256
                    epoch: latest
                     eval: False
                  gpu_ids: 0
                init_gain: 0.02
                init_type: normal
                 input_nc: 3
                  isTrain: False                                [default: None]
                load_iter: 0                                    [default: 0]
                load_size: 256
         max_dataset_size: inf
                    model: pix2pix                              [default: test]
               n_layers_D: 3
                     name: facades_label2photo_pretrained       [default: experiment_name]
                      ndf: 64
                     netD: basic
                     netG: unet_256
                      ngf: 64
               no_dropout: False
                  no_flip: False
                     norm: batch
                 num_test: 50
              num_threads: 4
                output_nc: 3
                    phase: test
               preprocess: resize_and_crop
              results_dir: ./results/
           serial_batches: False
                   suffix:
                use_wandb: False
                  verbose: False
----------------- End -------------------
dataset [AlignedDataset] was created
initialize network with normal
model [Pix2PixModel] was created
loading the model from ./checkpoints\facades_label2photo_pretrained\latest_net_G.pth
---------- Networks initialized -------------
[Network G] Total number of parameters : 54.414 M
-----------------------------------------------
creating web directory ./results/facades_label2photo_pretrained\test_latest
D:\Anaconda3\envs\yolov5_tpz\lib\site-packages\torchvision\transforms\transforms.py:280: UserWarning: Argument interpolation should be of type InterpolationMode instead of int. Please, use InterpolationMode enum.
  warnings.warn(
processing (0000)-th image... ['./datasets/facades\\test\\1.jpg']
processing (0005)-th image... ['./datasets/facades\\test\\103.jpg']
processing (0010)-th image... ['./datasets/facades\\test\\12.jpg']
processing (0015)-th image... ['./datasets/facades\\test\\17.jpg']
processing (0020)-th image... ['./datasets/facades\\test\\21.jpg']
processing (0025)-th image... ['./datasets/facades\\test\\26.jpg']
processing (0030)-th image... ['./datasets/facades\\test\\30.jpg']
processing (0035)-th image... ['./datasets/facades\\test\\35.jpg']
processing (0040)-th image... ['./datasets/facades\\test\\4.jpg']
processing (0045)-th image... ['./datasets/facades\\test\\44.jpg']
  • 查看结果
    图片位置: \results\facades_label2photo_pretrained\test_latest\images
    pix2pix学习系列(1):预训练模型测试pix2pix_第7张图片
    pix2pix学习系列(1):预训练模型测试pix2pix_第8张图片

5. 也可以使用pycharm进行调试

  • 设置 options/base_options.py
parser.add_argument('--dataroot', default='datasets/facades', help='path to images (should have subfolders trainA, trainB, valA, valB, etc)')
parser.add_argument('--name', type=str, default='facades_label2photo_pretrained', help='name of the experiment. It decides where to store samples and models')
parser.add_argument('--model', type=str, default='pix2pix', help='chooses which model to use. [cycle_gan | pix2pix | test | colorization]')
parser.add_argument('--direction', type=str, default='BtoA', help='AtoB or BtoA')
  • 设置 options/test_options.py
parser.set_defaults(model='pix2pix')

注意:
如果不将 parser.set_defaults(model='test ') 更改为 parser.set_defaults(model=‘pix2pix’),将会出现以下错误:
AttributeError: ‘Sequential’ object has no attribute ‘model’
pix2pix学习系列(1):预训练模型测试pix2pix_第9张图片
解决方案参考

  • 运行 test.py

你可能感兴趣的:(重要,笔记,学习,深度学习,pytorch,GAN,pix2pix)