本篇文章是基于新冠疫情下,毕业照怎么拍?10行Python代码搞定的学习记录。继手绘PS云毕业照片走红网络,身为预备役程序员的我却把好好的青春回忆变成了暗黑系恐怖片之后,终于找到了P图神器,orz,orz。
依托于PaddlePaddle深度学习底层框架实现对照片的快速P图
开源深度学习平台飞桨下载,详细的安装步骤在此
(base) warmtree@warmtree-HP-Pavilion-Laptop-15-cc5xx:~$ which python3
/home/warmtree/anaconda3/bin/python3
(base) warmtree@warmtree-HP-Pavilion-Laptop-15-cc5xx:~$ python3 --version
Python 3.7.3
(base) warmtree@warmtree-HP-Pavilion-Laptop-15-cc5xx:~$ python3 -m ensurepip
Looking in links: /tmp/tmpbk5oru46
Requirement already satisfied: setuptools in ./anaconda3/lib/python3.7/site-packages (46.1.3)
Requirement already satisfied: pip in ./anaconda3/lib/python3.7/site-packages (19.0.3)
(base) warmtree@warmtree-HP-Pavilion-Laptop-15-cc5xx:~$ python3 -m pip --versionpip 19.0.3 from /home/warmtree/anaconda3/lib/python3.7/site-packages/pip (python 3.7)
(base) warmtree@warmtree-HP-Pavilion-Laptop-15-cc5xx:~$ python3 -c "import platform;print(platform.architecture()[0]);print(platform.machine())"
64bit
x86_64
值得注意的是 python3 -c "import platform;print(platform.architecture()[0]);print(platform.machine())"
可以确认 Python 和 pip 是 64 bit,并且处理器架构是x86_64架构,PaddlePaddle不支持arm64架构。然后,我们输入下面的指令开始安装PaddlePaddle:
(base) warmtree@warmtree-HP-Pavilion-Laptop-15-cc5xx:~$ python3 -m pip install paddlepaddle -i https://mirror.baidu.com/pypi/simple
安装完出现了一个小问题,不知道会不会影响后续的工作,记住incompatible这个词。
Successfully built prettytable pathlib rarfile
tensorflow 2.0.0 has requirement gast==0.2.2, but you'll have gast 0.3.3 which is incompatible.
Installing collected packages: prettytable, objgraph, pathlib, gast, funcsigs, rarfile, opencv-python, paddlepaddle
Found existing installation: gast 0.2.2
Uninstalling gast-0.2.2:
Successfully uninstalled gast-0.2.2
Successfully installed funcsigs-1.0.2 gast-0.3.3 objgraph-3.4.1 opencv-python-4.2.0.34 paddlepaddle-1.8.1 pathlib-1.0.1 prettytable-0.7.2 rarfile-3.1
安装deeplabv3p_xception65_humanseg模型,毕业照设计的实质是扣图,该功能主要采用PaddleHub DeepLabv3+模型(deeplabv3p_xception65_humanseg)实现
由于我们的是Linux系统,Linux环境下如果deeplabv3p_xception65_humanseg模型未安装,我们加载模型时则会被自动安装(如下图显示)。
>>> humanseg = hub.Module(name='deeplabv3p_xception65_humanseg')
[2020-06-05 11:21:36,662] [ INFO] - Installing deeplabv3p_xception65_humanseg module
再继续安装paddlehub模块
pip install paddlehub
还是有安装问题没有解决,版本不兼容问题。
Successfully built distlib
spyder 3.3.3 requires pyqt5<=5.12; python_version >= "3", which is not installed.
virtualenv 20.0.21 has requirement importlib-metadata<2,>=0.12; python_version < "3.8", but you'll have importlib-metadata 0.0.0 which is incompatible.
visualdl 2.0.0b4 has requirement six>=1.14.0, but you'll have six 1.12.0 which is incompatible.
Installing collected packages: Jinja2, Werkzeug, flask, Flask-Babel, pyflakes, pycodestyle, flake8, toml, appdirs, distlib, virtualenv, cfgv, identify, nodeenv, pre-commit, Pillow, visualdl, yapf, cma, sentencepiece, colorlog, gunicorn, paddlehub
我们检查是否安装好则在python3环境下运行
>>> import paddle.fluid
>>> paddle.fluid.install_check.run_check()
Running Verify Fluid Program ...
Your Paddle Fluid works well on SINGLE GPU or CPU.
W0605 11:16:24.953212 9766 build_strategy.cc:170] fusion_group is not enabled for Windows/MacOS now, and only effective when running with CUDA GPU.
W0605 11:16:24.954181 9766 fuse_all_reduce_op_pass.cc:74] Find all_reduce operators: 2. To make the speed faster, some all_reduce ops are fused during training, after fusion, the number of all_reduce ops is 1.
Your Paddle Fluid works well on MUTIPLE GPU or CPU.
Your Paddle Fluid is installed successfully! Let's start deep Learning with Paddle Fluid now
>>>
如上证明我们已经安装好了之后,然后我们开始准备人物素材和背景素材。
humanseg = hub.Module(name='deeplabv3p_xception65_humanseg')
student = humanseg.segmentation(data={'image':[imgs]})
关于python图片的输入问题,其实有蛮多的库