且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

StyleMapGAN、有趣的风格迁移——评测【一】

更新时间:2022-06-06 05:25:34

???? 版权: 本文由【墨理学AI】原创、各位大佬、一文读懂、敬请查阅
???? 声明: 作为全网 AI 领域 干货最多的博主之一,❤️ 不负光阴不负卿 ❤️
声明:本博文按照官方readMe步骤,对测试实验过程进行简洁记录,仅供参考,码字不易,感谢支持

???? StyleMapGAN 继 StyleGAN2 发扬光大

论文摘要

生成对抗网络 (GAN) 从随机潜在向量合成逼真的图像。 尽管操纵潜在向量控制了合成输出,但使用 GAN 编辑真实图像存在以下问题:i) 将真实图像投影到潜在向量的优化耗时,ii) 或通过编码器嵌入不准确。 我们提出 StyleMapGAN:中间潜在空间具有空间维度,并且空间变体调制替代了 AdaIN。 它使通过编码器的嵌入比现有的基于优化的方法更准确,同时保持 GAN 的特性。 实验结果表明,我们的方法在各种图像处理任务(例如本地编辑和图像插值)中明显优于最先进的模型。 最后但并非最不重要的一点是,GAN 上的传统编辑方法在我们的 StyleMapGAN 上仍然有效。

???? 环境搭建

服务器:ubuntu1~18.04 Quadro RTX 5000 16G

StyleMapGAN、有趣的风格迁移——评测【一】

#!/bin/bash

conda install -y pytorch=1.4.0 torchvision=0.5.0 -c pytorch
conda install -y numpy=1.18.1 scikit-image=0.16.2 tqdm
conda install -y -c anaconda ipython=7.13.0
pip install lmdb==0.98 opencv-python==4.2.0.34 munch==2.5.0
pip install -U scikit-image==0.15.0 scipy==1.2.1 matplotlib scikit-learn
pip install flask==1.0.2 pillow==7.0.0
我博文已经搭建了很多环境,因此这里直接 activate 一个即可
conda activate torch15

???? 测试数据 + 预训练模型准备

StyleMapGAN、有趣的风格迁移——评测【一】

这里 下载 afhq 相关数据 + 模型,对其进行测试
# Download raw images and create LMDB datasets using them
# Additional files are also downloaded for local editing
bash download.sh create-lmdb-dataset afhq

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

# Download the pretrained network (1024x1024 image / 16x16 stylemap / Light version of Generator)
bash download.sh download-pretrained-network-1024 ffhq_16x16


__

???? Generate images 测试

__

???? Reconstruction

Reconstruction Results are saved to expr/reconstruction.
python generate.py --ckpt expr/checkpoints/afhq_256_8x8.pt --mixing_type reconstruction --test_lmdb data/afhq/LMDB_test
单卡 GPU 占用 11073MiB

StyleMapGAN、有趣的风格迁移——评测【一】

reconstruction 目录下是对 afhq_raw\raw_images\test\images 目录下 500 test 图像的 重建:

StyleMapGAN、有趣的风格迁移——评测【一】

???? Unaligned transplantation

Unaligned transplantation Results are saved to expr/transplantation. It shows local transplantations examples of AFHQ.
python generate.py --ckpt expr/checkpoints/afhq_256_8x8.pt --mixing_type transplantation --test_lmdb data/afhq/LMDB_test
transplantation 目录下是一个图像的合成转换:

StyleMapGAN、有趣的风格迁移——评测【一】

???? w_interpolation

Results are saved to expr/w_interpolation.
python generate.py --ckpt expr/checkpoints/afhq_256_8x8.pt  --mixing_type w_interpolation --test_lmdb data/afhq/LMDB_test
单卡 GPU 占用 8769MiB

StyleMapGAN、有趣的风格迁移——评测【一】

???? local_editing

Results are saved to expr/local_editing. We pair images using a target semantic mask similarity.
目标 mask 语义修复
python generate.py --ckpt expr/checkpoints/afhq_256_8x8.pt --mixing_type local_editing --test_lmdb data/afhq/LMDB_test
单卡 GPU 占用 9013MiB
  • mask 图像

StyleMapGAN、有趣的风格迁移——评测【一】

local_editing\afhq\synthesized_image

StyleMapGAN、有趣的风格迁移——评测【一】

???? 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/afhq_256_8x8.pt
单卡 GPU 占用 12995MiB

StyleMapGAN、有趣的风格迁移——评测【一】

???? Style Mixing

Style Mixing Results are saved to expr/stylemixing. It shows style mixing examples.
python generate.py --mixing_type stylemixing --ckpt expr/checkpoints/afhq_256_8x8.pt --test_lmdb data/afhq/LMDB_test
单卡 GPU 占用 8765 MiB
  • 粗修复结果: 124_coarse.png

StyleMapGAN、有趣的风格迁移——评测【一】

  • 细修复结果: 124_fine.png

StyleMapGAN、有趣的风格迁移——评测【一】

???? Semantic Manipulation 【 celeba_hq 可正常运行】

Semantic Manipulation Results are saved to expr/semantic_manipulation.
It shows local semantic manipulation examples.
python semantic_manipulation.py --ckpt expr/checkpoints/afhq_256_8x8.pt --LMDB data/afhq/LMDB --svm_train_iter 10000
单卡 GPU 占用 6455MiB
遇到报错 | Semantic Manipulation 应该暂时只有 celeba_hq 可以使用和运行
validate boundary.
Accuracy for validation set: 535 / 999 = 0.535536
classifier.coef_.shape (1, 4096)
boundary.shape (64, 8, 8)
30000 images, 16130 latent_codes
Traceback (most recent call last):
  File "semantic_manipulation.py", line 348, in <module>
    assert total_number == len(latent_codes)
AssertionError

???? 博主 AI 领域八大干货专栏、诚不我欺


???? 预祝各位 2022 前途似锦、可摘星辰

???? 作为全网 AI 领域 干货最多的博主之一,❤️ 不负光阴不负卿 ❤️
❤️ 如果文章对你有帮助、点赞、评论鼓励博主的每一分认真创作
❤️ 比寻找温暖更重要的是,让自己成为一盏灯火 ❤️

StyleMapGAN、有趣的风格迁移——评测【一】