萌娃人脸生成器+人脸编辑器 实践踩坑笔记

萌娃人脸生成器

项目地址:https://github.com/a312863063/seeprettyface-generator-babies

1.介绍

本文是运行一个 StyleGAN 训练出的萌娃人脸生成器。

2. 实践过程

1.1 下载代码库

1.2 下载预训练权重

下载链接在:seeprettyface-generator-babies/model/模型下载后放在这里.txt 说明中:

百度网盘:
	链接:https://pan.baidu.com/s/1Txa3HPxcWfL_mQynTxBJ-g 
	提取码:movs 

FK 百度网盘,太慢了。

下载解压后放在:

model/
├── classifier-smiling.pkl
├── generator_kids.pkl

1.3 配置环境

注释掉 generate_kid.py:

# from aip import AipFace

创建一个 conda 环境:

# 注意,python 不能选择3.8及以上,因为要装 tensorflow1.x
conda create -n gan python=3.6
# 安装一些必要包 PIL 的包名字叫 pillow
pip install numpy pillow requests -i https://pypi.tuna.tsinghua.edu.cn/simple 
# 安装 tensorflow-gpu
conda install tensorflow-gpu==1.15

遇到错误

安装 tensorflow-gpu , 但是我遇到了如下错误:

InvalidArchiveError("Error with archive /home/我的用户名/conda/pkgs/tensorflow-base-1.15.0-gpu_py36h9dcbed7_0/.cph_tmpli1l9i4d/pkg-tensorflow-base-1.15.0-gpu_py36h9dcbed7_0.tar.zst.  You probably need to delete and re-download or re-create this file.  Message from libarchive was:\n\nFailed to create dir 'lib/python3.6/site-packages/tensorflow_core/include/external/com_github_googleapis_googleapis'")

解决:

参考:https://blog.csdn.net/eaxy_z/article/details/120293066

conda clean -p		# 删除未使用的包
conda clean -t		# 删除缓存的tarballs包
conda clean -a		# 删除所有缓存的数据(包括索引缓存等 )

然后,重新运行:

conda install tensorflow-gpu==1.15

完美运行,在 result 下生成了 20只 萌娃,还有对应的 result/generate_code。


人脸编辑器

项目:https://github.com/a312863063/seeprettyface-face_editor

1.下载项目
2. 环境和上面一样
3. 按使用说明调整 4 个部分

  • 把上面的模型 cp 到当前 model 下
  • cp 上面生成的 result/generate_code 到 文件夹 input_latent 下
  • 修改幅度 比如:coeffs = [5]

报错:

KeyError: "The name 'G_synthesis_1/_Run/concat:0' refers to a Tensor which does not exist. The operation, 'G_synthesis_1/_Run/concat', does not exist in the graph."

解决:util/generator_model.py:55 修改为:

    try:
        self.generator_output = self.graph.get_tensor_by_name('G_synthesis_1/_Run/concat/concat:0')

参考:https://github.com/a312863063/seeprettyface-face_editor/issues/2


以上是 stylegan_v1 的模型。

作者还更新了基于 styleganv2 的项目。

https://github.com/a312863063/generators-with-stylegan2

1. 下载模型:

cute baby face generator(generator_baby-stylegan2-config-f.pkl):
Download link: https://drive.google.com/file/d/1--684mANXSgC3aDhLc7lPM7OBHWuVRXa/view?usp=drivesdk

放到 networks 目录下

2. 配置环境

错误1:找不到 NVCC

解决:https://blog.csdn.net/weixin_44750512/article/details/123156020

错误2:

Setting up TensorFlow plugin "fused_bias_act.cu": Preprocessing... Failed!
 #error This file requires compiler and library support for the ISO C++ 2011 standard. This support is currently experimental, and must be enabled with the -std=c++11 or -std=gnu++11 compiler options.
#error This file requires compiler and library support for the \
error: #error "C++ versions less than C++11 are not supported."
#error "C++ versions less than C++11 are not supported."

修改 dnnlib/tflib/custom_ops.py 64 行:

# cmd = 'nvcc ' + opts.strip()
cmd = 'nvcc --std=c++11 -DNDEBUG ' + opts.strip() 

错误 3:

tensorflow.python.framework.errors_impl.NotFoundError: /home/xxx/projects/generators-with-stylegan2-master/dnnlib/tflib/_cudacache/fused_bias_act_64ec699fc12c19f9294af9c9296d9244.so: undefined symbol: _ZN10tensorflow12OpDefBuilder6OutputESs

解决:

修改 dnnlib/tflib/custom_ops.py 128 行:

# compile_opts += ' --compiler-options \'-fPIC -D_GLIBCXX_USE_CXX11_ABI=0\''
compile_opts += ' --compiler-options \'-fPIC -D_GLIBCXX_USE_CXX11_ABI=1\''

参考:

https://github.com/NVlabs/stylegan2-ada/issues/91

https://blog.csdn.net/zaf0516/article/details/103618601

完美运行。

posted @ 2022-10-26 18:07  cold_moon  阅读(328)  评论(0编辑  收藏  举报