FastDeploy 安装部署

简介: FastDeploy 安装部署

一、FastDeploy 安装


由于编译配置较为困难(本地环境可能有误),建议大家使用已编译好的whl包。

FastDeploy 预编编译Python Wheel包


FastDeploy提供了在Windows/Linux/Mac上的预先编译Python Wheel包,开发者可以直接下载后安装,也可以自行编译代码。


使用如下命令即可在Linux的Pythotn 3.8环境安装支持CPU部署的FastDeploy

python -m pip install fastdeploy_python-0.2.0-cp38-cp38-manylinux1_x86_64.whl


1.注意事项


  • 不要重复安装fastdeploy-pythonfastdeploy-gpu-python
  • 如已安装CPU版本的fastdeploy-python后,在安装GPU版本的fastdeploy-gpu-python,请先执行pip uninstall fastdeploy-python卸载已有版本


2.环境依赖


  • cuda >= 11.2
  • cudnn >= 8.0


3.下载地址


3.1 Linux x64平台



3.2 Windows 10 x64平台



3.3 Linux aarch64平台



3.4 Mac OSX平台



4.其它文档



二、实践


1.git下载

# git下载
 !git clone -b develop https://github.com/PaddlePaddle/FastDeploy.git --depth=1
Cloning into 'FastDeploy'...
remote: Enumerating objects: 1253, done.
remote: Counting objects: 100% (1253/1253), done.
remote: Compressing objects: 100% (965/965), done.
remote: Total 1253 (delta 309), reused 1046 (delta 242), pack-reused 0
Receiving objects: 100% (1253/1253), 2.37 MiB | 57.00 KiB/s, done.
Resolving deltas: 100% (309/309), done.
Checking connectivity... done.


2.查看系统环境


!python --version
Python 3.7.4
!nvidia-smi
Wed Aug 17 21:21:49 2022       
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 460.32.03    Driver Version: 460.32.03    CUDA Version: 11.2     |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|                               |                      |               MIG M. |
|===============================+======================+======================|
|   0  Tesla V100-SXM2...  On   | 00000000:43:00.0 Off |                    0 |
| N/A   42C    P0    41W / 300W |      0MiB / 32510MiB |      0%      Default |
|                               |                      |                  N/A |
+-------------------------------+----------------------+----------------------+
+-----------------------------------------------------------------------------+
| Processes:                                                                  |
|  GPU   GI   CI        PID   Type   Process name                  GPU Memory |
|        ID   ID                                                   Usage      |
|=============================================================================|
|  No running processes found                                                 |
+-----------------------------------------------------------------------------+

可见环境满足条件

  • python 3.7
  • cuda 11.


3.linux安装


!pip install https://bj.bcebos.com/paddlehub/fastdeploy/wheels/fastdeploy_gpu_python-0.2.0-cp37-cp37m-manylinux1_x86_64.whl
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Collecting fastdeploy-gpu-python==0.2.0
  Downloading https://bj.bcebos.com/paddlehub/fastdeploy/wheels/fastdeploy_gpu_python-0.2.0-cp37-cp37m-manylinux1_x86_64.whl (1508.4 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.5/1.5 GB 711.9 kB/s eta 0:00:0000:0100:01
[?25hRequirement already satisfied: tqdm in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from fastdeploy-gpu-python==0.2.0) (4.27.0)
Requirement already satisfied: requests in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from fastdeploy-gpu-python==0.2.0) (2.24.0)
Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from requests->fastdeploy-gpu-python==0.2.0) (1.25.6)
Requirement already satisfied: idna<3,>=2.5 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from requests->fastdeploy-gpu-python==0.2.0) (2.8)
Requirement already satisfied: chardet<4,>=3.0.2 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from requests->fastdeploy-gpu-python==0.2.0) (3.0.4)
Requirement already satisfied: certifi>=2017.4.17 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from requests->fastdeploy-gpu-python==0.2.0) (2019.9.11)
Installing collected packages: fastdeploy-gpu-python
Successfully installed fastdeploy-gpu-python-0.2.0
[notice] A new release of pip available: 22.1.2 -> 22.2.2
[notice] To update, run: pip install --upgrade pip
!python -m pip install --upgrade pip --use
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Requirement already satisfied: pip in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (22.1.2)
Collecting pip
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/1f/2c/d9626f045e7b49a6225c6b09257861f24da78f4e5f23af2ddbdf852c99b8/pip-22.2.2-py3-none-any.whl (2.0 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 2.0/2.0 MB 4.1 MB/s eta 0:00:0000:0100:01
[?25hInstalling collected packages: pip
Successfully installed pip-22.2.2
[notice] A new release of pip available: 22.1.2 -> 22.2.2
[notice] To update, run: python -m pip install --upgrade pip


4.运行


4.1下载PaddleSeg


!git clone https://gitee.com/PaddlePaddle/PaddleSeg.git --depth=1
Cloning into 'PaddleSeg'...
remote: Enumerating objects: 1815, done.
remote: Counting objects: 100% (1815/1815), done.
remote: Compressing objects: 100% (1450/1450), done.
remote: Total 1815 (delta 485), reused 1227 (delta 287), pack-reused 0
Receiving objects: 100% (1815/1815), 48.94 MiB | 9.42 MiB/s, done.
Resolving deltas: 100% (485/485), done.
Checking connectivity... done.


4.2 获取预训练模型


%cd ~/PaddleSeg/
!mkdir bisenet
%cd bisenet
!wget https://paddleseg.bj.bcebos.com/dygraph/cityscapes/bisenet_cityscapes_1024x1024_160k/model.pdparams
%cd ../..
/home/aistudio/PaddleSeg
mkdir: cannot create directory ‘bisenet’: File exists
/home/aistudio/PaddleSeg/bisenet
--2022-08-17 21:41:56--  https://paddleseg.bj.bcebos.com/dygraph/cityscapes/bisenet_cityscapes_1024x1024_160k/model.pdparams
Resolving paddleseg.bj.bcebos.com (paddleseg.bj.bcebos.com)... 100.67.200.6
Connecting to paddleseg.bj.bcebos.com (paddleseg.bj.bcebos.com)|100.67.200.6|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 15301992 (15M) [application/octet-stream]
Saving to: ‘model.pdparams’
model.pdparams      100%[===================>]  14.59M  88.4MB/s    in 0.2s    
2022-08-17 21:41:56 (88.4 MB/s) - ‘model.pdparams’ saved [15301992/15301992]
/home/aistudio


4.3导出静态模型


%cd ~/PaddleSeg/
# 设置1张可用的卡
!export CUDA_VISIBLE_DEVICES=0
# windows下请执行以下命令
# set CUDA_VISIBLE_DEVICES=0
!python export.py \
       --config configs/bisenet/bisenet_cityscapes_1024x1024_160k.yml \
       --model_path bisenet/model.pdparams \
       --save_dir output \
       --input_shape 1 3 512 1024
/home/aistudio/PaddleSeg
/home/aistudio/PaddleSeg/paddleseg/models/losses/rmi_loss.py:78: DeprecationWarning: invalid escape sequence \i
  """
W0817 21:43:59.497787  2170 gpu_resources.cc:61] Please NOTE: device: 0, GPU Compute Capability: 7.0, Driver API Version: 11.2, Runtime API Version: 10.1
W0817 21:43:59.501492  2170 gpu_resources.cc:91] device: 0, cuDNN Version: 7.6.
2022-08-17 21:44:01 [INFO]  Loaded trained params of model successfully.
2022-08-17 21:44:03 [INFO]  Model is saved in output.
!ls output/
deploy.yaml  model.pdiparams  model.pdiparams.info  model.pdmodel


三、预测


在部署前,需确认以下两个步骤

  1. 软硬件环境满足要求,参考FastDeploy环境要求
  2. FastDeploy Python whl包安装,参考FastDeploy Python安装

本目录下提供infer.py快速完成Unet在CPU/GPU,以及GPU上通过TensorRT加速部署的示例。执行如下脚本即可完成

- 下载部署示例代码
git clone https://github.com/PaddlePaddle/FastDeploy.git
cd FastDeploy/examples/vision/segmentation/paddleseg/python
# 下载Unet模型文件和测试图片
wget https://bj.bcebos.com/paddlehub/fastdeploy/Unet_cityscapes_without_argmax_infer.tgz
tar -xvf Unet_cityscapes_without_argmax_infer.tgz
wget https://paddleseg.bj.bcebos.com/dygraph/demo/cityscapes_demo.png
# CPU推理
python infer.py --model Unet_cityscapes_without_argmax_infer --image cityscapes_demo.png --device cpu
# GPU推理
python infer.py --model Unet_cityscapes_without_argmax_infer --image cityscapes_demo.png --device gpu
# GPU上使用TensorRT推理 (注意:TensorRT推理第一次运行,有序列化模型的操作,有一定耗时,需要耐心等待)
python infer.py --model Unet_cityscapes_without_argmax_infer --image cityscapes_demo.png --device gpu --use_trt True

运行完成可视化结果如下图所示

image.png


1. PaddleSegModel Python接口


fd.vision.segmentation.PaddleSegModel(model_file, params_file, config_file, runtime_option=None, model_format=Frontend.PADDLE)

PaddleSeg模型加载和初始化,其中model_file, params_file以及config_file为训练模型导出的Paddle inference文件,具体请参考其文档说明模型导出

参数

  • model_file(str): 模型文件路径
  • params_file(str): 参数文件路径
  • config_file(str): 推理部署配置文件
  • runtime_option(RuntimeOption): 后端推理配置,默认为None,即采用默认配置
  • model_format(Frontend): 模型格式,默认为Paddle格式


2.predict函数


PaddleSegModel.predict(input_image)码

模型预测结口,输入图像直接输出检测结果。

参数

  • input_image(np.ndarray): 输入数据,注意需为HWC,BGR格式

返回

返回fastdeploy.vision.SegmentationResult结构体,结构体说明参考文档视觉模型预测结果


3.类成员属性


3.1 预处理参数


用户可按照自己的实际需求,修改下列预处理参数,从而影响最终的推理和部署效果

  • is_vertical_screen(bool): PP-HumanSeg系列模型通过设置此参数为true表明输入图片是竖屏,即height大于width的图片


3.2 后处理参数


  • with_softmax(bool): 当模型导出时,并未指定with_softmax参数,可通过此设置此参数为true,将预测的输出分割标签(label_map)对应的概率结果(score_map)做softmax归一化处理


4.其它文档



相关实践学习
部署Stable Diffusion玩转AI绘画(GPU云服务器)
本实验通过在ECS上从零开始部署Stable Diffusion来进行AI绘画创作,开启AIGC盲盒。
目录
相关文章
|
机器学习/深度学习 Web App开发 文字识别
OCRmypdf安装部署深入详解
1、OCRmypdf简介 OCRmyPDF使用最好的可用开源OCR引擎Tesseract执行OCR。 OCRmyPDF是一个Python 3包,将OCR图层处理结果添加到PDF。 OCRmyPDF是功能最丰富且经过彻底测试的OCR PDF转换工具。 2、OCRmypdf支持的系统 1) macOS 2) Ubuntu 16.04 LTS 3)ArchLinux 4)Windows 此外,OCRmypdf提供了docker镜像,可以直接下载镜像、使用。
981 0
|
弹性计算 关系型数据库 应用服务中间件
Wordpress 安装部署
简单几个步骤即可使用 ECS、RDS 进行 wordpress 安装,完成内容站点的部署。
178 0
|
域名解析 JSON 网络协议
freeipa安装部署
freeipa是linux的一个开源的安全解决方案,它提供账户管理和集中认证,类似于微软的AD(active directory)。
3758 0
|
SQL 分布式计算 关系型数据库
安装部署 | 学习笔记
快速学习 安装部署
134 0
安装部署 | 学习笔记
|
关系型数据库 数据库 PostgreSQL
pgAgent安装部署
pgAgent是PostgreSQL的一个job引擎,可以执行数据库job任务。本文简述其安装步骤 一 安装cmake #检查是否安装 [root@bogon ~]# cmake --version cmake version 2.
2595 0
|
Linux Docker 容器
安装部署应用
安装部署应用
107 0
|
jenkins Java 测试技术
jenkins安装部署实战
Jenkins安装部署 1、首先下载Jenkins.war包,官网:https://jenkins.io/download/,这块用的比较老,为了和配管的版本一致。 2、部署好Jdk和Tomcat 3、去apache官网下载maven软件包,部署好maven 4、svn环境,可以参考之前的博客配置web访问svn仓库篇。
1016 0
|
应用服务中间件 调度 nginx
DockerSwarm 集群环境搭建
Docker Swarm 是一个为 IT 运维团队提供集群和调度能力的编排工具。用户可以把集群中所有 Docker Engine 整合进一个「虚拟 Engine」的资源池,通过执行命令与单一的主 Swarm 进行沟通,而不必分别和每个 Docker Engine 沟通。
1406 0
|
关系型数据库 Java MySQL
|
虚拟化 数据安全/隐私保护