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

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

参考文献:

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

运行环境

win 10

1、代码下载

Github

2、下载pix2pix数据集

  • 通过URL手工下载:地址

房屋外观转换成房子实体

  • 存放路径:pytorch-CycleGAN-and-pix2pix\datasets
  • 存放路径

3、下载预训练模型

  • 下载链接
    下载预训练模型
  • 存放路径
    需要把模型的名称改为latest_net_G.pth,并存放在./checkpoints/facades_label2photo_pretrained目录中。
    存放路径

4. 使用Anaconda进行调试

  • 打开Anaconda Prompt (Anaconda3)
    在这里插入图片描述

  • 激活环境
    activate yolov5_tpz

  • 切换到d盘
    输入: d:
    在这里插入图片描述

  • 切换到 D:\tpz\the-third-paper\pytorch-CycleGAN-and-pix2pix-master
    输入: cd D:\tpz\the-third-paper\pytorch-CycleGAN-and-pix2pix-master
    在这里插入图片描述

  • 运行命令
    输入:
    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
    在这里插入图片描述
    在这里插入图片描述

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’
在这里插入图片描述
解决方案参考

  • 运行 test.py
  • 4
    点赞
  • 28
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值