README.md 9.8 KB
Newer Older
J
Jinliang Li 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
@page ai_agent ai_agent

# 概述
AI Agent作为AI的代理引擎框架,支持不同推理引擎的注册,对用户提供统一的接口,简化用户操作,目前注册的AI引擎为ucloud_ai云端推理引擎,用户可以根据需要注册其他推理引擎。

## 版权信息
> Apache license v2.0

## 目录结构
```sh
├── include
│   ├── aiagent_common.h         # aiagent模型定义头文件
│   ├── aiagent_engine.h         # aiagent引擎注册结构体定义头文件
│   ├── aiagent_service.h        # aiagent对外服务接口定义头文件
│   ├── engine
│   │   └── ucloud_ai_engine.h   # ucloud ai引擎头文件
│   └── aiconfig.h               # AI引擎配置文件
├── package.yaml                 # 编译配置文件
└── src
    ├── aiagent_engine.c         # aiagent引擎管理代码
    ├── aiagent_service.c        # aiagent服务接口实现
    └── engine
    │   └── ucloud_ai_engine.c   # ucloud ai引擎注册实例
    └── example
        └── aiagent_example.c
```

## 依赖组件
* ai_agent

# 常用配置
```sh
def_config:                      # 组件的可配置项
  CONFIG_UCLOUD_AI_ENGINE_ENABLE: 1
```
> 配置AI引擎为ucloud ai推理引擎

# API说明
@ref aiagent_aos_api

# 使用示例
示例代码参考example/aiagent_example.c,以运行ucloud_ai_demo为例,具体步骤如下:

## 添加示例代码
> ai_agent组件的package.yaml中添加example
```sh
source_file:
  - "example/aiagent_example.c" # add aiagent_example.c
```

> helloworld_demo组件的application_start中添加代码
```sh
    /*init network service*/
C
caiyan.cai 已提交
54
    event_service_init(NULL);
J
Jinliang Li 已提交
55 56 57 58
    netmgr_service_init(NULL);
```

## 云端功能开通
C
caiyan.cai 已提交
59
> 登陆https://vision.aliyun.com免费开通如下功能:
J
Jinliang Li 已提交
60 61 62 63 64 65 66 67 68 69 70 71 72 73
```sh
人脸人体: https://vision.aliyun.com/facebody
文字识别: https://vision.aliyun.com/ocr
分割抠图: https://vision.aliyun.com/imageseg
目标检测: https://vision.aliyun.com/objectdet

如没有阿里云账号,请登陆http://www.aliyun.com开通
```

> 登陆oss.console.aliyun.com创建bucket
```sh
1. 创建Bucket时地域选择“上海”
2. 读写权限选择“公共读”
```
C
caiyan.cai 已提交
74
## ucloud_ai/package.yaml中配置OSS信息
J
Jinliang Li 已提交
75
```sh
C
caiyan.cai 已提交
76 77 78 79
OSS_ACCESS_KEY: "Your-Access-Key"
OSS_ACCESS_SECRET: "Your-Access-Secret"
OSS_ENDPOINT: "Your-OSS-Endpoint"
OSS_BUCKET: "Your-OSS-Bucket"
J
Jinliang Li 已提交
80 81 82 83 84 85 86 87 88

KEY以及SECRET获取链接: https://usercenter.console.aliyun.com/#/accesskey
ENDPOINT使用默认即可,BUCKET请使用你创建好的Bucket名称
```

## 添加ai_agent组件
> helloworld_demo组件的package.yaml中添加
```sh
depends:
C
caiyan.cai 已提交
89 90 91
  - ai_agent: dev_aos   # helloworld_demo中引入ai_agent组件
  - netmgr: dev_aos     # helloworld_demo中引入netmgr组件
  - littlefs: dev_aos   # helloworld_demo中引入littlefs组件
J
Jinliang Li 已提交
92 93 94 95 96 97 98 99
```

## 编译
```sh
cd solutions/ucloud_ai_demo && aos make
```

## 烧录固件
C
caiyan.cai 已提交
100 101 102 103
> helloworld_demo bin烧录:
```sh
aos burn
```
J
Jinliang Li 已提交
104

C
caiyan.cai 已提交
105
> littlefs文件系统烧录:
J
Jinliang Li 已提交
106 107 108
```sh
aos burn -f hardware/chip/haas1000/release/write_flash_tool/ota_bin/littlefs.bin#0xB32000
```
C
caiyan.cai 已提交
109
本组件例子中使用到到图片存放在代码中hardware/chip/haas1000/prebuild/data目录,除烧录helloworld demo image外,需烧录littlefs文件系统。
J
Jinliang Li 已提交
110 111 112 113 114

## ucloud_ai示例测试

### CLI命令行输入:
```sh
C
caiyan.cai 已提交
115
aiagent -e ucloud-ai -m 0  # 人脸比对
J
Jinliang Li 已提交
116 117 118 119
```

> CLI关键日志:
```sh
C
caiyan.cai 已提交
120 121 122 123
Facebody comparing result:
confidence: 84.6
location at x: 159, y: 76, w: 143, h: 194
aiagent comp test success!
J
Jinliang Li 已提交
124 125 126 127
```

### CLI命令行输入:
```sh
C
caiyan.cai 已提交
128
aiagent -e ucloud-ai -m 1  # 人物动漫化
J
Jinliang Li 已提交
129 130 131 132
```

> CLI关键日志:
```sh
C
caiyan.cai 已提交
133 134 135
Generate human anime style result:
url: http://vibktprfx-prod-prod-aic-gd-cn-shanghai.oss-cn-shanghai.aliyuncs.com/person-image-cartoonizer/4F10FBB8-19DC-476B-A51D-458CD180A24F_07f2_20210331-142711.jpg?Expires=1617202631&OSSAccessKeyId=LTAI4FoLmvQ9urWXgSRpDvh1&Signature=YCLva1stK27Cn657nMeYhgFt7h4%3D
aiagent comp test success!
J
Jinliang Li 已提交
136 137 138 139
```

### CLI命令行输入:
```sh
C
caiyan.cai 已提交
140
aiagent -e ucloud-ai -m 2  # 表情识别
J
Jinliang Li 已提交
141 142 143 144
```

> CLI关键日志:
```sh
C
caiyan.cai 已提交
145 146 147
Recognize expression result:
type: anger, probability: 1.0
aiagent comp test success!
J
Jinliang Li 已提交
148 149 150 151
```

### CLI命令行输入:
```sh
C
caiyan.cai 已提交
152
aiagent -e ucloud-ai -m 3  # 目标检测
J
Jinliang Li 已提交
153 154 155 156
```

> CLI关键日志:
```sh
C
caiyan.cai 已提交
157 158 159 160 161 162 163 164 165 166 167 168 169
Detect object result:
type: potted plant, Score: 0.4, x: 35, y: 274, w: 185, h: 443
Detect object result:
type: potted plant, Score: 0.5, x: 663, y: 121, w: 847, h: 457
Detect object result:
type: monitor, Score: 0.6, x: 250, y: 43, w: 670, h: 439
Detect object result:
type: keyboard, Score: 0.5, x: 239, y: 435, w: 489, h: 485
Detect object result:
type: keyboard, Score: 0.3, x: 241, y: 428, w: 639, h: 506
Detect object result:
type: mouse, Score: 0.2, x: 660, y: 479, w: 750, h: 528
aiagent comp test success!
J
Jinliang Li 已提交
170 171 172 173
```

### CLI命令行输入:
```sh
C
caiyan.cai 已提交
174
aiagent -e ucloud-ai -m 4  # 主体检测
J
Jinliang Li 已提交
175 176 177 178
```

> CLI关键日志:
```sh
C
caiyan.cai 已提交
179 180 181
Detect main body result:
main body location x: 1, y: 31, w: 461, h: 528
aiagent comp test success!
J
Jinliang Li 已提交
182 183 184 185
```

### CLI命令行输入:
```sh
C
caiyan.cai 已提交
186
aiagent -e ucloud-ai -m 5  # 通用分割
J
Jinliang Li 已提交
187 188 189 190
```

> CLI关键日志:
```sh
C
caiyan.cai 已提交
191 192 193
Segment common image result:
url: http://viapi-cn-shanghai-dha-segmenter.oss-cn-shanghai.aliyuncs.com/upload/result_humansegmenter/2021-3-31/invi_humansegmenter_016172056326493133388_avpTpm.jpg?Expires=1617207432&OSSAccessKeyId=LTAI4FoLmvQ9urWXgSRpDvh1&Signature=WREOAoBUIvpLSyygGxKPfi82HfI%3D
aiagent comp test success!
J
Jinliang Li 已提交
194 195 196 197
```

### CLI命令行输入:
```sh
C
caiyan.cai 已提交
198
aiagent -e ucloud-ai -m 6  # 面部分割
J
Jinliang Li 已提交
199 200 201 202
```

> CLI关键日志:
```sh
C
caiyan.cai 已提交
203 204 205 206
Segment face result:
image url: http://viapi-cn-shanghai-dha-segmenter.oss-cn-shanghai.aliyuncs.com/upload/result_HeadSegmenter/2021-3-31/invi_HeadSegmenter_016172056422754285967296_yRhj6C.png?Expires=1617207442&OSSAccessKeyId=LTAI4FoLmvQ9urWXgSRpDvh1&Signature=wR7GUxqrrwRF9u3mCJ%2BNDhAPCzk%3D
location at x: 153, y: 66, w: 160, h: 209
aiagent comp test success!
J
Jinliang Li 已提交
207 208 209 210
```

### CLI命令行输入:
```sh
C
caiyan.cai 已提交
211
aiagent -e ucloud-ai -m 7  # 身份证证明识别
J
Jinliang Li 已提交
212 213 214 215
```

> CLI关键日志:
```sh
C
caiyan.cai 已提交
216 217 218 219 220 221 222 223 224 225 226 227
Recognize identity card face side result:
address: 江苏省南京市浦口区天天小区1栋11号
nationality: 汉
card location: x0: 1126563840, y0: 1126563840
card location: x1: 0, y1: 0
card location: x2: 0, y2: 0
card location: x3: 0, y3: 0
face location: x0: 1126563840, y0: 1126563840
face location: x1: 0, y1: 0
face location: x2: 0, y2: 0
face location: x3: 0, y3: 0
aiagent comp test success!
J
Jinliang Li 已提交
228 229 230 231
```

### CLI命令行输入:
```sh
C
caiyan.cai 已提交
232
aiagent -e ucloud-ai -m 8  # 身份证反面识别
J
Jinliang Li 已提交
233 234 235 236
```

> CLI关键日志:
```sh
C
caiyan.cai 已提交
237 238 239 240 241
Recognize identity card back side result:
start date: 20131010
issue: 杭州市公安局余杭分局
end date: 20231010
aiagent comp test success!
J
Jinliang Li 已提交
242 243 244 245
```

### CLI命令行输入:
```sh
C
caiyan.cai 已提交
246
aiagent -e ucloud-ai -m 9  # 银行卡识别
J
Jinliang Li 已提交
247 248 249 250
```

> CLI关键日志:
```sh
C
caiyan.cai 已提交
251 252 253 254 255 256 257 258
bankName: 中国工商银行
cardNumber: 6212262315007683105
validDate: 07/26
Recognize bank card result:
bank name: 中国工商银行
card number: 6212262315007683105
valid date: 07/26
aiagent comp test success!
J
Jinliang Li 已提交
259 260 261 262
```

### CLI命令行输入:
```sh
C
caiyan.cai 已提交
263
aiagent -e ucloud-ai -m 10  # 文本识别
J
Jinliang Li 已提交
264 265 266 267
```

> CLI关键日志:
```sh
C
caiyan.cai 已提交
268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296
Recognize character result:
text: 《爆炸新闻》
probability: 1.0
text area: left: 141, top: 442, weight: 89, height: 20
Recognize character result:
text: 19
probability: 1.0
text area: left: 115, top: 173, weight: 100, height: 109
Recognize character result:
text: 豆瓣评分7.1
probability: 0.9
text area: left: 168, top: 447, weight: 98, height: 18
Recognize character result:
text: 2019||美国|加拿大|剧情|传记
probability: 0.5
text area: left: 181, top: 450, weight: 241, height: 17
Recognize character result:
text: 杰伊·罗奇 导演
probability: 0.9
text area: left: 216, top: 454, weight: 112, height: 18
Recognize character result:
text: 2021年2月星期五
probability: 1.0
text area: left: 231, top: 187, weight: 150, height: 18
Recognize character result:
text: 农历正月初八
probability: 1.0
text area: left: 261, top: 193, weight: 104, height: 18
aiagent comp test success!
J
Jinliang Li 已提交
297 298 299 300
```

### CLI命令行输入:
```sh
C
caiyan.cai 已提交
301
aiagent -e ucloud-ai -m 11  # 垃圾分类
J
Jinliang Li 已提交
302 303 304 305
```

> CLI关键日志:
```sh
C
caiyan.cai 已提交
306 307 308 309 310 311
Recognize rubbish result:
rubbish: 塑料饮料瓶
rubbish score: 1.0
category: 可回收垃圾
category score: 1.0
aiagent comp test success!
J
Jinliang Li 已提交
312 313 314 315
```

### CLI命令行输入:
```sh
C
caiyan.cai 已提交
316
aiagent -e ucloud-ai -m 12  # 水果检测
J
Jinliang Li 已提交
317 318 319 320
```

> CLI关键日志:
```sh
C
caiyan.cai 已提交
321 322 323 324 325
Recognize fruits result:
fruit name: 橙子
fruit score: 0.8
fruit location: x: 214, y: 44, w: 509, h: 438
aiagent comp test success!
J
Jinliang Li 已提交
326 327 328 329
```

### CLI命令行输入:
```sh
C
caiyan.cai 已提交
330
aiagent -e ucloud-ai -m 13  # 图像人体擦除
J
Jinliang Li 已提交
331 332 333 334
```

> CLI关键日志:
```sh
C
caiyan.cai 已提交
335 336 337
Erase person result:
url: http://algo-app-isr-lab-cn-shanghai-prod.oss-cn-shanghai.aliyuncs.com/remove-person/2021-03-31_15%3A34%3A17.959810_person_org.jpg?Expires=1617206658&OSSAccessKeyId=LTAI4FoLmvQ9urWXgSRpDvh1&Signature=jFwwnSYOw2fXev1%2Fm5az4JBa%2B5Q%3D
aiagent comp test success!
J
Jinliang Li 已提交
338 339 340 341
```

### CLI命令行输入:
```sh
C
caiyan.cai 已提交
342
aiagent -e ucloud-ai -m 14  # 风格迁移
J
Jinliang Li 已提交
343 344 345 346
```

> CLI关键日志:
```sh
C
caiyan.cai 已提交
347 348 349
Extend image style result:
out image url: http://viapi-cn-shanghai-dha-filter.oss-cn-shanghai.aliyuncs.com/upload/result_/2021-3-31/invi__016172056608421021961_1mdK2W.jpg?Expires=1617207460&OSSAccessKeyId=LTAI4FoLmvQ9urWXgSRpDvh1&Signature=3t8Q%2BwTAo6Lib9utaoMrWUJX6Iw%3D
aiagent comp test success!
J
Jinliang Li 已提交
350 351 352 353 354 355 356 357
```

# 注意事项
NA

# FAQ
NA

C
caiyan.cai 已提交
358 359 360 361 362 363 364 365 366 367 368 369 370 371 372
如果遇到:
> error code: InvalidAction.NotFound
请确认Endpoint是否设置正确

> error code: InvalidApi.NotPurchase

请确认是否在vision.aliyun.com开通相应功能

> tlefs_vfs.c:677:error: lfs_vfs_open /data/ucloud_ai_image/object.jpg failed, ret - -2

请确认是否有拷贝图片到hardware/chip/haas1000/prebuild/data/ucloud_ai_image目录。
如果有,可能是文件系统存储空间不够,此时请执行:
1. 在ucloud_ai/package.yaml中屏蔽prebuild_script: cp_resources.py;
2. 删除ucloud_ai_image中其他文件,仅保留测试case使用的图片文件;
3. 再重新编译烧录。