Skip to content

The final project of course AU332-Artificial Intelligence(Principles and Techniques). We use cycle-consistent adversarial network to transform pictures into Chinese painting style, which is based on new data sets collected by our own.

Notifications You must be signed in to change notification settings

K1nght/GAN-based_Chinese_Painting_Generation

Repository files navigation

GAN-based Chinese Painting Generation

Author

黄哲昊 叶瑜超

Source code

pytorch-CycleGAN-and-pix2pix

Environment

  • torch>=1.4.0
  • torchvision>=0.5.0
  • dominate>=2.4.0
  • visdom>=0.1.8.8

Our datasets

  • cp2photo_v1: contains 5382 photosincluding landscape photos, plant photos and animal pho-tos, 1070 Chinese paintings including Chinese landscape painting, Chinese bird-and-flower painting and Chinesefigure painting.
  • cp2photo_v2: contains 826 photos including almostall landscape photos and 522 traditional Chinese paintingsincluding almost all landscape paintings.
  • cp2photo_v3: contains 2194 landscapephotos and 2686 Chinese landscape paintings.

Baiduyunpan link for these three datasets: https://pan.baidu.com/s/1cEgMAYsL8wLR17XnGa-vGA, password: 03ci

开启一次训练完整流程

  • 登录Xshell 6连接服务器au332p10

  • tmux new -s visdom用于开启visdom训练可视化终端链接
    在tmux窗口内运行 python -m visdom.server
    然后ctrl b + d 退出tmux窗口

  • 在自己电脑windows cmd终端使用ssh连接服务器
    ssh -L 8097:127.0.0.1:8097 -p 3333 [email protected]
    然后使用本地浏览器访问 http://localhost:8097 就可以实时监控训练情况了

  • 使用tmux另开一个窗口运行训练程序tmux new -s session_name session_name为窗口名

  • 在tmux窗口内运行 conda activate Pytorch

  • cd pytorch-CycleGAN-and-pix2pix

  • 开始训练

 --dataroot: path to images (should have subfolders trainA, trainB, valA, valB, etc)
 --name: name of the experiment. It decides where to store samples and models
 --model: chooses which model to use, we use 'cycle_gan'
 --gpu_ids: gpu ids: e.g. 0  0,1,2, 0,2. use -1 for CPU
 --display_env: visdom display environment name (default is "main")
 --netG: specify generator architecture, choose from [resnet_9blocks | unet_256 ]
 --n_epochs: number of epochs with the initial learning rate
 --n_epochs_decay: number of epochs to linearly decay learning rate to zero
 --n_epochs_D: number of epochs to train the D per training the G, which must > 0
 the total epochs = n_epochs * n_epochs_D + n_epochs_decay
 --lr_policy: learning rate schedular, choose from [linear | step | plateau | cosine]
 --addnoise: add which noise data augmentation to the training img or none, choose from ['SaltPepper', 'Gaussian', 'SaltPepper_and_Gaussian', None]

 python train_more_D.py --dataroot ./datasets/datasets_name --name save_name --model cycle_gan --gpu_ids 0 --display_env env --netG resnet_9blocks --n_epochs 100 --n_epochs_decay 200 --lr_policy cosine --n_epochs_D 3
  • 训练结果保存在checkpoints文件夹下
  • ctrl b + d 退出tmux窗口
  • tmux attach -t session_name重新进入tmux窗口

使用已经训练好的模型得到测试结果

  • 源代码中test.py使用epoch次的保存模型进行测试,得到Domain x 和Domain y的双向测试结果
 --epoch: which epoch to load?
 --num_test: how many test images to run
 python test.py --dataroot ./datasets/datasets_name --name save_name --model cycle_gan --gpu_ids 0 --epoch 50 --netG resnet_9blocks
  • 我们的test_img.py只得到从原图转换为水墨画
 --save_path: where to save the result
 python test_img.py --dataroot ./datasets/datasets_name --name save_name --model cycle_gan --epoch 50 --netG resnet_9blocks --save_path ./result/test

毛笔建模Demo

 python brush/brushwritev2.py

About

The final project of course AU332-Artificial Intelligence(Principles and Techniques). We use cycle-consistent adversarial network to transform pictures into Chinese painting style, which is based on new data sets collected by our own.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published