携手创作,共同成长!这是我参与「掘金日新计划 · 8 月更文挑战」的第29天,github.com/PaddlePaddl…
**### 待部署模型能力展示——实时扣图
1. Python + CPU部署流程
运行Demo,感受部署能力
1.安装FastDeploy的lib库
2.准备实时扣图MODNet模型 和 推理示例代码
3.运行推理代码
API调用,集成到自己项目中
## 运行Demo,感受部署能力
# (1) 安装FastDeploy CPU库
!pip install fastdeploy-python -f https://www.paddlepaddle.org.cn/whl/fastdeploy.html -q
# (2)准备MODNet模型和推理示例代码
# 推理示例代码;(如果是自己调用API完成,这部分代码都可以不用下载)
# !git clone https://gitee.com/PaddlePaddle/FastDeploy.git
%cd FastDeploy/examples/vision/matting/modnet/python/
/home/aistudio/FastDeploy/examples/vision/matting/modnet/python
!pip list|grep fastdeploy
fastdeploy-python 0.2.0
# 下载提前转换好的推理模型和图像
!wget https://bj.bcebos.com/paddlehub/fastdeploy/modnet_photographic_portrait_matting.onnx
# !wget https://raw.githubusercontent.com/DefTruth/lite.ai.toolkit/main/examples/lite/resources/test_lite_matting_input.jpg
--2022-08-26 16:39:02-- https://raw.githubusercontent.com/DefTruth/lite.ai.toolkit/main/examples/lite/resources/test_lite_matting_input.jpg
正在解析主机 raw.githubusercontent.com (raw.githubusercontent.com)... 185.199.108.133, 185.199.109.133, 185.199.110.133, ...
正在连接 raw.githubusercontent.com (raw.githubusercontent.com)|185.199.108.133|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度: 278476 (272K) [image/jpeg]
正在保存至: “test_lite_matting_input.jpg”
test_lite_ 0%[ ] 1.34K 327 B/s eta 14m 7s ^C
# CPU 推理预测,输出结果保存在FastDeploy/examples/vision/matting/modnet/python/visualized_result.jpg图像中
!python infer.py --model modnet_photographic_portrait_matting.onnx --image 1.jpg --device cpu
Visualized result save in ./visualized_result.jpg
#API调用,集成到自己项目中(需按FastDeploy模型文档要求,准备好部署模型;或者直接下载FastDeploy中已经提供好的模型)
(此处打开infer.py直接讲解就行。)
2. Python + GPU部署流程
特别说明:
- GPU部署与CPU部署流程区别:
- GPU部署,需要提前准备好CUDA>=11.2环境要求,CUCA版本需要按照FastDeploy软硬件要求来
- aistudio上的GPU环境,目前只有A100 40G满足CUDA>=11.2要求
#安装FastDeploy-GPU版本
!pip install fastdeploy-gpu-python -f https://www.paddlepaddle.org.cn/whl/fastdeploy.html
# 准备MODNet模型和推理示例代码
# 推理示例代码
!git clone https://github.com/PaddlePaddle/FastDeploy.git
%cd FastDeploy/examples/vision/matting/modnet/python/
# 下载提前转换好的推理模型和图像
# 注意:测试图像目前放在github上,wget有一些慢,如果自己有测试图像,可以选择跳过。
!wget https://bj.bcebos.com/paddlehub/fastdeploy/modnet_photographic_portrait_matting.onnx
!wget https://raw.githubusercontent.com/DefTruth/lite.ai.toolkit/main/examples/lite/resources/test_lite_matting_input.jpg
# GPU 推理预测,输出结果保存在FastDeploy/examples/vision/matting/modnet/python/visualized_result.jpg图像中
!python infer.py --model modnet_photographic_portrait_matting.onnx --image test_lite_matting_input.jpg --device gpu