1. 环境搭建
1.1. 安装环境依赖¶
📝SigmaStar DLA SDK基于AVX2指令集编写,请使用支援AVX2的Intel®处理器运行。
推荐配置
🖥️💻 | ⚙️ |
---|---|
CPU | Intel® CoreTM i7 or Higher |
RAM | 8G or Higher |
最低配置
🖥️💻 | ⚙️ |
---|---|
CPU | Intel® CoreTM i5 |
RAM | 6G |
系统依赖¶
Package | Installation command |
---|---|
i386 | dpkg --add-architecture i386 |
build-essential | sudo apt install build-essential |
cmake | sudo apt install cmake |
libc6-dev | sudo apt install libc6-dev libc6-dev:i386 libc6-dev-i386 |
libbz2-dev | sudo apt install libbz2-dev libbz2-dev:i386 |
libncurses5-dev | sudo apt install libncurses5-dev libncurses5-dev:i386 |
libglib2.0-dev | sudo apt install libglib2.0-dev libglib2.0-dev:i386 |
libsm6 | sudo apt install libsm6 libsm6:i386 |
libxrender1 | sudo apt install libxrender1 libxrender1:i386 |
libxext6 | sudo apt install libxext6 libxext6:i386 |
libgdbm-dev | sudo apt install libgdbm-dev libgdbm-dev:i386 |
liblzma-dev | sudo apt install liblzma-dev liblzma-dev:i386 |
libsqlite3-dev | sudo apt install libsqlite3-dev libsqlite3-dev:i386 |
libssl-dev | sudo apt install libssl-dev libssl-dev:i386 |
libreadline6-dev | sudo apt install libreadline6-dev libreadline6-dev:i386 |
libffi-dev | sudo apt install libffi-dev libffi-dev:i386 |
zlib1g-dev | sudo apt install zlib1g-dev zlib1g-dev:i386 |
libncursesw5-dev | sudo apt install libncursesw5-dev libncursesw5-dev:i386 |
libsqlite3-dev | sudo apt install libsqlite3-dev libsqlite3-dev:i386 |
libgdbm-dev | sudo apt install libgdbm-dev libgdbm-dev:i386 |
libbz2-dev | sudo apt install libbz2-dev libbz2-dev:i386 |
checkinstall | sudo apt install checkinstall |
openssl | sudo apt install openssl |
Python 依赖¶
使用SigmaStar DLA SDK需要安装以下依赖库:
Software | Installation Command | Tested Version |
---|---|---|
Python | 3.7 | |
enum34 | pip install enum34==1.1.10 | ==1.1.10 |
numpy | pip install numpy==1.16.6 | ==1.16.6 |
protobuf | pip install protobuf | >=3.8.0 |
six | pip install six | >=1.12.0 |
OpenCV-python | pip install opencv-python | ==4.2.0.34 |
TensorFlow | pip install tensorflow | ==1.14.0 |
Cython | pip install cython | >=0.29.13 |
pycocotools | pip install pycocotools | >=2.0.0 |
matplotlib | pip install matplotlib | >=3.0.3 |
SciPy | pip install scipy | >=1.3.1 |
Pillow | pip install pillow | ==6.1.0 |
joblib | pip install joblib | ==0.13.2 |
onnx-simplifier | pip install onnx-simplifier | ==0.2.10 |
sympy | pip install sympy | ==1.6.1 |
packaging | pip install packaging | ==20.4 |
onnx | pip install onnx | ==1.8.1 |
onnxruntime | pip install onnxruntime | ==1.7.0 |
onnxoptimizer | pip install onnxoptimizer==0.2.4 | ==0.2.4 |
python3-tk | sudo apt install python3-tk | |
libc6 | sudo apt install libc6-dev-i386 | |
libstdc++6 | sudo apt install libstdc++6 | |
python-qt4 | sudo apt install python-qt4 | |
torch | sudo install torch==1.8.0+cpu | ==1.8.0 |
torchvision | sudo install torchvision==0.9.0+cpu | ==0.9.0 |
wheel | sudo install wheel | |
scikit-image | sudo install scikit-image | |
scikit-learn | sudo install scikit-learn | |
pulp | sudo install pulp |
1.2. 快速上手¶
默认设置
请将SGS_Models和SGS_IPU_SDK放到主目录 ~/ 下,以下命令均基于该目录结构进行。请使用Linux环境运行本工具。
1.2.1 安装环境依赖¶
SigmaStar DLA SDK基于AVX2指令集编写,请使用支援AVX2的Intel®处理器运行。如果使用docker等虚拟机环境,请保证虚拟机内最低分配6G内存。
1.2.2 快速安装环境依赖¶
命令如下:
sudo apt update
sudo apt install python3-tk python-qt4 libc6-dev-i386 libstdc++6
cd ~/SGS_IPU_SDK
pip3 install -r Scripts/calibrator/setup/requirements.txt \
–i https://pypi.tuna.tsinghua.edu.cn/simple
1.2.3 环境设置¶
命令如下:
cd ~/SGS_IPU_SDK
source cfg_env.sh
1.2.4 快速上手说明¶
本手册使用caffe训练的mobilenet_v2作为参考例子。
在SGS_IPU_SDK ⽬录下运⾏以下脚本,输出Library的路径:
cd ~/
mkdir caffe_mobilenet_v2
cd caffe_mobilenet_v2
1.2.4.1 原始模型转化为SigmaStar浮点网络模型¶
python3 ~/SGS_IPU_SDK/Scripts/ConvertTool/ConvertTool.py caffe \
--model_file ~/SGS_Models/caffe/caffe_mobilenet_v2/caffe_mobilenet_v2.prototxt \
--weight_file ~/SGS_Models/caffe/caffe_mobilenet_v2/caffe_mobilenet_v2.caffemodel \
--input_arrays data \
--output_arrays prob \
--output_file ./caffe_mobilenet_v2_float.sim \
--input_config ~/SGS_Models/caffe/caffe_mobilenet_v2/input_config.ini
1.2.4.2 SigmaStar浮点网络模型转化为SigmaStar定点网络模型¶
进入caffe_mobilenet_v2文件夹,运行:
python3 ~/SGS_IPU_SDK/Scripts/calibrator/calibrator.py \
-i ~/SGS_Models/resource/classify/ilsvrc2012_calibration_set32/ \
-m ./caffe_mobilenet_v2_float.sim \
-c Classification \
--input_config ~/SGS_Models/caffe/caffe_mobilenet_v2/input_config.ini \
-n caffe_mobilenet_v2
1.2.4.3 SigmaStar定点网络模型转化为SigmaStar离线网络模型¶
进入caffe_mobilenet_v2 文件夹,运行:
python3 ~/SGS_IPU_SDK/Scripts/calibrator/compiler.py \
-m ./caffe_mobilenet_v2_fixed.sim
1.2.5 模型仿真¶
1.2.5.1 使用simulator对SigmaStar浮点网络模型验证¶
python3 ~/SGS_IPU_SDK/Scripts/calibrator/simulator.py \
-i ~/SGS_Models/resource/classify/ilsvrc2012_val_set100 \
-l ~/SGS_Models/resource/classify/caffe_labels.txt \
-m ./caffe_mobilenet_v2_float.sim \
-c Classification \
-t Float \
-n ~/SGS_Models/caffe/caffe_mobilenet_v2/caffe_mobilenet_v2.py \
--num_process 20
1.2.5.2 使用simulator对SigmaStar定点网络模型验证¶
python3 ~/SGS_IPU_SDK/Scripts/calibrator/simulator.py \
-i ~/SGS_Models/resource/classify/ilsvrc2012_val_set100 \
-l ~/SGS_Models/resource/classify/caffe_labels.txt \
-m ./caffe_mobilenet_v2_fixed.sim \
-c Classification \
-t Fixed \
-n ~/SGS_Models/caffe/caffe_mobilenet_v2/caffe_mobilenet_v2.py \
--num_process 20
1.2.5.3 使用simulator对SigmaStar离线网络模型验证¶
python3 ~/SGS_IPU_SDK/Scripts/calibrator/simulator.py \
-i ~/SGS_Models/resource/classify/ILSVRC2012_test_00000002.bmp \
-m caffe_mobilenet_v2_fixed.sim_sgsimg.img \
-l ~/SGS_Models/resource/classify/labels.txt \
-c Classification \
-t Offline \
-n ~/SGS_Models/caffe/caffe_mobilenet_v2/caffe_mobilenet_v2.py