Quick Start
This chapter mainly introduces the usage process of the Spacemit AI deployment tool to help you get started quickly.
1. Development Environment
Currently, Spacemit provides you with two options for the PC (x86_64) side: Docker and local manual configuration (choose one of them). Note: We strongly recommend that you choose the Docker method to avoid problems during the local manual installation process.
1.1 Using the Docker Environment
To simplify your deployment process, Spacemit provides a Docker image with a complete development environment. You can perform model conversion, quantization, testing, and other tasks in the relevant Docker environment. Therefore, you only need to correctly install the Docker environment. Docker Environment Installation Guide:
- Install Docker on Mac (Desktop Version)
- Install Docker on Windows (Desktop Version)
- Install Docker on Linux (Desktop Version)
Quick Check of the Docker Environment (Example):
$ sudo docker -v
Docker version 24.0.7, build afdd53b
Note: If you do not have root privileges, please contact the administrator of the PC device you are using to add your username to the docker user group. At that time, you will no longer need sudo to execute docker-related commands.
1.1.1 Obtaining the Docker Image
You can choose to directly pull the spacemit-ai-sdk related image from the spacemit-ai project in harbor.spacemit.com (Note: x86_64 architecture); or you can choose to manually download and import the compressed image file from https://archive.spacemit.com/spacemit-ai/spacemit-ai-sdk/. Note: For bandwidth and other factors, we recommend that you use the method of manually downloading the relevant image. Direct Pulling (Example):
$ sudo docker pull harbor.spacemit.com/spacemit-ai/spacemit-ai-sdk:latest
latest: Pulling from spacemit-ai/spacemit-ai-sdk
...
Note: If you need a specific version of the deployment tool, you can replace latest with the specified version number or other tags (e.g. v1.0.0) during the operation. Manual Downloading and Importing (Example):
$ wget https://archive.spacemit.com/spacemit-ai/spacemit-ai-sdk/spacemit-ai-sdk.v1.1.0.x86_64.img.tar.gz --no-check-certificate
$ sudo docker load -i spacemit-ai-sdk.v1.1.0.x86_64.img.tar.gz
1.1.2 Viewing the Docker Image
Example:
$ sudo docker images | grep spacemit-ai-sdk
REPOSITORY TAG IMAGE ID CREATED SIZE
harbor.spacemit.com/spacemit-ai/spacemit-ai-sdk latest 4d239b86f5ea 3 days ago 3.83GB
1.1.3 Creating a Docker Container
Creating a Container (Example):
$ NAME = ai_test # Give a name to your docker container
$ sudo docker run -itd --name $NAME --net = host harbor.spacemit.com/spacemit-ai/spacemit-ai-sdk:latest /bin/bash
Note: If you plan to mount the host directory to the container (e.g. parameter -v <host directory:container directory>)
, please avoid the /opt directory (the preset folder path of the current Spacemit AI deployment tool).
Viewing the Container (Example):
$ sudo docker ps -a | grep $NAME
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
0a35d7feebd9 harbor.spacemit.com/spacemit-ai/spacemit-ai-sdk:latest "/bin/bash" 2 minutes ago Up 2 minutes ai_test
1.1.4 Entering the Docker Container
Entering the Container (Example):
$ sudo docker exec -it $NAME /bin/bash
Querying the Version (Example):
root@xxx:/home/workspace# spine
...
Spacemit AI Toolkit(Version: 2024/01/15)
...
As you can see, the relevant output is the version information of the Spacemit AI deployment tool in the current docker development environment. Note: When you call the spine related commands (and its subcommands) for the first time, spine will automatically install the necessary dependency packages for you, so network support is required (normally, this process will not take up too much of your time).
1.2 Setting up the Local Environment
1.2.1 Environmental Requirements
Operating System: CentOS8 or Ubuntu18.04 (and above) Note: If you do not need to simulate and test on the PC side, CentOS7 or Ubuntu16.04 can meet the environmental requirements.
1.2.2 Obtaining the Deployment Tool
SDK Package Download Page: https://archive.spacemit.com/spacemit-ai/spacemit-ai-sdk/ Download Example (e.g. v1.1.0):
$ wget https://archive.spacemit.com/spacemit-ai/spacemit-ai-sdk/spacemit-ai-sdk.v1.1.0.x86_64.tar.gz --no-check-certificate
1.2.3 Installing the Deployment Tool
Unzipping the Tool (Example):
$ tar xzf spacemit-ai-sdk.v1.1.0.x86_64.tar.gz
Directory Structure (Example):
$ tree -L 1 spacemit-ai-sdk.v1.1.0
spacemit-ai-sdk.v1.1.0
├──.spine.rc -> spine* // Environment configuration script for the toolkit
├── bianbu-ai-support // Upper-layer application development support library (and examples)
├── quick_start* // Quick start example script
├── install.sh* // Dependency environment installation script
├── spacemit-gcc // x86_64-riscv64 compiler
├── spacemit-ort // Inference engine (including operator library)
├── spacemit-qemu // x86_64-riscv64 simulator
├── spacengine* // Entrance to the toolkit
├── spacengine-toolkit // Python environment for the toolkit (related to paddle/tf2/onnx models, etc.)
├── spacengine-toolkit-caffe // Python environment for the toolkit (related to official caffe models)
├── spacengine-toolkit-tf1 // Python environment for the toolkit (related to tf1 models)
├── spacengine-wheel // Python Wheel package for the toolkit
├── spacengine-xquant // Python environment for the toolkit (quantizer)
└── spine -> spacengine* // Entrance to the toolkit (shortcut)
Installing Dependencies (Example):
$ bash install.sh
Note: You may need root privileges to execute the installation of related dependent software. If you cannot obtain the relevant permissions, you can contact the administrator of the device you are currently using to assist in the installation, or use the AI deployment tool docker image provided by Spacemit (see the content of Section 2.1 Using the Docker Environment). Importing the Tool (Example):
# cd spacemit-ai-sdk.v1.1.0
$ source.spine.rc # Note: Only valid for the current terminal (you can also edit the ~/.bashrc file to make it valid for all terminals)
Querying the Version (Example):
root@xxx:/home/workspace# spine
...
Spacemit AI Toolkit(Version: 2024/01/15)
...
Note: When you call the spine related commands (and its subcommands) for the first time, spine will automatically install the necessary dependency packages for you, so network support is required (normally, this process will not take up too much of your time).
1.3 Quick Verification
To facilitate your quick start with the Spacemit AI deployment tool, we have prepared the quick_start script tool (under the root directory of the SDK) for you. You can quickly verify and familiarize yourself with the entire process of AI model deployment by running this tool. Usage Instructions (Example):
$ quick_start
Usage: /opt/spacemit-ai-sdk.v1.1.0/quick_start [paddle|demo|all]
Among them, the parameter paddle indicates a quick demonstration of the Paddle-related model deployment process (including: resource download, model conversion, model quantization, accuracy verification, simulation running, etc.); the parameter demo indicates a quick demonstration of the compilation and testing processes of the C/C++ application; the parameter all indicates a quick demonstration of all tasks (currently: paddle and demo). Note: When you execute quick_start paddle or quick_start all for the first time, the script tool will automatically download and unzip the quick_start.tar.gz data package (Directory Structure Example):
dataset/
├── data
│ └── Imagenet
│ ├── Calib // Calibration dataset
│ ├── Test // Test dataset
│ ├── calib_list.txt // Calibration data list
│ └── test_label.txt // Test data label
└── paddle
└── classification
├── infer.py // Inference test script
└── resnet50
├── inference.json // Quantization configuration file
├── inference.pdiparams
└── inference.pdmodel
2 Model Preparation
Taking the Paddle model in quick_start as an example (other framework models are similar, please refer to the content of Section 3. Model Conversion for details), you can also download and unzip the example model through the following command:
$ wget https://bj.bcebos.com/paddle2onnx/model_zoo/resnet50.tar.gz && tar xvf resnet50.tar.gz
$ tree resnet50
resnet50