轻松实现Rust系统入门,实战编译器开发gdsgdas

479 阅读2分钟

轻松实现Rust系统入门,实战编译器开发

download:链接:pan.baidu.com/s/190DmP3Tl… 提取码:wx3k --来自百度网盘超级会员V4的分享

准备工作

既然要装逼,准备工作是少不了的。所谓“站在伟人的肩膀上,做事事半功倍”,我们这里的“伟人”就是 paddlepaddle 了,中文称号叫“飞桨”,那么这个 paddlepaddle 是什么呢?

它是“源于产业理论的开源深度学习平台,努力于让深度学习技术的创新与应用更简单”,直白点就是我帮你完成了深度学习底层框架,你只需有创意就能够在我平台上运用少量简单代码轻松完成。它的官网是 www.paddlepaddle.org.cn/

它的装置也比拟简单,官网首页就有装置指引,我们这里依据官网的装置指引,运用 pip 方式来装置 CPU 版本。

我们首先执行语句:

python -m pip install paddlepaddle -i 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 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 。