天天看點

StyleMapGAN之celeba_hq 風格遷移 - 圖像編輯、實驗測評【二】

  • ???? 版權: 本文由【墨理學AI】原創、各位大佬、一文讀懂、敬請查閱
  • ???? 聲明: 作為全網 AI 領域 幹貨最多的部落客之一,❤️ 不負光陰不負卿 ❤️
StyleMapGAN 創作如下

​​StyleMapGAN、有趣的風格遷移——評測【一】 ​​

StyleMapGAN 基于 StyleGAN2 改進

論文題目

Exploiting Spatial Dimensions of Latent in GAN for Real-time Image Editing

所運作代碼 + paper
  • ​​github.com/naver-ai/St…​​
  • ​​arxiv.org/pdf/2104.14…​​
本博文記錄StyleMapGAN 預訓練模型 在 celeba_hq 測試資料上的 生成效果
  • 環境搭建參考上一篇博文即可

celeba_hq 測試資料 + 預訓練模型準備

作者把相關下載下傳連結和解壓邏輯已經在 download.sh 中整理完畢,真的非常 Nice

直接傻瓜式操作,複制指令一路下載下傳即可【看網速,差不多半小時的樣子】

# Download raw images and create LMDB datasets using them
# Additional files are also downloaded for local editing

bash download.sh create-lmdb-dataset celeba_hq

# Download the pretrained network (256x256)
bash download.sh download-pretrained-network-256 celeba_hq

# Download the pretrained network (1024x1024 image / 16x16 stylemap / Light version of Generator)
bash download.sh download-pretrained-network-1024 ffhq_16x16      
StyleMapGAN之celeba_hq 風格遷移 - 圖像編輯、實驗測評【二】
StyleMapGAN之celeba_hq 風格遷移 - 圖像編輯、實驗測評【二】
整個項目 + 以上指令下載下傳解壓的資料 ,總共就 占用 20G 存儲
du -sh

20G     .      

項目資料部分目錄結構

StyleMapGAN之celeba_hq 風格遷移 - 圖像編輯、實驗測評【二】

Generate images test of celeba_hq 資料集

Reconstruction

Reconstruction Results are saved to expr/reconstruction.
# CelebA-HQ
python generate.py --ckpt expr/checkpoints/celeba_hq_256_8x8.pt --mixing_type reconstruction --test_lmdb data/celeba_hq/LMDB_test      
單卡 GPU 占用 11073MiB
StyleMapGAN之celeba_hq 風格遷移 - 圖像編輯、實驗測評【二】

interpolation

W interpolation Results are saved to expr/w_interpolation
# CelebA-HQ
python generate.py --ckpt expr/checkpoints/celeba_hq_256_8x8.pt --mixing_type w_interpolation --test_lmdb data/celeba_hq/LMDB_test      
單卡 GPU 占用 8769MiB
StyleMapGAN之celeba_hq 風格遷移 - 圖像編輯、實驗測評【二】

Local editing

Local editing Results are saved to expr/local_editing. We pair images using a target semantic mask similarity. If you want to see details, please follow preprocessor/README.md.
# Using GroundTruth(GT) segmentation masks for CelebA-HQ dataset.
python generate.py --ckpt expr/checkpoints/celeba_hq_256_8x8.pt --mixing_type local_editing --test_lmdb data/celeba_hq/LMDB_test --local_editing_part nose      
StyleMapGAN之celeba_hq 風格遷移 - 圖像編輯、實驗測評【二】
單卡 GPU 占用 8793MiB
StyleMapGAN之celeba_hq 風格遷移 - 圖像編輯、實驗測評【二】
重建得到的 nose
StyleMapGAN之celeba_hq 風格遷移 - 圖像編輯、實驗測評【二】
synthesized_image 生成的鼻子如下【也有少許失敗樣例】
StyleMapGAN之celeba_hq 風格遷移 - 圖像編輯、實驗測評【二】

Random Generation

Random Generation Results are saved to expr/random_generation. It shows random generation examples.
python generate.py --mixing_type random_generation --ckpt expr/checkpoints/celeba_hq_256_8x8.pt      
StyleMapGAN之celeba_hq 風格遷移 - 圖像編輯、實驗測評【二】

Style Mixing

Style Mixing Results are saved to expr/stylemixing. It shows style mixing examples.
python generate.py --mixing_type stylemixing --ckpt expr/checkpoints/celeba_hq_256_8x8.pt --test_lmdb data/celeba_hq/LMDB_test      
單卡 GPU 占用 8769MiB
  • 粗修複結果: 135_coarse.png
StyleMapGAN之celeba_hq 風格遷移 - 圖像編輯、實驗測評【二】
  • 細修複結果: 135_fine.png
StyleMapGAN之celeba_hq 風格遷移 - 圖像編輯、實驗測評【二】

Semantic Manipulation

Semantic Manipulation Results are saved to expr/semantic_manipulation. It shows local semantic manipulation examples.
# CelebA-HQ
python semantic_manipulation.py --ckpt expr/checkpoints/celeba_hq_256_8x8.pt --LMDB data/celeba_hq/LMDB --svm_train_iter 10000      

單卡 GPU 占用 6455MiB

生成【化妝】效果如下

StyleMapGAN之celeba_hq 風格遷移 - 圖像編輯、實驗測評【二】

運作輸出如下【運作5分鐘左右】

latent_code_shape (64, 8, 8)
positive_train: 5867, negative_train:3134, positive_val:651, negative_val:348
Training boundary. 2021-07-09 10:36:17.187714
/home/墨理/anaconda3/envs/torch15/lib/python3.7/site-packages/sklearn/svm/_base.py:258: ConvergenceWarning: Solver terminated early (max_iter=10000).  Consider pre-processing your data with StandardScaler or MinMaxScaler.
  % self.max_iter, ConvergenceWarning)
Finish training. 2021-07-09 10:37:23.516691
validate boundary.
Accuracy for validation set: 914 / 999 = 0.914915
classifier.coef_.shape (1, 4096)
boundary.shape (64, 8, 8)
30000 images, 30000 latent_codes
Heavy_Makeup 18      

代碼結構如下

tree -L 5
.
├── assets
│   ├── teaser.jpg
│   └── teaser_video.jpg
├── data
│   └── afhq
│       ├── LMDB_test
│       │   ├── data.mdb
│       │   └── lock.mdb
│       ├── LMDB_train
│       │   ├── data.mdb
│       │   └── lock.mdb
│       ├── LMDB_val
│       │   ├── data.mdb
│       │   └── lock.mdb
│       ├── local_editing
│       └── raw_images
│           ├── test
│           │   └── images
│           ├── train
│           │   └── images
│           └── val
│               └── images
├── demo
│   ├── static
│   │   └── components
│   │       ├── css
│   │       │   ├── image-picker.css
│   │       │   ├── main.css
│   │       │   └── main.scss
│   │       ├── img
│   │       │   ├── afhq
│   │       │   ├── celeba_hq
│   │       │   ├── eraser.png
│   │       │   └── lsun
│   │       └── js
│   │           ├── agh.sprintf.js
│   │           ├── image-picker.min.js
│   │           └── main.js
│   └── templates
│       ├── index.html
│       └── layout.html
├── demo.py
├── download.sh
├── expr
│   ├── checkpoints
│   │   ├── afhq_256_8x8.pt
│   │   ├── celeba_hq_256_8x8.pt
│   │   └── ffhq_1024_16x16.pt
│   ├── checkpoints_afhq
│   │   ├── afhq_256_8x8.pt
│   │   ├── ffhq_1024_16x16.pt
│   │   ├── small_ffhq_16x16_5M.pt
│   │   └── small_ffhq_32x32_2_5M.pt
│   ├── local_editing
│   │   └── celeba_hq
│   │       └── nose
│   │           ├── mask
│   │           ├── mask_ref
│   │           ├── mask_src
│   │           ├── reference_image
│   │           ├── reference_reconstruction
│   │           ├── source_image
│   │           ├── source_reconstruction
│   │           └── synthesized_image
│   ├── semantic_manipulation
│   │   ├── afhq_256_8x8_inverted.npy
│   │   └── Heavy_Makeup
│   │       └── afhq_256_8x8_Heavy_Makeup_boundary.npy
│   └── stylemixing
│       └── afhq
│           ├── 124_coarse.png
│           ├── 124_fine.png
│           ├── 135_coarse.png
│           ├── 135_fine.png
│           ├── 136_coarse.png
│           ├── 136_fine.png
│           ├── 162_coarse.png
│           ├── 162_fine.png
│           ├── 173_coarse.png
│           ├── 173_fine.png
│           ├── 7_coarse.png
│           └── 7_fine.png
├── generate.py
├── install.sh
├── LICENSE
├── metrics
│   ├── calc_inception.py
│   ├── fid.py
│   ├── inception.py
│   ├── __init__.py
│   ├── local_editing.py
│   ├── README.md
│   └── reconstruction.py
├── NOTICE
├── preprocessor
│   ├── pair_masks.py
│   ├── prepare_data.py
│   └── README.md
├── README.md
├── semantic_manipulation
│   ├── 0_neg_indices.npy
...
...
│   ├── 9_pos_indices.npy
│   └── list_attr_celeba_hq.txt
├── semantic_manipulation.py
├── training
│   ├── dataset_ddp.py
│   ├── dataset.py
│   ├── __init__.py
│   ├── lpips
│   │   ├── base_model.py
│   │   ├── dist_model.py
│   │   ├── __init__.py
│   │   ├── networks_basic.py
│   │   ├── pretrained_networks.py
│   │   └── weights
│   │       ├── v0.0
│   │       │   ├── alex.pth
│   │       │   ├── squeeze.pth
│   │       │   └── vgg.pth
│   │       └── v0.1
│   │           ├── alex.pth
│   │           ├── squeeze.pth
│   │           └── vgg.pth
│   ├── model.py
│   ├── op
│   │   ├── fused_act.py
│   │   ├── fused_bias_act.cpp
│   │   ├── fused_bias_act_kernel.cu
│   │   ├── __init__.py
│   │   ├── __pycache__
│   │   │   ├── fused_act.cpython-37.pyc
│   │   │   ├── __init__.cpython-37.pyc
│   │   │   └── upfirdn2d.cpython-37.pyc
│   │   ├── upfirdn2d.cpp
│   │   ├── upfirdn2d_kernel.cu
│   │   └── upfirdn2d.py
│   └── __pycache__
│       ├── dataset.cpython-37.pyc
│       ├── __init__.cpython-37.pyc
│       └── model.cpython-37.pyc
├── train.py
└── wget-log

53 directories, 167 files      
  • ???? 作為全網 AI 領域 幹貨最多的部落客之一,❤️ 不負光陰不負卿 ❤️
  • ❤️ 如果文章對你有幫助、點贊、評論鼓勵部落客的每一分認真創作
  • ???? 目标檢測、超分重建、圖像修複、資料集整理 四大專欄持續更新、敬請關注

繼續閱讀