原文链接:https://dsx2016.com/?p=1826
公众号:大师兄2016
git地址
https://github.com/minivision-ai/photo2cartoon
输入命令
git clone https://github.com/minivision-ai/photo2cartoon.git
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
conda env create -f environment.yml
报错解决
安装dlib报错
conda activate UGATIT3
安装cmake
pip install cmake
再次安装dlib
pip install dlib
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++.
地址
https://visualstudio.microsoft.com/zh-hans/downloads/
继续安装
选择c++环境
安装完成后重启即可
再次安装dlib
pip install dlib
ModuleNotFoundError: No module named ‘torchvision’
安装torchvision
pip install torchvision
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"
python test.py --photo_path ./images/photo_test.jpg --save_path ./images/cartoon_result.png
会自动下载一些依赖
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"
没有报错,但是没有保存图片
UserWarning: Warning: this detector is deprecated. Please use a different one, i.e.: S3FD
字面上的意思是没有进行人脸分割,无法识别
按照官方文档,在测试前需要下载模型和数据包,放在对应文件夹下
谷歌网盘 | 百度网盘 提取码: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路径下。
至此,保存图片成功
也实现了真人转动画效果
python test_onnx.py --photo_path ./images/photo_test.jpg --save_path ./images/cartoon_result.png
onnx转换的结果图片
END.