photo2cartoon环境搭建-真人头像卡通画-写实

NO.1
下载项目

git地址

https://github.com/minivision-ai/photo2cartoon

输入命令

git clone https://github.com/minivision-ai/photo2cartoon.git

NO.2
创建conan环境

environment.yml

name: UGATIT3
dependencies:
  - python=3.6
  - matplotlib
  - numpy
  - pip
  - pip:
    - pytorch
    - onnxruntime
    - tensorflow==1.14.0
    # - tensorflow-gpu==1.14.0
    - dlib
    - face-alignment
    - cmake

NO.3
创建环境

conda env create -f environment.yml

报错解决

安装dlib报错

img

NO.4
启动环境

conda activate UGATIT3

NO.5
终端设置

安装cmake

pip install cmake

再次安装dlib

pip install blib

NO.6
c++报错

You must use Visual Studio to build a python extension on windows.  If you
are getting this error it means you have not installed Visual C++.  Note
that there are many flavors of Visual Studio, like Visual Studio for C#
development.  You need to install Visual Studio for C++.

img

NO.7
安装Visual Studio 2019

地址

https://visualstudio.microsoft.com/zh-hans/downloads/

img

继续安装

选择c++环境

img

安装完成后重启即可

再次安装dlib

pip install blib

NO.8
启动报错

ModuleNotFoundError: No module named ‘torchvision’

安装torchvision

pip install torchvision

NO.9
运行报错

OMP: Error #15: Initializing libiomp5md.dll, but found libiomp5md.dll already initialized. OMP: Hi

在对应的文件,此处为test.py的顶部添加

import os
os.environ["KMP_DUPLICATE_LIB_OK"]  =  "TRUE"

img

NO.10
再次运行

python test.py --photo_path ./images/photo_test.jpg --save_path ./images/cartoon_result.png

会自动下载一些依赖

img

NO.11
报错qint8
site-packages/tensorflow/python/framework/dtypes.py:458: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint8 = np.dtype([("qint8", np.int8, 1)])
numpy的版本太高了。TensorFlow 2.0.b1的版本以下,如果Numpy的版本超过了1.17,就会出现这个警告
降级,然后就好了

pip install "numpy<1.17"

img

NO.12
有警告无图片

没有报错,但是没有保存图片

UserWarning: Warning: this detector is deprecated. Please use a different one, i.e.: S3FD

字面上的意思是没有进行人脸分割,无法识别

img

按照官方文档,在测试前需要下载模型和数据包,放在对应文件夹下

NO.13
下载资源

谷歌网盘 | 百度网盘 提取码:y2ch

人像卡通化预训练模型:photo2cartoon_weights.pt(20200504更新),存放在models路径下。

头像分割模型:seg_model_384.pb,存放在utils路径下。

人脸识别预训练模型:model_mobilefacenet.pth,存放在models路径下。(From: InsightFace_Pytorch)

卡通画开源数据:cartoon_data,包含trainB和testB。

人像卡通化onnx模型:photo2cartoon_weights.onnx 谷歌网盘,存放在models路径下。

NO.14
保存成功

至此,保存图片成功

img

也实现了真人转动画效果

img

NO.15
运行onnx

python test_onnx.py --photo_path ./images/photo_test.jpg --save_path ./images/cartoon_result.png

img

onnx转换的结果图片

img

END.