🛠**Lite.Ai.ToolKit**:一个轻量级的 C++ 工具包,包含 100+ 个很棒的 AI 模型,例如对象检测、人脸检测、人脸识别、分割、遮罩等。请参阅 Model Zoo 和 ONNX Hub、MNN Hub、TNN Hub、NCNN Hub。
3700 Stars 711 Forks 0 Issues 6 贡献者 GPL-3.0 License C 语言
代码: https://github.com/DefTruth/lite.ai.toolkit
更多AI开源软件:AI开源 - 小众AI

主要功能
- **简单且用户友好。**简单一致的语法,如 **lite::cv::Type::Class**,参见示例。
- **最小依赖项。**默认情况下只需要 **OpenCV** 和 **ONNXRuntime**,详见 build。
- **支持多种型号。** **300+**C++ 实现和 **500+** 权重 👉 **Supported-Matrix**。
快速开始 🌟🌟
示例 0:使用 YOLOv5 进行对象检测。从 Model-Zoo 下载模型^2^.
#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;
}
您可以从 tag/v0.2.0 下载预构建的 lite.ai.tooklit 库和测试资源。
export LITE_AI_TAG_URL=https://github.com/DefTruth/lite.ai.toolkit/releases/download/v0.2.0
wget ${LITE_AI_TAG_URL}/lite-ort1.17.1+ocv4.9.0+ffmpeg4.2.2-linux-x86_64.tgz
wget ${LITE_AI_TAG_URL}/yolov5s.onnx && wget ${LITE_AI_TAG_URL}/test_yolov5.jpg
🎉🎉TensorRT :通过 TensorRT 使用 NVIDIA GPU 提高推理性能。
运行以构建支持 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 。bash ./build.sh tensorrt
// trtexec --onnx=yolov5s.onnx --saveEngine=yolov5s.engine
auto *yolov5 = new lite::trt::cv::detection::YOLOV5(engine_path);
快速设置 👀
要快速设置,您可以按照下面列出的方法进行操作。👇👀lite.ai.toolkitCMakeLists.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})
与 MNN 或 ONNXRuntime 👇👇 混合
lite.ai.toolkit 的目标不是在 MNN 和 ONNXRuntime 之上抽象。因此,您可以将 lite.ai.toolkit 与 MNN() 或 ONNXRuntime() 混合使用。lite.ai.toolkit 安装包包含完整的 MNN 和 ONNXRuntime。工作流可能如下所示:-DENABLE_MNN=ON, default OFF-DENABLE_ONNXRUNTIME=ON, default ON
#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 ...
MNN 和 ONNXRuntime 包含的标头可以在 mnn_config.h 和 ort_config.h 中找到。
- 🔑️ 查看详细的 Quick Start!单击此处!
下载资源
您可以从 tag/v0.2.0 下载预构建的 lite.ai.tooklit 库和测试资源。
export LITE_AI_TAG_URL=https://github.com/DefTruth/lite.ai.toolkit/releases/download/v0.2.0
wget ${LITE_AI_TAG_URL}/lite-ort1.17.1+ocv4.9.0+ffmpeg4.2.2-linux-x86_64.tgz
wget ${LITE_AI_TAG_URL}/yolov5s.onnx && wget ${LITE_AI_TAG_URL}/test_yolov5.jpg
tar -zxvf lite-ort1.17.1+ocv4.9.0+ffmpeg4.2.2-linux-x86_64.tgz
编写测试代码
编写 YOLOv5 示例代码并命名:test_lite_yolov5.cpp
#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;
}
设置 CMakeLists.txt
cmake_minimum_required(VERSION 3.10)
project(lite_yolov5)
set(CMAKE_CXX_STANDARD 17)
set(lite.ai.toolkit_DIR YOUR-PATH-TO-LITE-INSTALL)
find_package(lite.ai.toolkit REQUIRED PATHS ${lite.ai.toolkit_DIR})
if (lite.ai.toolkit_Found)
message(STATUS "lite.ai.toolkit_INCLUDE_DIRS: ${lite.ai.toolkit_INCLUDE_DIRS}")
message(STATUS " lite.ai.toolkit_LIBS: ${lite.ai.toolkit_LIBS}")
message(STATUS " lite.ai.toolkit_LIBS_DIRS: ${lite.ai.toolkit_LIBS_DIRS}")
endif()
add_executable(lite_yolov5 test_lite_yolov5.cpp)
target_link_libraries(lite_yolov5 ${lite.ai.toolkit_LIBS})
构建示例
mkdir build && cd build && cmake .. && make -j1
然后,将 中列出的 lib 路径导出到 .LD_LIBRARY_PATHlite.ai.toolkit_LIBS_DIRS
export LD_LIBRARY_PATH=YOUR-PATH-TO-LITE-INSTALL/lib:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=YOUR-PATH-TO-LITE-INSTALL/third_party/opencv/lib:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=YOUR-PATH-TO-LITE-INSTALL/third_party/onnxruntime/lib:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=YOUR-PATH-TO-LITE-INSTALL/third_party/MNN/lib:$LD_LIBRARY_PATH # if -DENABLE_MNN=ON
运行 binary:
cp ../yolov5s.onnx ../test_yolov.jpg .
./lite_yolov5
输出日志:
LITEORT_DEBUG LogId: ../examples/hub/onnx/cv/yolov5s.onnx
=============== Input-Dims ==============
Name: images
Dims: 1
Dims: 3
Dims: 640
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: 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
支持的模型矩阵
- / = 现在不支持。
- ✅ = 已知工作和官方支持。
- ✔️ = 已知工作,但现在支持非官方。
- ❔ = 在我的计划中,但不会很快出现,也许几个月后。
NVIDIA GPU 推理:TensorRT
| 类 | 类 | 类 | 类 | 类 | 系统 | 发动机 |
|---|---|---|---|---|---|---|
| ✅YOLOv5 | ✅YOLOv6 | ✅YOLOv8 | ✅ |

最低0.47元/天 解锁文章
7318

被折叠的 条评论
为什么被折叠?



