Skip to main content
Version: 最新版本(unreleased)

mnist

0. install sdk

please use python3.9+ (本示例建议用python3.9,如果是最新的python版本,可能没有对应的torch包) or you can choosedocker base image

pip3 install aiges==0.7.2 -i https://pypi.python.org/simple

1. download aiges

  1. wget https://github.com/iflytek/aiges/releases/download/v3.0-alpha4/aiges_3.0-alpha4_linux_amd64.tar.gz

init python wrapper project

init a project called mnist using aiges sdk

python3 -m aiges create -n mnist

2. init project structure

root# tree mnist/
mnist/
├── Dockerfile
├── README.md
├── requirements.txt
└── wrapper
├── test_data
│   └── test.png
└── wrapper.py

3. unzip the tar (in the future , it will be intergrated to the sdk)

tar zxvf aiges_3.0-alpha4_linux_amd64.tar.gz -C mnist

now the structure:

➜  mnist git:(master) ✗ tree -L 3 .
.
├── AIservice
├── Dockerfile
├── include
│   ├── type.h
│   └── wrapper.h
├── library
│   ├── libahsc.so
│   ├── libIce.so.34
│   └── libIceUtil.so.34
├── README.md
├── requirements.txt
└── wrapper
├── test_data
│   └── test.png
└── wrapper.py

4 directories, 11 files

4. config the aiges using grpc mode.

excute by this order:

  • export AIGES_PLUGIN_MODE=python

  • ./AIservice -init 【ingnore the error, it will generate aiges.toml】

  • ./AIservice -m 0 -c aiges.toml -s svcName start the aiservice:【becareful this svcName is the section of the aiges.toml】

root@012d31456c50:/home/aiges/mnist# ./AIservice -m 0 -c aiges.toml  -s svcName
2022/11/15 18:22:01 widgetpy.go:26: Starting Using Python :
config.toml version:
2022/11/15 18:22:01 utils.NewLocalLog success. -> LOGLEVEL:debug, FILENAME:./log/aiges.log, MAXSIZE:3, MAXBACKUPS:3, MAXAGE:3
2022/11/15 18:22:01 host2ip->ip:0.0.0.0,port:5090
2022/11/15 18:22:01 finderSwitch:0,finderSwitchErr:<nil>
2022/11/15 18:22:01 about to deal with hermes.
2022/11/15 18:22:02 NewSessionManager success.
2022/11/15 18:22:02 NewSidGenerator success.
2022/11/15 18:22:02 fn:AbleTrace,able:false
2022/11/15 18:22:02 about to deal finder.
2022/11/15 18:22:02 about to deal metrics.
2022/11/15 18:22:02 metrics is disable
2022/11/15 18:22:02 about to deal rateLimiter.
2022/11/15 18:22:02 about to deal vCpuManager.
2022/11/15 18:22:02 about to deal bvtVerifier.
2022/11/15 18:22:02 namespace not set, use default
2022/11/15 18:22:02 bvt is disable
header pass list: []
2022-11-15T18:22:02.476+0800 [WARN] python-plugin: plugin configured with a nil SecureConfig
2022-11-15T18:22:02.477+0800 [DEBUG] python-plugin: starting plugin: path=/bin/sh args=[sh, -c, "/usr/bin/env python -m aiges.serve"]
2022-11-15T18:22:02.478+0800 [DEBUG] python-plugin: plugin started: path=/bin/sh pid=126
2022-11-15T18:22:02.478+0800 [DEBUG] python-plugin: waiting for RPC address: path=/bin/sh
2022-11-15T18:22:02.653+0800 [DEBUG] python-plugin: using plugin: version=1
2022-11-15T18:22:02.655+0800 [DEBUG] python-plugin.stdio: received EOF, stopping recv loop: err="rpc error: code = Unimplemented desc = Method not found!"
2022-11-15T18:22:02.656+0800 [DEBUG] python-plugin.sh: root:wrapperInit:107 - INFO: Importing module from wrapper.py: wrapper
2022-11-15T18:22:02.657+0800 [DEBUG] python-plugin.sh: root:wrapperInit:119 - ERROR: module 'wrapper' has no attribute 'Wrapper'
2022/11/15 18:22:02 grpc.go:20: Call WrapperInit Failed...ret: 30001

Failed because we haven't start preparing python infer wrapper...

5. prepare the infer wrapper,mnist as the example

down load mnist demo:

  • git clone https://github.com/iflytek/aiges_demo.git
  • rm -r mnist/wrapper
  • cp -ra aiges_demo/mnist/wrapper/ mnist/
  • cp -ra aiges_demo/mnist/requirements.txt mnist/
  • pip install -r requirements.txt
  • export PYTHONPATH=/home/aiges/mnist/wrapper
  • 再次运行引擎 ./AIservice -m 0 -c aiges.toml -s svcName

stdout as below:

2022/11/15 21:26:29 widgetpy.go:26: Starting Using Python :
config.toml version:
2022/11/15 21:26:29 utils.NewLocalLog success. -> LOGLEVEL:debug, FILENAME:./log/aiges.log, MAXSIZE:3, MAXBACKUPS:3, MAXAGE:3
2022/11/15 21:26:29 host2ip->ip:0.0.0.0,port:5090
2022/11/15 21:26:29 finderSwitch:0,finderSwitchErr:<nil>
2022/11/15 21:26:29 about to deal with hermes.
2022/11/15 21:26:30 NewSessionManager success.
2022/11/15 21:26:30 NewSidGenerator success.
2022/11/15 21:26:30 fn:AbleTrace,able:false
2022/11/15 21:26:30 about to deal finder.
2022/11/15 21:26:30 about to deal metrics.
2022/11/15 21:26:30 metrics is disable
2022/11/15 21:26:30 about to deal rateLimiter.
2022/11/15 21:26:30 about to deal vCpuManager.
2022/11/15 21:26:30 about to deal bvtVerifier.
2022/11/15 21:26:30 namespace not set, use default
2022/11/15 21:26:30 bvt is disable
header pass list: []
[GIN-debug] [WARNING] Creating an Engine instance with the Logger and Recovery middleware already attached.

[GIN-debug] [WARNING] Running in "debug" mode. Switch to "release" mode in production.
- using env: export GIN_MODE=release
- using code: gin.SetMode(gin.ReleaseMode)

[GIN-debug] GET /v1/svcName --> github.com/xfyun/aiges/httproto.(*Server).ginHandler.func1 (3 handlers)
[GIN-debug] POST /v1/svcName --> github.com/xfyun/aiges/httproto.(*Server).ginHandler.func1 (3 handlers)
[GIN-debug] PUT /v1/svcName --> github.com/xfyun/aiges/httproto.(*Server).ginHandler.func1 (3 handlers)
[GIN-debug] PATCH /v1/svcName --> github.com/xfyun/aiges/httproto.(*Server).ginHandler.func1 (3 handlers)
[GIN-debug] HEAD /v1/svcName --> github.com/xfyun/aiges/httproto.(*Server).ginHandler.func1 (3 handlers)
2022-11-15T21:26:30.116+0800 [WARN] python-plugin: plugin configured with a nil SecureConfig
2022-11-15T21:26:30.116+0800 [DEBUG] python-plugin: starting plugin: path=/bin/sh args=[sh, -c, "/usr/bin/env python -m aiges.serve"]
[GIN-debug] OPTIONS /v1/svcName --> github.com/xfyun/aiges/httproto.(*Server).ginHandler.func1 (3 handlers)
[GIN-debug] DELETE /v1/svcName --> github.com/xfyun/aiges/httproto.(*Server).ginHandler.func1 (3 handlers)
[GIN-debug] CONNECT /v1/svcName --> github.com/xfyun/aiges/httproto.(*Server).ginHandler.func1 (3 handlers)
[GIN-debug] TRACE /v1/svcName --> github.com/xfyun/aiges/httproto.(*Server).ginHandler.func1 (3 handlers)
[GIN-debug] GET /test.json --> github.com/xfyun/aiges/httproto.getDemo (3 handlers)
2022-11-15T21:26:30.116+0800 [DEBUG] python-plugin: plugin started: path=/bin/sh pid=1081
2022-11-15T21:26:30.116+0800 [DEBUG] python-plugin: waiting for RPC address: path=/bin/sh
[GIN-debug] GET /swagger/*any --> github.com/swaggo/gin-swagger.CustomWrapHandler.func1 (3 handlers)
2022-11-15T21:26:30.242+0800 [DEBUG] python-plugin: using plugin: version=1
2022-11-15T21:26:30.244+0800 [DEBUG] python-plugin.stdio: received EOF, stopping recv loop: err="rpc error: code = Unimplemented desc = Method not found!"
2022-11-15T21:26:30.245+0800 [DEBUG] python-plugin.sh: root:wrapperInit:107 - INFO: Importing module from wrapper.py: wrapper
2022-11-15T21:26:31.642+0800 [DEBUG] python-plugin.sh: root:_check_path:151 - WARNING: <class 'FileNotFoundError'>
2022-11-15T21:26:31.643+0800 [DEBUG] python-plugin.sh: root:wrapperInit:112 - INFO: User Wrapper newed Success.. starting call user init functions...
2022-11-15T21:26:31.643+0800 [DEBUG] python-plugin.sh: root:wrapperInit:85 - INFO: Initializing ...
2022-11-15T21:26:31.666+0800 [DEBUG] python-plugin.sh: root:wrapperSchema:141 - INFO: Entering warpperSchema ...
2022-11-15T21:26:31.672+0800 [DEBUG] python-plugin.sh: root:test_value:233 - WARNING: test_data/0.png not exist.. check
2022-11-15T21:26:31.672+0800 [DEBUG] python-plugin.sh: root:schema:434 - INFO: Genrating Schema...
aiService.Init: init success!
2022/11/15 21:26:31 about to x.run
2022/11/15 21:26:31 about init interceptor
2022/11/15 21:26:31 success init interceptor
2022/11/15 21:26:31 about to call grpc.NewServer(opts...),maxRecv:4194304,maxSend:4194304
2022/11/15 21:26:31 about to call utils.RegisterXsfCallServer(x.grpcserver, srv)
2022/11/15 21:26:31 about to call reflection.Register(x.grpcserver)
2022/11/15 21:26:31 about to exec userCallback
2022/11/15 21:26:31 deal with UserHighPriority
2022/11/15 21:26:31 deal with UserNormalPriority
2022/11/15 21:26:31 deal with UserLowPriority
2022/11/15 21:26:31 about to call x.grpcserver.Serve
2022/11/15 21:26:31 about to check if the grpc service([::]:5090) is started
2022/11/15 21:26:31 grpc server([::]:5090) started successfully
2022/11/15 21:26:31 bvtVerifierInst is disable,ignore...
2022/11/15 21:26:31 about to call finderadapter.Register([::]:5090)
2022/11/15 21:26:31 about to exec fcDelayInst
2022/11/15 21:26:31 about to call fc delay task
2022/11/15 21:26:31 blocking for grpcserver.Serve

默认监听 http端口是: 1888, 可从aiges.toml文件中看到

5. Postman调试

  • api地址: http://youIP:1888/v1/svcName
  • post方式请求: body 部分
 {
"header":{
"appid":"123456",
"uid":"39769795890",
"did":"SR082321940000200",
"imei":"8664020318693660",
"imsi":"4600264952729100",
"mac":"6c:92:bf:65:c6:14",
"net_type":"wifi",
"net_isp":"CMCC",
"status":3,
"res_id":""
},
"parameter":{
"svcName":{
"result":{
"encoding":"utf8",
"compress":"raw",
"format":"plain",
"data_type": "text"
}
}
},
"payload":{
"img":{
"encoding":"jpg",
"status":3,
"image":"iVBORw0KGgoAAAANSUhEUgAAAOEAAADgCAYAAAD17wHfAAANa0lEQVR4Xu3dr29USxyG8VpUExQOhcGRIAkGU1OFh/+gCZI/AEdSWdMEj0A2QW+CQyFRyAYFloS9eTf5hsm7c2a295w9c3484hPgnrvdbbvPzrYzc87J5eXl9uLiYvvmzRsAI3r9+vV2s9lsTxTgyckJgAZubm62JyrSDwAYx+fPn4kQaGkX4ePHj/cOABgHIyHQGBECjREh0BgRAo0RIdAYEQKNESHQGBECjREh0BgRAo0RIdAYEQKNESHQGBECjREh0BgRAo0RIdAYEQKNESHQGBECjREh0BgRAo0RIdAYEQKNESHQGBECjREh0BgRAo0RIdAYEQKNESHQGBECjREh0BgRAo0RIdAYEQKNESHQG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
},
"payload": {
"result": {
"compress": "raw",
"encoding": "utf8",
"format": "plain",
"seq": "0",
"status": "3",
"text":"{\"result\": 7, \"msg\": \"\识\别\结\果\为\数\字: 7\"}"
}
}
}
  • Now we have done demo for the aiges.

bugs:

  • python process exit problem

  • some fatal errors.