视觉任务LinuxSDK集成文档-Python
更新时间:2020-11-26
简介
本文档介绍 EasyDL 的 Linux Python SDK 的使用方法,适用于 EasyDL 经典版和专业版。
- 网络类型支持:图像分类,物体检测
-
硬件支持:
- Intel Movidius MyRIAD2 / MyRIAD X
- 语言支持:Python 3.5, 3.6, 3.7
Release Notes
时间 | 版本 | 说明 |
---|---|---|
2020.09.17 | 1.1.19 | 支持更多模型 |
2020.08.11 | 1.1.18 | 性能优化 |
2020.06.23 | 1.1.17 | 支持更多EasyDL专业版模型 |
2020.04.16 | 1.1.15 | 技术优化;升级 OpenVINO 版本 |
2020.01.16 | 1.1.12 | 预测函数默认使用推荐阈值 |
2019.12.26 | 1.1.11 | EasyDL 专业版支持加速棒 |
2019.10.21 | 1.1.9 | 支持 EasyDL 专业版 |
2019.07.19 | 1.1.7 | 提供模型更新工具 |
2019.03.15 | 1.1.0 | 架构与功能完善 |
2019.02.28 | 1.0.6 | 引擎功能完善 |
2019.02.13 | 1.0.5 | paddlepaddle 支持 |
2018.11.30 | 1.0.0 | 第一版! |
快速开始
1. 安装依赖
根据引擎的不同,SDK 依赖了不同的底层引擎。根据所需自行安装。
安装 openvino
使用Intel Movidius
加速棒 SDK 预测时,必须安装 OpenVINO 预测引擎,两种方式:
- 使用 OpenVINO™ toolkit 安装,请参考 OpenVINO toolkit 文档安装 2020.1(必须)版本, 安装时可忽略
Configure the Model Optimizer
及后续部分。 - 使用源码编译安装,请参考 Openvino Inference Engine文档编译安装 2020.1(必须)版本。
2. 安装 easyedge python wheel 包
pip3 install -U BaiduAI_EasyEdge_SDK-{版本号}-cp36-cp36m-linux_x86_64.whl
具体名称以 SDK 包中的 whl 为准。
3. 使用序列号激活
获取序列号
修改demo.py
填写序列号
edge.set_auth_license_key("这里填写序列号")
4. 测试 Demo
输入对应的模型文件夹(默认为RES
)和测试图片路径,运行:
python3 demo.py {model_dir} {image_name.jpg}
测试效果:
使用说明
使用流程
import BaiduAI.EasyEdge as edge
edge.set_auth_license_key("这里填写序列号")
pred = edge.Program()
pred.init(model_dir={RES文件夹路径}, device=edge.Device.MOVIDIUS, engine=edge.Engine.OPENVINO)
pred.infer_image({numpy.ndarray的图片})
pred.close()
初始化
- 接口
def init(self,
model_dir,
device=Device.LOCAL,
engine=Engine.PADDLE_FLUID,
config_file='conf.json',
preprocess_file='preprocess_args.json',
model_file='model',
params_file='params',
graph_file='graph.ncsmodel',
label_file='label_list.txt',
device_id=0
):
"""
Args:
device: Device.CPU
engine: Engine.PADDLE_FLUID
model_dir: str
model dir
preprocess_file: str
model_file: str
params_file: str
graph_file: str
label_file: str
device_id: int
Raises:
RuntimeError, IOError
Returns:
bool: True if success
"""
预测图像
- 接口
def infer_image(self, img,
threshold=0.3,
channel_order='HWC',
color_format='BGR',
data_type='numpy'):
"""
Args:
img: np.ndarray or bytes
threshold: float
only return result with confidence larger than threshold
channel_order: string
channel order HWC or CHW
color_format: string
color format order RGB or BGR
data_type: string
image data type
Returns:
list
"""
- 返回格式:
[dict1, dict2, ...]
字段 | 类型 | 取值 | 说明 |
---|---|---|---|
confidence | float | 0~1 | 分类或检测的置信度 |
label | string | 分类或检测的类别 | |
index | number | 分类或检测的类别 | |
x1, y1 | float | 0~1 | 物体检测,矩形的左上角坐标 (相对长宽的比例值) |
x2, y2 | float | 0~1 | 物体检测,矩形的右下角坐标(相对长宽的比例值) |
mask | string/numpy.ndarray | 图像分割的mask |
关于矩形坐标
x1 * 图片宽度 = 检测框的左上角的横坐标
y1 * 图片高度 = 检测框的左上角的纵坐标
x2 * 图片宽度 = 检测框的右下角的横坐标
y2 * 图片高度 = 检测框的右下角的纵坐标
可以参考 demo 文件中使用 opencv 绘制矩形的逻辑。
结果示例
- i) 图像分类
{
"index": 736,
"label": "table",
"confidence": 0.9
}
- ii) 物体检测
{
"y2": 0.91211,
"label": "cat",
"confidence": 1.0,
"x2": 0.91504,
"index": 8,
"y1": 0.12671,
"x1": 0.21289
}
- iii) 图像分割
{
"name": "cat",
"score": 1.0,
"location": {
"left": ...,
"top": ...,
"width": ...,
"height": ...,
},
"mask": ...
}
mask字段中,data_type为numpy
时,返回图像掩码的二维数组
{
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 1, 1, 1, 0, 0, 0, 0},
{0, 0, 0, 1, 1, 1, 0, 0, 0, 0},
{0, 0, 0, 1, 1, 1, 0, 0, 0, 0},
{0, 0, 0, 1, 1, 1, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
}
其中1代表为目标区域,0代表非目标区域
data_type为string
时,mask的游程编码,解析方式可参考 demo
升级模型
适用于经典版升级模型,执行bash update_model.sh
,根据提示,输入模型路径、激活码、模型ID、模型版本,等待模型更新完毕即可。