如何用PaddlePaddle在短时间内P图一个毕业照片

本篇文章是基于新冠疫情下,毕业照怎么拍?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]})

别再用PS了,我用五行Python代码就实现了批量抠图

关于python图片的输入问题,其实有蛮多的库

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

肥鼠路易

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值