图像分割WindowsSDK集成文档
简介
本文档介绍图像分割服务器端Windows SDK的使用方法。
-
硬件支持:
- Intel CPU 普通版 * x86_64
- CPU 加速版 - Intel Xeon with AVX2 and AVX512 - Intel Core Processors with AVX2 - Intel Atom Processors with SSE * - AMD Core Processors with AVX2
- Intel Movidius MyRIAD2/MyRIAD X (仅支持Win10)
-
操作系统支持
- 普通版:64位 Windows 7 及以上,64位Windows Server2012及以上
- 加速版:64位 Windows 10,64位Windows Server 2019及以上
-
环境依赖(必须安装以下版本)
- .NET Framework 4.5
- Visual C++ Redistributable Packages for Visual Studio 2013
- Visual C++ Redistributable Packages for Visual Studio 2015-2019
-
协议
- HTTP
- 更详细的环境说明可参考SDK内的README.md
*intel 官方合作,拥有更好的适配与性能表现
Release Notes
时间 | 版本 | 说明 |
---|---|---|
2023-08-30 | 1.8.3 | 新增支持按实例数鉴权 |
2023-06-29 | 1.8.2 | 优化模型算法 |
2023-05-17 | 1.8.1 | 预测引擎升级,修复部分网络内存泄露问题 |
2023-03-16 | 1.8.0 | 预测引擎升级 |
2022-12-29 | 1.7.2 | 预测引擎升级 |
2022-10-27 | 1.7.1 | 优化模型算法 |
2022-09-15 | 1.7.0 | 新增支持表格预测 |
2022-07-28 | 1.6.0 | 优化模型算法 |
2022-05-27 | 1.5.1 | 新增支持BML Cloud小目标检测模型 |
2022-05-18 | 1.5.0 | 修复各别机器下程序崩溃的问题 |
2022-04-25 | 1.4.1 | EasyDL, BML升级支持paddle2模型 |
2022-03-25 | 1.4.0 | 优化模型算法 |
2021-12-22 | 1.3.5 | CPU基础版推理引擎优化升级;demo程序优化环境依赖检测 |
2021-10-20 | 1.3.4 | CPU加速版推理引擎优化升级 |
2021-08-19 | 1.3.2 | 新增DEMO二进制文件 |
2021-06-29 | 1.3.1 | 预测引擎升级 |
2021-05-13 | 1.3.0 | 模型发布新增多种加速方案选择;目标追踪支持x86平台的GPU及加速版;展示已发布模型性能评估报告 |
2021-04-08 | 1.2.3 | 支持BML平台模型仓库本地上传模型 |
2021-03-09 | 1.2.2 | CPU加速版支持int8量化模型 |
2021-01-27 | 1.2.1 | 新增模型支持;性能优化;问题修复 |
2020.12.18 | 1.2.0 | 推理引擎升级 |
2020-11-26 | 1.1.20 | 新增一些模型的加速版支持 |
2020.10.29 | 1.1.20 | 修复已知问题 |
2020.05.15 | 1.1.16 | 优化性能,修复已知问题 |
2020-09-17 | 1.1.19 | 支持更多模型 |
2020.08.11 | 1.1.18 | 支持专业版更多模型 |
2020.06.23 | 1.1.17 | 支持专业版更多模型 |
2020.05.15 | 1.1.16 | 优化性能,修复已知问题 |
2020.04.16 | 1.1.15 | 升级引擎版本 |
2020.03.13 | 1.1.14 | 支持EdgeBoardVMX |
2020.02.23 | 1.1.13 | 支持多阶段模型 |
2020.01.16 | 1.1.12 | 预测默认使用推荐阈值 |
2019.12.26 | 1.1.11 | CPU加速版支持物体检测高精度 |
2019.12.04 | 1.1.10 | 支持图像分割 |
2019.10.21 | 1.1.9 | 支持 EasyDL 专业版 |
2019.08.29 | 1.1.8 | CPU 加速版支持 |
2019.07.19 | 1.1.7 | 提供模型更新工具 |
2019.05.16 | 1.1.3 | NVIDIA GPU 支持 |
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. 安装依赖
必须安装:
安装.NET Framework4.5
1https://www.microsoft.com/zh-CN/download/details.aspx?id=42642
Visual C++ Redistributable Packages for Visual Studio 2013
1https://www.microsoft.com/zh-cn/download/details.aspx?id=40784
Visual C++ Redistributable Packages for Visual Studio 2015-2019
1https://docs.microsoft.com/en-us/cpp/windows/latest-supported-vc-redist?view=msvc-160
可选安装:
Openvino (仅使用Python Intel Movidius必须)
- 使用 OpenVINO™ toolkit 安装,请参考 OpenVINO toolkit 文档安装 2020.3.1LTS(必须)版本, 安装时可忽略
Configure the Model Optimizer
及后续部分。 - 使用源码编译安装,请参考 Openvino Inference Engine文档编译安装 2020.3.1LTS(必须)版本。
安装完成后,请设置环境变量OPENVINO_HOME
为您设置的安装地址,默认是C:\Program Files (x86)\IntelSWTools
,并确保文件夹下的openvino的快捷方式指到了2020.3.1LTS版本。
注意事项
- 安装目录不能包含中文
- Windows Server 请自行开启,选择“我的电脑”——“属性”——“管理”——”添加角色和功能“——勾选”桌面体验“,点击安装,安装之后重启即可。
2. 运行离线SDK
解压下载好的SDK,打开EasyEdge.exe,输入Serial Num,选择鉴权模式,点击"启动服务",等待数秒即可启动成功,本地服务默认运行在
1http://127.0.0.1:24401/
其他任何语言只需通过HTTP调用即可。
2.1 离线鉴权(默认鉴权模式)
首次联网激活,后续离线使用
2.2 按实例数鉴权
周期性联网激活,离线后会释放所占用鉴权,启动时请确保心跳间隔小于等于生成序列号时填写的定期确认时间
基于源码集成时,若需要按实例数鉴权,需要通过代码指定使用按实例数鉴权
1global_controller()->set_config(easyedge::params::CONTROLLER_KEY_AUTH_MODE, 2);
2global_controller()->set_config(easyedge::params::CONTROLLER_KEY_INSTANCE_UPDATE_INTERVAL, 20);
或通过环境变量指定
1set EDGE_CONTROLLER_KEY_AUTH_MODE=2
2set EDGE_CONTROLLER_KEY_INSTANCE_UPDATE_INTERVAL=20
2.3 序列号激活错误码
错误码 | 文案 | 描述 |
---|---|---|
4001 | parameters missing. 参数缺失 | |
4002 | parameters invalid. 参数不合法 | |
4003 | model invalid. 模型信息不合法 | |
4004 | no more activation left. 该序列号和该设备的激活次数超上限 | |
4005 | the serial key is out of date. 该序列号过期 | |
4006 | the serial key has been activated. 该序列号已被其他设备激活 | 该序列号已被其他设备激活,不能重复激活。 |
4007 | account invalid. 序列号不能用于其他账号的模型 | 序列号不能用于其他账号的模型,只能用于绑定账号的模型。 |
4008 | serial key invalid. 序列号不合法 | 序列号不存在或找不到 |
4009 | bundle id invalid. 包名不合法 | |
4010 | product invalid. 产品不合法 | 如easydl的SDK使用BML的序列号来激活,会报该错误 |
4011 | platform invalid. 平台不合法 | |
4012 | activate too frequent. 激活太频繁 | 激活太频繁,请稍后再进行激活。 |
4013 | device type and license type not match. 硬件类型和序列号类型不匹配 | 如使用加速版序列号激活基础版SDK会报该错误 |
4014 | exceed max activate device num. 超过最大授权数量 | |
4015 | technology invalid. 技术类型不合法 | |
4016 | exceed max activate entity num. 超过最大模型数量 | |
4017 | device invalid. 设备不合法 | |
4018 | model invalid. 模型不合法 |
3. Demo示例(以图像服务为例)
服务运行成功,此时可直接在浏览器中输入http://127.0.0.1:24401
,在h5中测试模型效果。
使用说明
调用说明
使用示例代码如下
1import requests
2
3with open('./1.jpg', 'rb') as f:
4 img = f.read()
5
6## params 为GET参数 data 为POST Body
7result = requests.post('http://127.0.0.1:24401/', params={'threshold': 0.1},
8 data=img).json()
9print(result)
1FileStream fs = new FileStream("./img.jpg", FileMode.Open);
2BinaryReader br = new BinaryReader(fs);
3byte[] img = br.ReadBytes((int)fs.Length);
4br.Close();
5fs.Close();
6string url = "http://127.0.0.1:8402?threshold=0.1";
7HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);
8request.Method = "POST";
9Stream stream = request.GetRequestStream();
10stream.Write(img, 0, img.Length);
11stream.Close();
12
13WebResponse response = request.GetResponse();
14StreamReader sr = new StreamReader(response.GetResponseStream());
15Console.WriteLine(sr.ReadToEnd());
16sr.Close();
17response.Close();
1// 使用示例代码如下,需要安装curl
2#include <sys/stat.h>
3#include <curl/curl.h>
4#include <iostream>
5#include <string>
6#define S_ISREG(m) (((m) & 0170000) == (0100000))
7#define S_ISDIR(m) (((m) & 0170000) == (0040000))
8
9size_t write_callback(void *ptr, size_t size, size_t num, void *data) {
10 std::string *str = dynamic_cast<std::string *>((std::string *)data);
11 str->append((char *)ptr, size*num);
12 return size*num;
13}
14
15int main(int argc, char *argv[]) {
16 const char *post_data_filename = "./img.jpg";
17 FILE *fp = NULL;
18 std::string response;
19 struct stat stbuf = { 0, };
20 fp = fopen(post_data_filename, "rb");
21 if (!fp) {
22 fprintf(stderr, "Error: failed to open file \"%s\"\n", post_data_filename);
23 return -1;
24 }
25 if (fstat(fileno(fp), &stbuf) || !S_ISREG(stbuf.st_mode)) {
26 fprintf(stderr, "Error: unknown file size \"%s\"\n", post_data_filename);
27 return -1;
28 }
29 CURL *curl;
30 CURLcode res;
31 curl_global_init(CURL_GLOBAL_ALL);
32 curl = curl_easy_init();
33 if (curl != NULL) {
34 curl_easy_setopt(curl, CURLOPT_URL, "http://127.0.0.1:24401?threshold=0.1");
35 curl_easy_setopt(curl, CURLOPT_POST, 1L);
36 curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE_LARGE,(curl_off_t)stbuf.st_size);
37 curl_easy_setopt(curl, CURLOPT_READDATA, (void *)fp);
38 curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_callback);
39 curl_easy_setopt(curl, CURLOPT_WRITEDATA, &response);
40 res = curl_easy_perform(curl);
41
42 if (res != CURLE_OK) {
43 fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
44 }
45 std::cout << response << std::endl; // response即为返回的json数据
46 curl_easy_cleanup(curl);
47 }
48 curl_global_cleanup();
49 fclose(fp);
50 return 0;
51}
1import java.io.*;
2import java.net.HttpURLConnection;
3import java.net.URL;
4
5public class Main {
6 public static void main(String[] args) {
7 String result = doPostFile("http://127.0.0.1:24401/?threshold=0.1", "./1.jpg");
8 System.out.println(result);
9 }
10
11 private static String doPostFile(String reqUrl, String fileUrl) {
12 HttpURLConnection url_con = null;
13 String responseContent = null;
14 try {
15 URL url = new URL(reqUrl);
16 url_con = (HttpURLConnection) url.openConnection();
17 url_con.setRequestMethod("POST");
18 url_con.setDoOutput(true);
19 byte[] data = Util.readFileByBytes(fileUrl);
20 url_con.getOutputStream().write(data, 0, data.length);
21 url_con.getOutputStream().flush();
22 url_con.getOutputStream().close();
23 InputStream in = url_con.getInputStream();
24 BufferedReader rd = new BufferedReader(new InputStreamReader(in , "UTF-8"));
25 String tempLine = rd.readLine();
26 StringBuffer tempStr = new StringBuffer();
27 String crlf = System.getProperty("line.separator");
28 while (tempLine != null) {
29 tempStr.append(tempLine);
30 tempStr.append(crlf);
31 tempLine = rd.readLine();
32 }
33 responseContent = tempStr.toString();
34 rd.close();
35 in.close();
36 } catch (IOException e) {
37 System.out.println("请求错误信息:" + e.getMessage());
38 } finally {
39 if (url_con != null) {
40 url_con.disconnect();
41 }
42 }
43 return responseContent;
44 }
45
46 static class Util {
47 static byte[] readFileByBytes(String fileUrl) throws IOException {
48 InputStream in = null;
49 ByteArrayOutputStream out = null;
50 try {
51 in = new FileInputStream(fileUrl);
52 out = new ByteArrayOutputStream();
53 byte[] buffer = new byte[1024];
54 int len;
55 while ((len = in.read(buffer)) != -1) {
56 out.write(buffer, 0, len);
57 }
58 return out.toByteArray();
59 } finally {
60 if (in != null) {
61 in.close();
62 }
63 if (out != null) {
64 out.close();
65 }
66 }
67 }
68 }
69}
结果
获取的结果存储在response字符串中。
请求参数
字段 | 类型 | 取值 | 说明 |
---|---|---|---|
threshold | float | 0 ~ 1 | 置信度阈值 |
HTTP POST Body直接发送图片二进制。
返回参数
字段 | 类型 | 取值 | 说明 |
---|---|---|---|
confidence | float | 0~1 | 分割的置信度 |
label | string | 分割的类别 | |
index | number | 分割的类别 | |
mask | string | 游程编码的mask |
代码参考 https://github.com/Baidu-AIP/EasyDL-Segmentation-Demo
集成指南
基于HTTP集成
通过EasyEdge.exe启动服务后,参照上面的调用说明,通过HTTP请求集成到自己的服务中
基于c++ dll集成
集成前提
解压开的SDK包中包含src、lib、dll、include四个目录才支持基于c++ dll集成
集成方法
参考src目录中的CMakeLists.txt进行集成
基于c# dll集成
集成前提
解压开的SDK包中包含src\demo_serving_csharp、dll两个目录才支持基于c# dll集成
集成方法
参考src\demo_serving_csharp目录中的CMakeLists.txt进行集成
FAQ
1. 服务启动失败,怎么处理?
根据SDK内的README.md检查依赖是否都已正确安装
请确保相关依赖都安装正确,版本必须如下: .NET Framework 4.5 Visual C++ Redistributable Packages for Visual Studio 2013 * Visual C++ Redistributable Packages for Visual Studio 2015
如使用的是CPU加速版,需额外确保Openvino安装正确,版本为2020.3.1LTS版 如使用Windows Server,需确保开启桌面体验
2. 服务调用时返回为空,怎么处理?
调用输入的图片必须是RGB格式,请确认是否有alpha通道。
3. 多个模型怎么同时使用?
SDK设置运行不同的端口,点击运行即可。
4. JAVA、C#等其他语言怎么调用SDK?
参考 https://ai.baidu.com/forum/topic/show/943765
5. 启动失败,缺失DLL?
打开EasyEdge.log,查看日志错误,根据提示处理 缺失DLL,请使用 https://www.dependencywalker.com/ 查看相应模块依赖DLL缺失哪些,请自行下载安装
6. 启动失败,报错NotDecrypted?
Windows下使用,当前用户名不能为中文,否则无法正确加载模型。
7. 启动失败,报错 SerialNum无效
日志显示failed to get/check device id(xxx)
或者Device fingerprint mismatch(xxx)
此类情况一般是设备指纹发生了变更,包括(但不局限于)以下可能的情况:
- mac 地址变化
- 磁盘变更
- bios重刷
以及系统相关信息。
遇到这类情况,请确保硬件无变更,如果想更换序列号,请先删除 C:\Users\${用户名}\.baidu\easyedge 目录
,再重新激活。
8. 勾选“开机自动启动”后,程序闪退
一般是写注册表失败。
可以确认下HKEY_CURRENT_USER下Software\Microsoft\Windows\CurrentVersion\Run能否写入(如果不能写入,可能被杀毒软件等工具管制)。也可以尝试基于bin目录下的easyedge_serving.exe命令行形式的二进制,自行配置开机自启动。
其他问题
如果无法解决,可到论坛发帖: https://ai.baidu.com/forum/topic/list/199 描述使用遇到的问题,我们将及时回复您的问题。