赞
踩
python -m pip install paddlepaddle -i https://mirror.baidu.com/pypi/simple
安装成功后,我们在 python 环境中测试一下是否安装成功(这个也是按照官网指引来做),我们切换到 python 环境,运行如下代码:
Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 26 2018, 23:26:24) [Clang 6.0 (clang-600.0.57)] on darwinType "help", "copyright", "credits" or "license" for more information.>>> import paddle.fluid>>> paddle.fluid.install_check.run_check()Running Verify Paddle Program ... Your Paddle works well on SINGLE GPU or CPU.I0506 21:47:48.657404 2923565952 parallel_executor.cc:440] The Program will be executed on CPU using ParallelExecutor, 2 cards are used, so 2 programs are executed in parallel.W0506 21:47:48.658407 2923565952 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.I0506 21:47:48.658516 2923565952 build_strategy.cc:365] SeqOnlyAllReduceOps:0, num_trainers:1I0506 21:47:48.659137 2923565952 parallel_executor.cc:307] Inplace strategy is enabled, when build_strategy.enable_inplace = TrueI0506 21:47:48.659595 2923565952 parallel_executor.cc:375] Garbage collection strategy is enabled, when FLAGS_eager_delete_tensor_gb = 0Your Paddle works well on MUTIPLE GPU or CPU.Your Paddle is installed successfully! Let's start deep Learning with Paddle now>>>
看到 Your Paddle is installed successfully 就表示安装成功了。
我们接下来需要使用的是这个平台的 paddlehub 工具,所以我们还需要安装 paddlehub :
pip install -i https://mirror.baidu.com/pypi/simple paddlehub
安装完成后,我们就可以开始运用了。
import os, paddlehub as hubhuseg = hub.Module(name='deeplabv3p_xception65_humanseg') # 加载模型path = './imgs/' # 文件目录files = [path + i for i in os.listdir(path)] # 获取文件列表results = huseg.segmentation(data={'image': files}) # 抠图
我将图片放在代码文件夹的同级目录 imgs 文件夹下。
运行代码后,输出的抠图图片会自动放在代码同级目录的 humanseg_output 目录下。
文件名称跟原图片的名称相同,但是文件格式是 png 。
我在 imgs 目录下放了5张图片,为了便于展示,我将他们放在一起截图:
-END-
往期精彩
1、用python更换“必应图片”为“桌面壁纸”2、用python爬取海贼王漫画推送kindle3、python学习,100天从新手到大师
@GitPython
一个有料又有颜的编程技术号
你 “在看” 我吗?
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。