Deploy General CPU Model
This tutorial describes how to use EasyEdge to generate the end model and how to use BIE to distribute the model to the edge device.
I. Prerequisite
The prerequisite in this case is that the [Getting Started](BIE/Getting Started/Getting Started Guide.md) operation has been complete and the edge node has been connected to the cloud and is online.
## II. Generate End Model on EasyEdge Console
1. Get original model of mobilnetv1-ssd-voc-fluid
The original model may be the customer's training model or the existing model. We will use the Paddle framework-based Object Detection model mobilnetv1-ssd-voc-fluid in this tutorial.
### 2. Upload Original Model on EasyEdge
Open the EasyEdge Official Website and click Use Now to log in to the EasyEdge console. The login account used here is the Baidu AI Cloud account which is consistent with the BIE account.
Enter EasyEdge, and click Upload Model.
Enter the original model information on the Upload Original Model interface:
- Model name: Custom, enter mobilnetv1-ssd-voc-fluid-paddle here.
- Model type: Object detection
- Model framework: PaddlePaddle
- Model network: MobileNetV1-SSD
- Network structure: Select the Model file in the model directory.
- Network Parameters: Select the params file in the model directory.
- Model tag: Select the label_list.txt file in the model directory.
- Other configuration: Select the preprocess_args.json file in the model directory.
- Custom group: Custom, enter <19>PaddlePaddle here.
- Function description: Custom, enter MobileNet SSD Demo here.
### 3. Generate end model
Click Verify and Submit Model. After successful verification, enter the Generate End Model menu and set the end environment that adapts to this model, as shown in the figure below:
Click Generate Model to enter the model generation phase. This process will take about a few minutes, depending on the size of the model.
Here, we generate the end models of general ARM chip version and general x86 chip version based on the Linux operating system, which corresponds to the Linux-arm64 and Linux-amd64 architectures respectively.
4. Download end model in SDK list
After generating the model, enter the SDK List. Then, you can see the generated end model.
Click <29>Download to get the end model of V1 (amd64) and V2 (arm64) chip architecture versions, and calculate the MD5 Value of two zip files, which is used to verify the integrity of files in the model.
version | Model SDK file name | Model file MD5 value | Chip architecture |
---|---|---|---|
V1 | mobilnetv1-ssd-voc-fluid-amd64.zip | d2664dfd726e9bbcf1b42b81b357dc26 | amd64 |
V2 | mobilnetv1-ssd-voc-fluid-arm64.zip | 64c2fad351a5bf455d382cbf864316b0 | arm64 |
## III. Create and Distribute Model Service on BIE Console
1. Upload AI model
After you obtain the AI model, you need to upload the AI model to the object storage. BIE supports the acquisition of the model file from the following object storage:
- Baidu BOS
- AWS S3-compliant object storage, such as AWS S3, CEPH, and Minio.
Upload model to Baidu BOS
If you use Baidu BOS, the operation steps are as follows:
- Create the bucket: bucket-demo-01.
- Create the directory: easyedge in the bucket.
- Upload the model file to the EasyEdge directory as shown in the figure below:
Upload model to Minio
If you use your Minio, the operation steps are as follows:
- Log in to Minio.
-
Enter the user name and password. In general, the default user name and password are as follows:
- ak:AKIAIOSFODNN7EXAMPLE
- sk:wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
- Create the bucket: model-upload.
- Upload the model file to the bucket as shown in the figure below:
2. Create AI model configuration item
Enter the Configuration Management interface, click Create Configuration Item, and fill in the configuration item name: mobilnetv1-ssd-voc-fluid-arm64. Then, click Import File, and enter the download information on the AI model file in the object storage.
Scheme 1: Import file from Baidu BOS
BIE integrates with the BOS account in the public cloud environment. If you import a file from the BOS, you do not need to enter the user name and password. You can directly select the location of the model file through the drop-down menu. If you import a model file that is not under the current BIE account, you need to enter the AK/SK to access BOS.
Scheme 2: Import file from AWS S3
If you need to download the model file from AWS S3 or the AWS S3-compliant object storage (CEPH and Minio), enter the download information of the model file according to the following case. We use our own Minio service.
3.Create and deploy AI application to edge node
Enter the Application Deployment interface, click Create Application, and fill in>①Basic Information->②Service Configuration->③Target Node in turn by following the prompt.
① Basic information
Fill in the basic information of applications on the Basic Information interface as shown in the figure below:
- Application name: edge-ai-demo-app
- Application type: Container application
- Application description: Optional, it can be empty.
② Service configuration
Fill in the service information on the Service Configuration interface, click Add Service, and fill in the following information in the pop-up box:
-
Basic information
- Service name: ai-infer-service
- Service image address:
hub.baidubce.com/baetyl/easyedge-inference:0.5.1
, which is a multi-platform image and supports thearm64
andamd64
chip architectures.
-
Volume configuration
- Volume name: ai-model
- Type: Configuration item
- Parameter: Select the AI model configuration item easyedge-model-mobilnet created previously from the drop-down box.
- Container directory: /var/db/baetyl
- Read/write permission: Read/write
-
Port Mapping
- Host port: 8088
- Container port: 8088
- Protocol: TCP
-
Startup parameter (there is a strong correlation between startup parameter and model/inference image, and the startup parameter is not standard for all models)
- bash
- run.sh
- /var/db/baetyl/RES
- 0.0.0.0
- 8088
-
Other
- Use the default configuration.
③ Target node
You can select which edge nodes to deploy the application in the application deployment and match the deployment logic by the tag of the edge node. For example, there is a KV tag for the baetyl-node-name: edge-node
as shown in the figure below:
Click Match Tag on the Target Node interface, and add baetyl-node-name: edge-node
as the target node tag as shown in the figure below:
After adding, the system automatically matches the target node as edge-node based on the tag as shown in the figure below:
4. Verify edge AI service
Open the label_list.txt file of the original model, and we can see that this model can identify the following types of objects: Background, aeroplane, bicycle, bird, boat, bottle, bus, car, cat, chair, cow, diningtable, dog, horse, motorbike, person, pottedplant, sheep, sofa, train, tvmonitor.
We can see that this model can identify the objects Person and Dog, we can find a Test Photo of walking the dog.
Browser verification
The AI inference service in this case provides the web operation interface, so we can upload the above test photos through the web interface. Open the browser, and access to: http://[Edge node IP address]:8088/
. If you can open the interface, it indicates that the edge inference service is started normally. At this time, upload the test photo, and the inference service will automatically provide the inference result as shown in the figure below. When the confidence level is 80%, it identifies that there are three persons and one dog in the photo, and the confidence level can be customized by users.
API verification
ai-infer-service runs as a container service on the edge node. Furthermore, it provides the API access interface, supports to be called by other applications, and returns the object detection results. For the specific usage of API, refer to the EasyEdge SDK Documentation.
The following will take an example for illustration through the Python code call interface:
- Copy the following Python code and save it locally, and name it as test_ai_model_api.py.
import requests
with open('./1.jpg', 'rb') as f:
img = f.read()
# params is GET params, data is POST Body
result = requests.post('http://[Edge Node ip]:8088/', params={'threshold': 0.8},data=img).json()
print (result)
- Download the photo 1.jpg, and save it to the same directory of test_ai_model_api.py.
- Execute test_ai_model_api.py.
python test_ai_model_api.py
- View that the interface returns a result is the following JSON, which also identifies one person and three dogs.
{
'cost_ms': 179,
'error_code': 0,
'results': [{
'confidence': 0.9943918585777283,
'index': 12,
'label': 'dog',
'location': {
'height': 397,
'left': 100,
'top': 691,
'width': 383
},
'name': 'dog',
'score': 0.9943918585777283,
'x1': 0.14523082971572876,
'x2': 0.6987910866737366,
'y1': 0.6263848543167114,
'y2': 0.9866765737533569
}, {
'confidence': 0.9922541379928589,
'index': 15,
'label': 'person',
'location': {
'height': 304,
'left': 547,
'top': 332,
'width': 92
},
'name': 'person',
'score': 0.9922541379928589,
'x1': 0.7918291687965393,
'x2': 0.9249030947685242,
'y1': 0.30082497000694275,
'y2': 0.5762962102890015
}, {
'confidence': 0.9846013784408569,
'index': 15,
'label': 'person',
'location': {
'height': 1020,
'left': 311,
'top': 63,
'width': 308
},
'name': 'person',
'score': 0.9846013784408569,
'x1': 0.4507014751434326,
'x2': 0.8969031572341919,
'y1': 0.05781838297843933,
'y2': 0.9817966222763062
}, {
'confidence': 0.9536634683609009,
'index': 15,
'label': 'person',
'location': {
'height': 357,
'left': 35,
'top': 327,
'width': 149
},
'name': 'person',
'score': 0.9536634683609009,
'x1': 0.05083557963371277,
'x2': 0.2662031948566437,
'y1': 0.2963605523109436,
'y2': 0.6200013160705566
}]
}