基于photo2carton使用真人相片生成卡通头像

我的python环境中缺少相关包,依次按缺少的资源安装。此处建议使用conda等应用版本管理工具管理,防止把自己的环境搞乱了。

一下安装过程中,优先使用清华源,失败情况下可以尝试使用阿里源和默认源,请根据自己的情况处理。

从github上克隆源码包,根据执行的错误提示,分别安装缺少的包。

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

安装过程可能遇到的错误处理

ModuleNotFoundError: No module named ‘cv2’

# cv2
#使用清华源
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple opencv-python
#使用默认源
pip install opencv-python

tqdm

ModuleNotFoundError: No module named 'tqdm'
#tqdm
#使用清华源
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple tqdm
#使用默认源
pip install tqdm

face_alignment

ModuleNotFoundError: No module named ‘face_alignment’

#face_alignment
#使用清华源
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple face_alignment
#使用默认源
pip install face_alignment
#ali
pip install -i http://mirrors.aliyun.com/pypi/simple/ face_alignment --trusted-host mirrors.aliyun.com

tensorflow

ModuleNotFoundError: No module named 'tensorflow'
pip install -i http://mirrors.aliyun.com/pypi/simple/  tensorflow --trusted-host mirrors.aliyun.com

dlib

ModuleNotFoundError: No module named ‘dlib’

#默认源
pip install  dlib
#阿里源
pip install -i http://mirrors.aliyun.com/pypi/simple/  dlib --trusted-host mirrors.aliyun.com

pip install -i https://pypi.tuna.tsinghua.edu.cn/simple dlib

安装出现以下错误 CMake must be installed to build the following extensions: _dlib_pybind11 表示需要安装 cmake

pip install -i http://mirrors.aliyun.com/pypi/simple/  --trusted-host mirrors.aliyun.com cmake

torchvision

ModuleNotFoundError: No module named ‘torchvision’

pip install -i http://mirrors.aliyun.com/pypi/simple/  --trusted-host mirrors.aliyun.com torchvision

将上面的确实的包合并安装

pip install -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com opencv-python  tqdm face_alignment tensorflow cmake  dlib  torchvision

错误 AttributeError: module ‘tensorflow’ has no attribute ‘ConfigProto’ ,根据提示在出现错误的代码中修改

使用CUDA10.1加上Tensorflow 2.0会出现AttributeError: module ‘tensorflow’ has no attribute ‘ConfigProto’这个问题,这个是由于现在新版本中一些1.0版本的函数被和2.0版本函数区分开的缘故

所以,需要将
tf.ConfigProto
修改为
tf.compat.v1.ConfigProto

错误 AttributeError: module ‘tensorflow’ has no attribute ‘Session’ 和上面的错误修改方式相同

将
tf.Session
修改为
tf.compat.v1.Session

错误 AttributeError: module ‘tensorflow’ has no attribute ‘GraphDef’

tf.GraphDef
修改为
tf.compat.v1.GraphDef

测试头像转换命令:

python test.py --photo_path ./images/zhoujielun.jpg --save_path ./images/zhoujielun_c.jpg

转换结果

Related Posts: