简介
推荐 GitHub 上一款开箱即用的 C++ AI 模型工具箱:Lite.AI.ToolKit,涵盖目标检测、人脸检测、人脸识别、语义分割、抠图等领域。
里面包括了 70+ 流行开源模型,如最新的 RVM、YOLOX、YoloV5、DeepLabV3、ArcFace 等模型,对用户友好,简单易用。
GitHub:github.com/DefTruth/lite.ai.toolkit
环境
WSL2 Ubuntu18.04
配置
配置预编译库:
- 下载预编译好的库
2 . 配置
通过命令 vim ~/.bashrc 打开.bashrc,然后添加
export LD_LIBRARY_PATH=YOUR-PATH-TO/lite.ai.toolkit/lib:$LD_LIBRARY_PATH
export LIBRARY_PATH=YOUR-PATH-TO/lite.ai.toolkit/lib:$LIBRARY_PATH
执行 source ~/.bashrc
注意事项:
lite.ai.toolkit/lib 里面库之间的软连接失效,需要重新创建软连接,否则编译时会报错;
主要修改一下浅蓝色的库:
编译
查看build.sh
#!/bin/bash
BUILD_DIR=build
if [ ! -d "${BUILD_DIR}" ]; then
mkdir "${BUILD_DIR}"
echo "creating build dir: ${BUILD_DIR} ..."
else
echo "build dir: ${BUILD_DIR} directory exist! ..."
fi
cd "${BUILD_DIR}" && pwd && cmake .. \
-DCMAKE_BUILD_TYPE=MinSizeRel \
-DINCLUDE_OPENCV=ON \
-DENABLE_MNN=ON \
-DENABLE_NCNN=OFF \
-DENABLE_TNN=OFF &&
make -j8
设置了-DENABLE_MNN=ON,因为需要配置MNN库和头文件,将MNN-2.0.0/build/install 下面的库和头文件,放置到上面步骤的lite.ai.toolkit文件夹下面的库、头文件目录下即可;
执行编译:
cd lite.ai.toolkit-main
./build.sh
编译完成后,可执行程序在 lite.ai.toolkit-main/build/lite.ai.toolkit/bin;
头文件:lite.ai.toolkit-main/build/lite.ai.toolkit/include
库:lite.ai.toolkit-main/build/lite.ai.toolkit/lib
测试:
root@DL3H:/home/XX/test_net/lite.ai.toolkit-main/build/lite.ai.toolkit/bin# ./lite_yolov5
LITEORT_DEBUG LogId: ../../../hub/onnx/cv/yolov5s.onnx
=============== Input-Dims ==============
input_node_dims: 1
input_node_dims: 3
input_node_dims: 640
input_node_dims: 640
=============== Output-Dims ==============
Output: 0 Name: pred Dim: 0 :1
Output: 0 Name: pred Dim: 1 :25200
Output: 0 Name: pred Dim: 2 :85
Output: 1 Name: output2 Dim: 0 :1
Output: 1 Name: output2 Dim: 1 :3
Output: 1 Name: output2 Dim: 2 :80
Output: 1 Name: output2 Dim: 3 :80
Output: 1 Name: output2 Dim: 4 :85
Output: 2 Name: output3 Dim: 0 :1
Output: 2 Name: output3 Dim: 1 :3
Output: 2 Name: output3 Dim: 2 :40
Output: 2 Name: output3 Dim: 3 :40
Output: 2 Name: output3 Dim: 4 :85
Output: 3 Name: output4 Dim: 0 :1
Output: 3 Name: output4 Dim: 1 :3
Output: 3 Name: output4 Dim: 2 :20
Output: 3 Name: output4 Dim: 3 :20
Output: 3 Name: output4 Dim: 4 :85
========================================
detected num_anchors: 25200
generate_bboxes num: 48
时间消耗: 237ms
Default Version Detected Boxes Num: 5
LITEORT_DEBUG LogId: ../../../hub/onnx/cv/yolov5s.onnx
=============== Input-Dims ==============
input_node_dims: 1
input_node_dims: 3
input_node_dims: 640
input_node_dims: 640
=============== Output-Dims ==============
Output: 0 Name: pred Dim: 0 :1
Output: 0 Name: pred Dim: 1 :25200
Output: 0 Name: pred Dim: 2 :85
Output: 1 Name: output2 Dim: 0 :1
Output: 1 Name: output2 Dim: 1 :3
Output: 1 Name: output2 Dim: 2 :80
Output: 1 Name: output2 Dim: 3 :80
Output: 1 Name: output2 Dim: 4 :85
Output: 2 Name: output3 Dim: 0 :1
Output: 2 Name: output3 Dim: 1 :3
Output: 2 Name: output3 Dim: 2 :40
Output: 2 Name: output3 Dim: 3 :40
Output: 2 Name: output3 Dim: 4 :85
Output: 3 Name: output4 Dim: 0 :1
Output: 3 Name: output4 Dim: 1 :3
Output: 3 Name: output4 Dim: 2 :20
Output: 3 Name: output4 Dim: 3 :20
Output: 3 Name: output4 Dim: 4 :85
========================================
detected num_anchors: 25200
generate_bboxes num: 39
ONNXRuntime Version Detected Boxes Num: 4
LITEMNN_DEBUG LogId: ../../../hub/mnn/cv/yolov5s.mnn
=============== Input-Dims ==============
**Tensor shape**: 1, 3, 640, 640,
Dimension Type: (CAFFE/PyTorch/ONNX)NCHW
=============== Output-Dims ==============
getSessionOutputAll done!
Output: output2: **Tensor shape**: 1, 3, 80, 80, 85,
Output: output3: **Tensor shape**: 1, 3, 40, 40, 85,
Output: output4: **Tensor shape**: 1, 3, 20, 20, 85,
Output: pred: **Tensor shape**: 1, 25200, 85,
========================================
detected num_anchors: 25200
generate_bboxes num: 39
时间消耗: 253ms
MNN Version Detected Boxes Num: 4