一、Lite.Ai.ToolKit软件介绍(文末提供整合包下载)
一个轻量级的 C++ 工具包,包含 100+ 个很棒的 AI 模型,例如对象检测、人脸检测、人脸识别、分割、遮罩等。请参阅 Model Zoo 和 ONNX Hub、MNN Hub、TNN Hub、NCNN Hub。
GitHub地址:https://github.com/DefTruth/lite.ai.toolkit
本文信息图片均来源于github作者地址
二、软件主要特征
1、简单且用户友好。简单一致的语法,如 lite::cv::Type::Class
2、最小依赖项。默认情况下只需要 OpenCV 和 ONNXRuntime
3、支持多种型号。300+ C++ 实现和 500+ 权重
三、使用方法
示例 0:使用 YOLOv5 进行对象检测。从 Model-Zoo 下载模型
#include "lite/lite.h"
int main(int argc, char *argv[]) {
std::string onnx_path = "yolov5s.onnx";
std::string test_img_path = "test_yolov5.jpg";
std::string save_img_path = "test_results.jpg";
auto *yolov5 = new lite::cv::detection::YoloV5(onnx_path);
std::vector<lite::types::Boxf> detected_boxes;
cv::Mat img_bgr = cv::imread(test_img_path);
yolov5->detect(img_bgr, detected_boxes);
lite::utils::draw_boxes_inplace(img_bgr, detected_boxes);
cv::imwrite(save_img_path, img_bgr);
delete yolov5;
return 0;
}
TensorRT:通过TensorRT使用NVIDIA GPU提升推理性能
运行 bash ./build.sh tensorrt
以构建支持 TensorRT 的 lite.ai.toolkit,然后使用下面的代码测试 yolov5 。注意: lite.ai.toolkit 需要 TensorRT 10.x(或更高版本)和 CUDA 12.x(或更高版本)。有关更多详细信息,请查看 build.sh、 tensorrt-linux-x86_64-install.zh.md 、 test_lite_yolov5.cpp 和 NVIDIA/TensorRT。
// trtexec --onnx=yolov5s.onnx --saveEngine=yolov5s.engine
auto *yolov5 = new lite::trt::cv::detection::YOLOV5(engine_path);
四、快速设置软件
1、要快速设置 lite.ai.toolkit,您可以按照下面列出的CMakeLists.txt进行作。
set(lite.ai.toolkit_DIR YOUR-PATH-TO-LITE-INSTALL)
find_package(lite.ai.toolkit REQUIRED PATHS ${lite.ai.toolkit_DIR})
add_executable(lite_yolov5 test_lite_yolov5.cpp)
target_link_libraries(lite_yolov5 ${lite.ai.toolkit_LIBS})
2、与 MNN 或 ONNXRuntime 混合
lite.ai.toolkit 的目标不是在 MNN 和 ONNXRuntime 之上进行抽象。因此,您可以将 lite.ai.toolkit 与 MNN( -DENABLE_MNN=ON, default OFF
) 或 ONNXRuntime() 混合使用 -DENABLE_ONNXRUNTIME=ON, default ON
。lite.ai.toolkit 安装包包含完整的 MNN 和 ONNXRuntime。工作流可能如下所示
#include "lite/lite.h"
// 0. use yolov5 from lite.ai.toolkit to detect objs.
auto *yolov5 = new lite::cv::detection::YoloV5(onnx_path);
// 1. use OnnxRuntime or MNN to implement your own classfier.
interpreter = std::shared_ptr<MNN::Interpreter>(MNN::Interpreter::createFromFile(mnn_path));
// or: session = new Ort::Session(ort_env, onnx_path, session_options);
classfier = interpreter->createSession(schedule_config);
// 2. then, classify the detected objs use your own classfier ...
3、Supported Models Matrix 支持的模型矩阵
- / = not supported now.
/ = 现在不支持。 - / = Not supported at this time.
/ = 目前不支持。 - ✅ = known work and official supported now.
✅ = 已知工作和官方支持。 - ✔️ = known work, but unofficial supported now.
✔️ = 已知工作,但现在支持非官方。 - ✔️ = Known to work, but not officially supported at this time.
✔️ = 已知有效,但目前不受官方支持。 - ❔ = in my plan, but not coming soon, maybe a few months later.
❔ = 在我的计划中,但不会很快出现,也许几个月后。