[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"similar-cyrusbehr--tensorrt-cpp-api":3,"tool-cyrusbehr--tensorrt-cpp-api":61},[4,18,26,36,44,53],{"id":5,"name":6,"github_repo":7,"description_zh":8,"stars":9,"difficulty_score":10,"last_commit_at":11,"category_tags":12,"status":17},4358,"openclaw","openclaw\u002Fopenclaw","OpenClaw 是一款专为个人打造的本地化 AI 助手，旨在让你在自己的设备上拥有完全可控的智能伙伴。它打破了传统 AI 助手局限于特定网页或应用的束缚，能够直接接入你日常使用的各类通讯渠道，包括微信、WhatsApp、Telegram、Discord、iMessage 等数十种平台。无论你在哪个聊天软件中发送消息，OpenClaw 都能即时响应，甚至支持在 macOS、iOS 和 Android 设备上进行语音交互，并提供实时的画布渲染功能供你操控。\n\n这款工具主要解决了用户对数据隐私、响应速度以及“始终在线”体验的需求。通过将 AI 部署在本地，用户无需依赖云端服务即可享受快速、私密的智能辅助，真正实现了“你的数据，你做主”。其独特的技术亮点在于强大的网关架构，将控制平面与核心助手分离，确保跨平台通信的流畅性与扩展性。\n\nOpenClaw 非常适合希望构建个性化工作流的技术爱好者、开发者，以及注重隐私保护且不愿被单一生态绑定的普通用户。只要具备基础的终端操作能力（支持 macOS、Linux 及 Windows WSL2），即可通过简单的命令行引导完成部署。如果你渴望拥有一个懂你",349277,3,"2026-04-06T06:32:30",[13,14,15,16],"Agent","开发框架","图像","数据工具","ready",{"id":19,"name":20,"github_repo":21,"description_zh":22,"stars":23,"difficulty_score":10,"last_commit_at":24,"category_tags":25,"status":17},3808,"stable-diffusion-webui","AUTOMATIC1111\u002Fstable-diffusion-webui","stable-diffusion-webui 是一个基于 Gradio 构建的网页版操作界面，旨在让用户能够轻松地在本地运行和使用强大的 Stable Diffusion 图像生成模型。它解决了原始模型依赖命令行、操作门槛高且功能分散的痛点，将复杂的 AI 绘图流程整合进一个直观易用的图形化平台。\n\n无论是希望快速上手的普通创作者、需要精细控制画面细节的设计师，还是想要深入探索模型潜力的开发者与研究人员，都能从中获益。其核心亮点在于极高的功能丰富度：不仅支持文生图、图生图、局部重绘（Inpainting）和外绘（Outpainting）等基础模式，还独创了注意力机制调整、提示词矩阵、负向提示词以及“高清修复”等高级功能。此外，它内置了 GFPGAN 和 CodeFormer 等人脸修复工具，支持多种神经网络放大算法，并允许用户通过插件系统无限扩展能力。即使是显存有限的设备，stable-diffusion-webui 也提供了相应的优化选项，让高质量的 AI 艺术创作变得触手可及。",162132,"2026-04-05T11:01:52",[14,15,13],{"id":27,"name":28,"github_repo":29,"description_zh":30,"stars":31,"difficulty_score":32,"last_commit_at":33,"category_tags":34,"status":17},1381,"everything-claude-code","affaan-m\u002Feverything-claude-code","everything-claude-code 是一套专为 AI 编程助手（如 Claude Code、Codex、Cursor 等）打造的高性能优化系统。它不仅仅是一组配置文件，而是一个经过长期实战打磨的完整框架，旨在解决 AI 代理在实际开发中面临的效率低下、记忆丢失、安全隐患及缺乏持续学习能力等核心痛点。\n\n通过引入技能模块化、直觉增强、记忆持久化机制以及内置的安全扫描功能，everything-claude-code 能显著提升 AI 在复杂任务中的表现，帮助开发者构建更稳定、更智能的生产级 AI 代理。其独特的“研究优先”开发理念和针对 Token 消耗的优化策略，使得模型响应更快、成本更低，同时有效防御潜在的攻击向量。\n\n这套工具特别适合软件开发者、AI 研究人员以及希望深度定制 AI 工作流的技术团队使用。无论您是在构建大型代码库，还是需要 AI 协助进行安全审计与自动化测试，everything-claude-code 都能提供强大的底层支持。作为一个曾荣获 Anthropic 黑客大奖的开源项目，它融合了多语言支持与丰富的实战钩子（hooks），让 AI 真正成长为懂上",159267,2,"2026-04-17T11:29:14",[14,13,35],"语言模型",{"id":37,"name":38,"github_repo":39,"description_zh":40,"stars":41,"difficulty_score":32,"last_commit_at":42,"category_tags":43,"status":17},2271,"ComfyUI","Comfy-Org\u002FComfyUI","ComfyUI 是一款功能强大且高度模块化的视觉 AI 引擎，专为设计和执行复杂的 Stable Diffusion 图像生成流程而打造。它摒弃了传统的代码编写模式，采用直观的节点式流程图界面，让用户通过连接不同的功能模块即可构建个性化的生成管线。\n\n这一设计巧妙解决了高级 AI 绘图工作流配置复杂、灵活性不足的痛点。用户无需具备编程背景，也能自由组合模型、调整参数并实时预览效果，轻松实现从基础文生图到多步骤高清修复等各类复杂任务。ComfyUI 拥有极佳的兼容性，不仅支持 Windows、macOS 和 Linux 全平台，还广泛适配 NVIDIA、AMD、Intel 及苹果 Silicon 等多种硬件架构，并率先支持 SDXL、Flux、SD3 等前沿模型。\n\n无论是希望深入探索算法潜力的研究人员和开发者，还是追求极致创作自由度的设计师与资深 AI 绘画爱好者，ComfyUI 都能提供强大的支持。其独特的模块化架构允许社区不断扩展新功能，使其成为当前最灵活、生态最丰富的开源扩散模型工具之一，帮助用户将创意高效转化为现实。",108322,"2026-04-10T11:39:34",[14,15,13],{"id":45,"name":46,"github_repo":47,"description_zh":48,"stars":49,"difficulty_score":32,"last_commit_at":50,"category_tags":51,"status":17},6121,"gemini-cli","google-gemini\u002Fgemini-cli","gemini-cli 是一款由谷歌推出的开源 AI 命令行工具，它将强大的 Gemini 大模型能力直接集成到用户的终端环境中。对于习惯在命令行工作的开发者而言，它提供了一条从输入提示词到获取模型响应的最短路径，无需切换窗口即可享受智能辅助。\n\n这款工具主要解决了开发过程中频繁上下文切换的痛点，让用户能在熟悉的终端界面内直接完成代码理解、生成、调试以及自动化运维任务。无论是查询大型代码库、根据草图生成应用，还是执行复杂的 Git 操作，gemini-cli 都能通过自然语言指令高效处理。\n\n它特别适合广大软件工程师、DevOps 人员及技术研究人员使用。其核心亮点包括支持高达 100 万 token 的超长上下文窗口，具备出色的逻辑推理能力；内置 Google 搜索、文件操作及 Shell 命令执行等实用工具；更独特的是，它支持 MCP（模型上下文协议），允许用户灵活扩展自定义集成，连接如图像生成等外部能力。此外，个人谷歌账号即可享受免费的额度支持，且项目基于 Apache 2.0 协议完全开源，是提升终端工作效率的理想助手。",100752,"2026-04-10T01:20:03",[52,13,15,14],"插件",{"id":54,"name":55,"github_repo":56,"description_zh":57,"stars":58,"difficulty_score":32,"last_commit_at":59,"category_tags":60,"status":17},4721,"markitdown","microsoft\u002Fmarkitdown","MarkItDown 是一款由微软 AutoGen 团队打造的轻量级 Python 工具，专为将各类文件高效转换为 Markdown 格式而设计。它支持 PDF、Word、Excel、PPT、图片（含 OCR）、音频（含语音转录）、HTML 乃至 YouTube 链接等多种格式的解析，能够精准提取文档中的标题、列表、表格和链接等关键结构信息。\n\n在人工智能应用日益普及的今天，大语言模型（LLM）虽擅长处理文本，却难以直接读取复杂的二进制办公文档。MarkItDown 恰好解决了这一痛点，它将非结构化或半结构化的文件转化为模型“原生理解”且 Token 效率极高的 Markdown 格式，成为连接本地文件与 AI 分析 pipeline 的理想桥梁。此外，它还提供了 MCP（模型上下文协议）服务器，可无缝集成到 Claude Desktop 等 LLM 应用中。\n\n这款工具特别适合开发者、数据科学家及 AI 研究人员使用，尤其是那些需要构建文档检索增强生成（RAG）系统、进行批量文本分析或希望让 AI 助手直接“阅读”本地文件的用户。虽然生成的内容也具备一定可读性，但其核心优势在于为机器",93400,"2026-04-06T19:52:38",[52,14],{"id":62,"github_repo":63,"name":64,"description_en":65,"description_zh":66,"ai_summary_zh":66,"readme_en":67,"readme_zh":68,"quickstart_zh":69,"use_case_zh":70,"hero_image_url":71,"owner_login":72,"owner_name":73,"owner_avatar_url":74,"owner_bio":75,"owner_company":76,"owner_location":77,"owner_email":78,"owner_twitter":78,"owner_website":79,"owner_url":80,"languages":81,"stars":98,"forks":99,"last_commit_at":100,"license":101,"difficulty_score":102,"env_os":103,"env_gpu":104,"env_ram":105,"env_deps":106,"category_tags":117,"github_topics":118,"view_count":32,"oss_zip_url":78,"oss_zip_packed_at":78,"status":17,"created_at":124,"updated_at":125,"faqs":126,"releases":156},8493,"cyrusbehr\u002Ftensorrt-cpp-api","tensorrt-cpp-api","TensorRT C++ API Tutorial","tensorrt-cpp-api 是一个专注于 NVIDIA TensorRT C++ API 的实战教程项目，旨在帮助开发者轻松掌握高性能 GPU 机器学习推理技术。面对 TensorRT 官方文档繁杂难懂、上手门槛高的问题，该项目通过完整的代码示例和详细的视频讲解，手把手教用户如何在 Ubuntu 环境下部署和优化推理引擎。\n\n它核心解决了从环境搭建、引擎生成到异步推理执行的全流程痛点，支持单\u002F多输入输出模型及动态批处理，涵盖 FP32、FP16 和 INT8 多种精度模式。项目特别强调了 CUDA 流的使用以實現异步推理，并提供了处理 GPU 内存与图像数据的实用方案。作为基于 Insightface、YoloV8 等主流模型的通用底座，用户只需补充后处理逻辑即可快速迁移应用。\n\n这份资源非常适合具备一定 C++ 基础的 AI 工程师、研究人员及系统架构师。对于希望深入理解底层推理机制、追求极致性能优化，或需要将深度学习模型高效部署到生产环境的开发者来说，tensorrt-cpp-api 能大幅缩短学习曲线，避免在复杂的配置细节中迷失方向，是连接理论文档与实际工程落地的优质桥梁。","[![Stargazers][stars-shield]][stars-url]\n\u003C!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->\n[![All Contributors](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002Fall_contributors-3-orange.svg?style=flat-square)](#contributors-)\n\u003C!-- ALL-CONTRIBUTORS-BADGE:END -->\n[![Issues][issues-shield]][issues-url]\n[![LinkedIn][linkedin-shield]][linkedin-url]\n\n\u003C!-- PROJECT LOGO -->\n\u003Cbr \u002F>\n\u003Cp align=\"center\">\n  \u003Ca href=\"https:\u002F\u002Fgithub.com\u002Fcyrusbehr\u002Ftensorrt-cpp-api\">\n    \u003Cimg width=\"40%\" src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fcyrusbehr_tensorrt-cpp-api_readme_e3e3ef3451fd.png\" alt=\"logo\">\n  \u003C\u002Fa>\n\n  \u003Ch3 align=\"center\">TensorRT C++ API Tutorial\u003C\u002Fh3>\n\n  \u003Cp align=\"center\">\n    \u003Cb>\n    How to use TensorRT C++ API for high performance GPU machine-learning inference.\n    \u003C\u002Fb>\n    \u003Cbr \u002F>\n    Supports models with single \u002F multiple inputs and single \u002F multiple outputs with batching.\n    \u003Cbr \u002F>\n    \u003Cbr \u002F>\n    \u003Ca href=\"https:\u002F\u002Fwww.youtube.com\u002Fwatch?v=kPJ9uDduxOs\">Project Overview Video\u003C\u002Fa>\n    .\n    \u003Ca href=\"https:\u002F\u002Fyoutu.be\u002FZ0n5aLmcRHQ\">Code Deep-Dive Video\u003C\u002Fa>\n  \u003C\u002Fp>\n\u003C\u002Fp>\n\n## Looking for Maintainers 🚀\n\nThis project is actively seeking maintainers to help guide its growth and improvement. If you're passionate about this project and interested in contributing, I’d love to hear from you!\n\nPlease feel free to reach out via [LinkedIn](https:\u002F\u002Fwww.linkedin.com\u002Fin\u002Fcyrus-behroozi\u002F) to discuss how you can get involved.\n\n\n# TensorRT C++ Tutorial\n*I read all the NVIDIA TensorRT docs so that you don't have to!*\n\nThis project demonstrates how to use the TensorRT C++ API for high performance GPU inference on image data. It covers how to do the following:\n- How to install TensorRT 10 on Ubuntu 20.04 \u002F 22.04.\n- How to generate a TensorRT engine file optimized for your GPU.\n- How to specify a simple optimization profile.\n- How to run FP32, FP16, or INT8 precision inference. \n- How to read \u002F write data from \u002F into GPU memory and work with GPU images.\n- How to use cuda stream to run async inference and later synchronize. \n- How to work with models with static and dynamic batch sizes.\n- How to work with models with single or multiple output tensors.\n- How to work with models with multiple inputs.\n- Includes a [Video walkthrough](https:\u002F\u002Fyoutu.be\u002FZ0n5aLmcRHQ) where I explain every line of code.\n- The code can be used as a base for any model which takes a fixed size image \u002F images as input, including [Insightface](https:\u002F\u002Fgithub.com\u002Fdeepinsight\u002Finsightface) [ArcFace](https:\u002F\u002Fgithub.com\u002Fonnx\u002Fmodels\u002Ftree\u002Fmain\u002Fvision\u002Fbody_analysis\u002Farcface), [YoloV8](https:\u002F\u002Fgithub.com\u002Fultralytics\u002Fultralytics), [SCRFD](https:\u002F\u002Finsightface.ai\u002Fscrfd) face detection.\n  - You will just need to implement the appropriate post-processing code.\n- TODO: Add support for models with dynamic input shapes.\n- TODO: Add support for Windows\n\n## Getting Started\nThe following instructions assume you are using Ubuntu 20.04 or 22.04.\nYou will need to supply your own onnx model for this sample code or you can download the sample model (see Sanity Check section below). \n\n### Prerequisites\n- Tested and working on Ubuntu 20.04 and 22.04 (Windows is **not** supported at this time)\n- Install CUDA 11 or 12, instructions [here](https:\u002F\u002Fdeveloper.nvidia.com\u002Fcuda-downloads).\n  - Recommended >= 12.0\n  - Required >= 11.0\n- Install cudnn, instructions [here](https:\u002F\u002Fdocs.nvidia.com\u002Fdeeplearning\u002Fcudnn\u002Finstall-guide\u002Findex.html#download).\n  - Required >= 8\n  - Required \u003C 9 (OpenCV GPU does not yet support)\n- `sudo apt install build-essential`\n- `sudo snap install cmake --classic`\n- `sudo apt install libspdlog-dev libfmt-dev` (for logging)\n- Install OpenCV with cuda support. To compile OpenCV from source, run the `build_opencv.sh` script provided in `.\u002Fscripts\u002F`.\n  - If you use the provided script and you have installed cuDNN to a non-standard location, you must modify the `CUDNN_INCLUDE_DIR` and `CUDNN_LIBRARY` variables in the script.  \n  - Recommended >= 4.8\n- Download TensorRT 10 from [here](https:\u002F\u002Fdeveloper.nvidia.com\u002Ftensorrt\u002Fdownload\u002F10x).\n  - Required >= 10.0 \n- Navigate to the `CMakeLists.txt` file and replace the `TODO` with the path to your TensorRT installation.\n\n### Building the Library\n- `mkdir build`\n- `cd build`\n- `cmake ..`\n- `make -j$(nproc)`\n\n### Running the Executable\n- Navigate to the build directory\n- Run the executable and provide the path to your onnx model.\n- ex. `.\u002Frun_inference_benchmark --onnx_model ..\u002Fmodels\u002Fyolov8n.onnx`\n  - Note: See sanity check section below for instructions on how to obtain the yolov8n model.  \n- The first time you run the executable for a given model and options, a TensorRT engine file will be built from your onnx model. This process is fairly slow and can take 5+ minutes for some models (ex. yolo models). \n- Alternatively, you can choose to supply your own TensorRT engine file directly:\n- ex. `.\u002Frun_inference_benchmark --trt_model ..\u002Fmodels\u002Fyolov8n.engine.NVIDIAGeForceRTX3080LaptopGPU.fp16.1.1`\n  - Note: See V5.0 changelog below for warnings when supply your own TensorRT engine file. \n\n### Sanity Check\n- To perform a sanity check, download the `YOLOv8n` model from [here](https:\u002F\u002Fgithub.com\u002Fultralytics\u002Fultralytics#models).\n- Next, convert it from pytorch to onnx using the following script:\n  - You will need to run `pip3 install ultralytics` first.\n     \n```python\nfrom ultralytics import YOLO\nmodel = YOLO(\".\u002Fyolov8n.pt\")\nmodel.fuse()\nmodel.info(verbose=False)  # Print model information\nmodel.export(format=\"onnx\", opset=12) # Export the model to onnx using opset 12\n```\n\n- Place the resulting onnx model, `yolov8n.onnx`, in the `.\u002Fmodels\u002F` directory. \n- Running inference using said model and the image located in `.\u002Finputs\u002Fteam.jpg` should produce the following feature vector:\n  - Note: The feature vector will not be identical (but very similar) as [TensorRT is not deterministic](https:\u002F\u002Fdocs.nvidia.com\u002Fdeeplearning\u002Ftensorrt\u002Fdeveloper-guide\u002Findex.html#determinism). \n```text\n3.41113 16.5312 20.8828 29.8984 43.7266 54.9609 62.0625 65.8594 70.0312 72.9531 ...\n```\n\n### INT8 Inference\nEnabling INT8 precision can further speed up inference at the cost of accuracy reduction due to reduced dynamic range. \nFor INT8 precision, the user must supply calibration data which is representative of real data the model will see. \nIt is advised to use 1K+ calibration images. To enable INT8 inference with the YoloV8 sanity check model, the following steps must be taken:\n-  Change `options.precision = Precision::FP16;` to `options.precision = Precision::INT8;` in `main.cpp`\n- `options.calibrationDataDirectoryPath = \"\";` must be changed in `main.cpp` to specify path containing calibration data. \n  - If using the YoloV8 model, it is advised to used the COCO validation dataset, which can be downloaded with `wget http:\u002F\u002Fimages.cocodataset.org\u002Fzips\u002Fval2017.zip`\n- Make sure the resizing code in the `Int8EntropyCalibrator2::getBatch` method in `engine.cpp` (see `TODO`) is correct for your model.\n  - If using the YoloV8 model, the preprocessing code is correct and does not need to be changed.\n- Recompile, run the executable. \n- The calibration cache will be written to disk (`.calibration` extension) so that on subsequent model optimizations it can be reused. If you'd like to regenerate the calibration data, you must delete this cache file.  \n- If you get an \"out of memory in function allocate\" error, then you must reduce `Options.calibrationBatchSize` so that the entire batch can fit in your GPU memory. \n\n### Benchmarks\nBenchmarks run on RTX 3050 Ti Laptop GPU, 11th Gen Intel(R) Core(TM) i9-11900H @ 2.50GHz.\n\n| Model   | Precision | Batch Size | Avg Inference Time |\n|---------|-----------|------------|--------------------|\n| yolov8n | FP32      | 1          | 4.732 ms           |\n| yolov8n | FP16      | 1          | 2.493 ms           |\n| yolov8n | INT8      | 1          | 2.009 ms           |\n| yolov8x | FP32      | 1          | 76.63 ms           |\n| yolov8x | FP16      | 1          | 25.08 ms           |\n| yolov8x | INT8      | 1          | 11.62 ms           |\n\n### Sample Integration\nWondering how to integrate this library into your project? Or perhaps how to read the outputs of the YoloV8 model to extract meaningful information? \nIf so, check out my two latest projects, [YOLOv8-TensorRT-CPP](https:\u002F\u002Fgithub.com\u002Fcyrusbehr\u002FYOLOv8-TensorRT-CPP) and [YOLOv9-TensorRT-CPP](https:\u002F\u002Fgithub.com\u002Fcyrusbehr\u002FYOLOv9-TensorRT-CPP), which demonstrate how to use the TensorRT C++ API to run YoloV8\u002F9 inference (supports object detection, semantic segmentation, and body pose estimation). They make use of this project in the backend!\n\n### Project Structure\n```sh\nproject-root\u002F\n├── include\u002F\n│   ├── engine\u002F\n│   │   ├── EngineRunInference.inl\n│   │   ├── EngineUtilities.inl\n│   │   └── EngineBuildLoadNetwork.inl\n│   ├── util\u002F...\n│   ├── ...\n├── src\u002F\n|   ├── ...\n│   ├── engine.cpp\n│   ├── engine.h\n│   └── main.cpp\n├── CMakeLists.txt\n└── README.md\n```\n\n### Understanding the Code\n- The bulk of the implementation is located in `include\u002Fengine`. I have written lots of comments all throughout the code which should make it easy to understand what is going on. \n- The inference code is located in `include\u002Fengine\u002FEngineRunInference.inl`. \n- The building and loading of the TensorRT engine file is located in `include\u002Fengine\u002FEngineBuildLoadNetwork.inl`.\n- You can also check out my [deep-dive video](https:\u002F\u002Fyoutu.be\u002FZ0n5aLmcRHQ) in which I explain every line of code.\n\n### How to Debug\n- The implementation uses the `spdlog` library for logging. You can change the log level by setting the environment variable `LOG_LEVEL` to one of the following values: `trace`, `debug`, `info`, `warn`, `error`, `critical`, `off`.\n\n- If you have issues creating the TensorRT engine file from the onnx model, consider setting the environment variable `LOG_LEVEL` to `trace` and re-run the application. This should give you more information on where exactly the build process is failing.\n\n### Show your Appreciation\nIf this project was helpful to you, I would appreciate if you could give it a star. That will encourage me to ensure it's up to date and solve issues quickly. I also do consulting work if you require more specific help. Connect with me on [LinkedIn](https:\u002F\u002Fwww.linkedin.com\u002Fin\u002Fcyrus-behroozi\u002F). \n\n### Contributors\n\n\u003C!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->\n\u003C!-- prettier-ignore-start -->\n\u003C!-- markdownlint-disable -->\n\u003Ctable>\n  \u003Ctbody>\n    \u003Ctr>\n      \u003Ctd align=\"center\" valign=\"top\" width=\"14.28%\">\u003Ca href=\"https:\u002F\u002Fltetrel.github.io\u002F\">\u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fcyrusbehr_tensorrt-cpp-api_readme_a29092047009.png\" width=\"100px;\" alt=\"Loic Tetrel\"\u002F>\u003Cbr \u002F>\u003Csub>\u003Cb>Loic Tetrel\u003C\u002Fb>\u003C\u002Fsub>\u003C\u002Fa>\u003Cbr \u002F>\u003Ca href=\"https:\u002F\u002Fgithub.com\u002Fcyrusbehr\u002Ftensorrt-cpp-api\u002Fcommits?author=ltetrel\" title=\"Code\">💻\u003C\u002Fa>\u003C\u002Ftd>\n      \u003Ctd align=\"center\" valign=\"top\" width=\"14.28%\">\u003Ca href=\"https:\u002F\u002Fgithub.com\u002Fthomaskleiven\">\u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fcyrusbehr_tensorrt-cpp-api_readme_3adf31448ad5.png\" width=\"100px;\" alt=\"thomaskleiven\"\u002F>\u003Cbr \u002F>\u003Csub>\u003Cb>thomaskleiven\u003C\u002Fb>\u003C\u002Fsub>\u003C\u002Fa>\u003Cbr \u002F>\u003Ca href=\"https:\u002F\u002Fgithub.com\u002Fcyrusbehr\u002Ftensorrt-cpp-api\u002Fcommits?author=thomaskleiven\" title=\"Code\">💻\u003C\u002Fa>\u003C\u002Ftd>\n      \u003Ctd align=\"center\" valign=\"top\" width=\"14.28%\">\u003Ca href=\"https:\u002F\u002Fgithub.com\u002Fqq978358810\">\u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fcyrusbehr_tensorrt-cpp-api_readme_ef7bcf38b9cc.png\" width=\"100px;\" alt=\"WiCyn\"\u002F>\u003Cbr \u002F>\u003Csub>\u003Cb>WiCyn\u003C\u002Fb>\u003C\u002Fsub>\u003C\u002Fa>\u003Cbr \u002F>\u003Ca href=\"https:\u002F\u002Fgithub.com\u002Fcyrusbehr\u002Ftensorrt-cpp-api\u002Fcommits?author=qq978358810\" title=\"Code\">💻\u003C\u002Fa>\u003C\u002Ftd>\n    \u003C\u002Ftr>\n  \u003C\u002Ftbody>\n\u003C\u002Ftable>\n\n\u003C!-- markdownlint-restore -->\n\u003C!-- prettier-ignore-end -->\n\n\u003C!-- ALL-CONTRIBUTORS-LIST:END -->\n\n### Changelog\n\n**V6.0**\n\n- Implementation now requires TensorRT >= 10.0.\n\n**V5.0**\n\n- `Engine` class has been modified to take a template parameter which specifies the models output data type. The implementation now supports outputs of type `float`, `__half`, `int8_t`, `int32_t`, `bool`, and `uint8_t`. \n- Added support for loading TensorRT engine file directly without needing to compile from onnx model. Howver, it is highly recommended that you use the API provided to build the engine file from the onnx model, instead of loading a TensorRT model directly. If you choose to load a TensorRT model file directly, you must hand-check that the `Options` have been set correctly for your model (for example, if your model has been compiled for FP32 but you try running FP16 inference, it will fail, potentially without a verbose error).\n- Added command line parser. \n\n**V4.1**\n\n- Added support for fixed batch size > 1.  \n\n**V4.0**\n\n- Added support for INT8 precision.\n\n\n**V3.0**\n\n- Implementation has been updated to use TensorRT 8.6 API (ex. `IExecutionContext::enqueueV3()`). \n- Executable has renamed from `driver` to `run_inference_benchmark` and now must be passed path to onnx model as command line argument. \n- Removed `Options.doesSupportDynamicBatchSize`. Implementation now auto-detects supported batch sizes.\n- Removed `Options.maxWorkspaceSize`. Implementation now does not limit GPU memory during model constructions, allowing implementation to use as much of memory pool as is available for intermediate layers.\n\n**v2.2**\n\n- Serialize model name as part of engine file. \n\n**V2.1**\n\n- Added support for models with multiple inputs. Implementation now supports models with single inputs, multiple inputs, single outputs, multiple outputs, and batching. \n\n**V2.0**\n\n- Requires OpenCV cuda to be installed. To install, follow instructions [here](https:\u002F\u002Fgist.github.com\u002Fraulqf\u002Ff42c718a658cddc16f9df07ecc627be7).\n- `Options.optBatchSizes` has been removed, replaced by `Options.optBatchSize`.\n- Support models with more than a single output (ex. SCRFD).  \n- Added support for models which do not support batch inference (first input dimension is fixed).\n- More error checking.\n- Fixed a bunch of common issues people were running into with the original V1.0 version.\n- Remove whitespace from GPU device name \n\n\u003C!-- MARKDOWN LINKS & IMAGES -->\n\u003C!-- https:\u002F\u002Fwww.markdownguide.org\u002Fbasic-syntax\u002F#reference-style-links -->\n[stars-shield]: https:\u002F\u002Fimg.shields.io\u002Fgithub\u002Fstars\u002Fcyrusbehr\u002Ftensorrt-cpp-api.svg?style=flat-square\n[stars-url]: https:\u002F\u002Fgithub.com\u002Fcyrusbehr\u002Ftensorrt-cpp-api\u002Fstargazers\n[issues-shield]: https:\u002F\u002Fimg.shields.io\u002Fgithub\u002Fissues\u002Fcyrusbehr\u002Ftensorrt-cpp-api.svg?style=flat-square\n[issues-url]: https:\u002F\u002Fgithub.com\u002Fcyrusbehr\u002Ftensorrt-cpp-api\u002Fissues\n[linkedin-shield]: https:\u002F\u002Fimg.shields.io\u002Fbadge\u002F-LinkedIn-black.svg?style=flat-square&logo=linkedin&colorB=555\n[linkedin-url]: https:\u002F\u002Flinkedin.com\u002Fin\u002Fcyrus-behroozi\u002F\n\n## Contributors ✨\n\nThanks goes to these wonderful people ([emoji key](https:\u002F\u002Fallcontributors.org\u002Fdocs\u002Fen\u002Femoji-key)):\n\n\u003C!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->\n\u003C!-- prettier-ignore-start -->\n\u003C!-- markdownlint-disable -->\n\u003C!-- markdownlint-restore -->\n\u003C!-- prettier-ignore-end -->\n\u003C!-- ALL-CONTRIBUTORS-LIST:END -->\n\nThis project follows the [all-contributors](https:\u002F\u002Fgithub.com\u002Fall-contributors\u002Fall-contributors) specification. Contributions of any kind welcome!\n","[![Stargazers][stars-shield]][stars-url]\n\u003C!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->\n[![All Contributors](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002Fall_contributors-3-orange.svg?style=flat-square)](#contributors-)\n\u003C!-- ALL-CONTRIBUTORS-BADGE:END -->\n[![Issues][issues-shield]][issues-url]\n[![LinkedIn][linkedin-shield]][linkedin-url]\n\n\u003C!-- PROJECT LOGO -->\n\u003Cbr \u002F>\n\u003Cp align=\"center\">\n  \u003Ca href=\"https:\u002F\u002Fgithub.com\u002Fcyrusbehr\u002Ftensorrt-cpp-api\">\n    \u003Cimg width=\"40%\" src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fcyrusbehr_tensorrt-cpp-api_readme_e3e3ef3451fd.png\" alt=\"logo\">\n  \u003C\u002Fa>\n\n  \u003Ch3 align=\"center\">TensorRT C++ API 教程\u003C\u002Fh3>\n\n  \u003Cp align=\"center\">\n    \u003Cb>\n    如何使用 TensorRT C++ API 实现高性能 GPU 机器学习推理。\n    \u003C\u002Fb>\n    \u003Cbr \u002F>\n    支持具有单个\u002F多个输入以及单个\u002F多个输出的模型，并且可以进行批处理。\n    \u003Cbr \u002F>\n    \u003Cbr \u002F>\n    \u003Ca href=\"https:\u002F\u002Fwww.youtube.com\u002Fwatch?v=kPJ9uDduxOs\">项目概述视频\u003C\u002Fa>\n    .\n    \u003Ca href=\"https:\u002F\u002Fyoutu.be\u002FZ0n5aLmcRHQ\">代码深度解析视频\u003C\u002Fa>\n  \u003C\u002Fp>\n\u003C\u002Fp>\n\n## 寻求维护者 🚀\n\n本项目正在积极寻找维护者，以帮助指导其发展和改进。如果您对该项目充满热情并有意贡献，我非常期待与您交流！\n\n欢迎通过 [LinkedIn](https:\u002F\u002Fwww.linkedin.com\u002Fin\u002Fcyrus-behroozi\u002F) 联系我，讨论您如何参与其中。\n\n\n# TensorRT C++ 教程\n*我已阅读所有 NVIDIA TensorRT 文档，这样您就不必再费心了！*\n\n本项目演示如何使用 TensorRT C++ API 对图像数据进行高性能 GPU 推理。它涵盖了以下内容：\n- 如何在 Ubuntu 20.04 \u002F 22.04 上安装 TensorRT 10。\n- 如何为您的 GPU 生成优化后的 TensorRT 引擎文件。\n- 如何指定一个简单的优化配置文件。\n- 如何运行 FP32、FP16 或 INT8 精度的推理。\n- 如何从 GPU 内存读取\u002F写入数据，并处理 GPU 图像。\n- 如何使用 CUDA 流执行异步推理并在稍后同步。\n- 如何处理具有静态和动态批大小的模型。\n- 如何处理具有单个或多个输出张量的模型。\n- 如何处理具有多个输入的模型。\n- 包含一个 [视频教程](https:\u002F\u002Fyoutu.be\u002FZ0n5aLmcRHQ)，我在其中逐行解释代码。\n- 此代码可用作任何以固定尺寸图像\u002F图像集作为输入的模型的基础，包括 [Insightface](https:\u002F\u002Fgithub.com\u002Fdeepinsight\u002Finsightface) [ArcFace](https:\u002F\u002Fgithub.com\u002Fonnx\u002Fmodels\u002Ftree\u002Fmain\u002Fvision\u002Fbody_analysis\u002Farcface)、[YoloV8](https:\u002F\u002Fgithub.com\u002Fultralytics\u002Fultralytics)、[SCRFD](https:\u002F\u002Finsightface.ai\u002Fscrfd) 人脸检测等。\n  - 您只需实现相应的后处理代码即可。\n- 待办事项：增加对输入形状动态变化的模型的支持。\n- 待办事项：增加对 Windows 的支持。\n\n## 入门指南\n以下说明假定您正在使用 Ubuntu 20.04 或 22.04。\n您需要提供自己的 ONNX 模型用于此示例代码，或者您可以下载示例模型（请参阅下方的“健康检查”部分）。\n\n### 前提条件\n- 已在 Ubuntu 20.04 和 22.04 上测试并正常工作（目前 **不** 支持 Windows）\n- 安装 CUDA 11 或 12，安装说明 [在此](https:\u002F\u002Fdeveloper.nvidia.com\u002Fcuda-downloads)。\n  - 推荐 >= 12.0\n  - 必需 >= 11.0\n- 安装 cuDNN，安装说明 [在此](https:\u002F\u002Fdocs.nvidia.com\u002Fdeeplearning\u002Fcudnn\u002Finstall-guide\u002Findex.html#download)。\n  - 必需 >= 8\n  - 必需 \u003C 9（OpenCV GPU 尚不支持）\n- `sudo apt install build-essential`\n- `sudo snap install cmake --classic`\n- `sudo apt install libspdlog-dev libfmt-dev`（用于日志记录）\n- 安装带有 CUDA 支持的 OpenCV。要从源代码编译 OpenCV，请运行 `.\u002Fscripts\u002F` 中提供的 `build_opencv.sh` 脚本。\n  - 如果您使用提供的脚本，并且将 cuDNN 安装到了非标准位置，则必须修改脚本中的 `CUDNN_INCLUDE_DIR` 和 `CUDNN_LIBRARY` 变量。\n  - 推荐 >= 4.8\n- 从 [此处](https:\u002F\u002Fdeveloper.nvidia.com\u002Ftensorrt\u002Fdownload\u002F10x) 下载 TensorRT 10。\n  - 必需 >= 10.0\n- 导航到 `CMakeLists.txt` 文件，将 `TODO` 替换为您 TensorRT 的安装路径。\n\n### 构建库\n- `mkdir build`\n- `cd build`\n- `cmake ..`\n- `make -j$(nproc)`\n\n### 运行可执行文件\n- 导航到构建目录\n- 运行可执行文件，并提供您的 ONNX 模型路径。\n- 例如：`.\u002Frun_inference_benchmark --onnx_model ..\u002Fmodels\u002Fyolov8n.onnx`\n  - 注意：有关如何获取 yolo8n 模型的说明，请参阅下方的“健康检查”部分。\n- 首次针对特定模型和选项运行可执行文件时，将根据您的 ONNX 模型构建一个 TensorRT 引擎文件。此过程相对较慢，某些模型（如 YOLO 模型）可能需要 5 分钟以上。\n- 或者，您也可以直接提供自己的 TensorRT 引擎文件：\n  - 例如：`.\u002Frun_inference_benchmark --trt_model ..\u002Fmodels\u002Fyolov8n.engine.NVIDIAGeForceRTX3080LaptopGPU.fp16.1.1`\n  - 注意：有关提供自定义 TensorRT 引擎文件时的注意事项，请参阅下方的 V5.0 更改日志。\n\n### 健康检查\n- 要进行健康检查，可从 [这里](https:\u002F\u002Fgithub.com\u002Fultralytics\u002Fultralytics#models) 下载 `YOLOv8n` 模型。\n- 接下来，使用以下脚本将其从 PyTorch 转换为 ONNX：\n  - 您需要先运行 `pip3 install ultralytics`。\n     \n```python\nfrom ultralytics import YOLO\nmodel = YOLO(\".\u002Fyolov8n.pt\")\nmodel.fuse()\nmodel.info(verbose=False)  # 打印模型信息\nmodel.export(format=\"onnx\", opset=12) # 使用 opset 12 将模型导出为 ONNX\n```\n\n- 将生成的 ONNX 模型 `yolov8n.onnx` 放入 `.\u002Fmodels\u002F` 目录中。\n- 使用该模型和位于 `.\u002Finputs\u002Fteam.jpg` 的图像进行推理，应产生以下特征向量：\n  - 注意：由于 [TensorRT 不是确定性的](https:\u002F\u002Fdocs.nvidia.com\u002Fdeeplearning\u002Ftensorrt\u002Fdeveloper-guide\u002Findex.html#determinism)，因此特征向量不会完全相同，但会非常相似。\n```text\n3.41113 16.5312 20.8828 29.8984 43.7266 54.9609 62.0625 65.8594 70.0312 72.9531 ...\n```\n\n### INT8 推理\n启用 INT8 精度可以在牺牲一定精度（由于动态范围减小）的情况下进一步加速推理。对于 INT8 精度，用户必须提供能够代表模型实际输入数据的校准数据。建议使用 1000 张以上的校准图像。要使用 YoloV8 检查模型启用 INT8 推理，需执行以下步骤：\n- 在 `main.cpp` 中将 `options.precision = Precision::FP16;` 改为 `options.precision = Precision::INT8;`。\n- 必须在 `main.cpp` 中修改 `options.calibrationDataDirectoryPath = \"\";`，以指定包含校准数据的路径。\n  - 如果使用 YoloV8 模型，建议使用 COCO 验证数据集，可通过 `wget http:\u002F\u002Fimages.cocodataset.org\u002Fzips\u002Fval2017.zip` 下载。\n- 确保 `engine.cpp` 中 `Int8EntropyCalibrator2::getBatch` 方法中的调整大小代码（见 `TODO`）适用于您的模型。\n  - 如果使用 YoloV8 模型，预处理代码是正确的，无需更改。\n- 重新编译并运行可执行文件。\n- 校准缓存将被写入磁盘（`.calibration` 扩展名），以便在后续模型优化中重复使用。如果希望重新生成校准数据，则必须删除此缓存文件。\n- 如果出现“函数 allocate 内存不足”的错误，则需要降低 `Options.calibrationBatchSize` 的值，以确保整个批次能够容纳在 GPU 内存中。\n\n### 基准测试\n基准测试在 RTX 3050 Ti 笔记本 GPU 和第 11 代 Intel(R) Core(TM) i9-11900H @ 2.50GHz 处理器上运行。\n\n| 模型   | 精度 | 批量大小 | 平均推理时间 |\n|---------|-----------|------------|--------------------|\n| yolov8n | FP32      | 1          | 4.732 ms           |\n| yolov8n | FP16      | 1          | 2.493 ms           |\n| yolov8n | INT8      | 1          | 2.009 ms           |\n| yolov8x | FP32      | 1          | 76.63 ms           |\n| yolov8x | FP16      | 1          | 25.08 ms           |\n| yolov8x | INT8      | 1          | 11.62 ms           |\n\n### 示例集成\n想知道如何将此库集成到您的项目中吗？或者如何读取 YoloV8 模型的输出以提取有意义的信息？如果是这样，请查看我的两个最新项目：[YOLOv8-TensorRT-CPP](https:\u002F\u002Fgithub.com\u002Fcyrusbehr\u002FYOLOv8-TensorRT-CPP) 和 [YOLOv9-TensorRT-CPP](https:\u002F\u002Fgithub.com\u002Fcyrusbehr\u002FYOLOv9-TensorRT-CPP)，它们演示了如何使用 TensorRT C++ API 运行 YoloV8\u002F9 推理（支持目标检测、语义分割和人体姿态估计）。这些项目在后端都使用了本项目！\n\n### 项目结构\n```sh\nproject-root\u002F\n├── include\u002F\n│   ├── engine\u002F\n│   │   ├── EngineRunInference.inl\n│   │   ├── EngineUtilities.inl\n│   │   └── EngineBuildLoadNetwork.inl\n│   ├── util\u002F...\n│   ├── ...\n├── src\u002F\n|   ├── ...\n│   ├── engine.cpp\n│   ├── engine.h\n│   └── main.cpp\n├── CMakeLists.txt\n└── README.md\n```\n\n### 理解代码\n- 大部分实现位于 `include\u002Fengine` 目录中。我在代码中添加了大量的注释，应该能帮助您轻松理解代码的工作原理。\n- 推理代码位于 `include\u002Fengine\u002FEngineRunInference.inl`。\n- 构建和加载 TensorRT 引擎文件的代码位于 `include\u002Fengine\u002FEngineBuildLoadNetwork.inl`。\n- 您也可以观看我的[深度解析视频](https:\u002F\u002Fyoutu.be\u002FZ0n5aLmcRHQ)，其中我逐行解释了所有代码。\n\n### 调试方法\n- 实现中使用了 `spdlog` 库进行日志记录。可以通过设置环境变量 `LOG_LEVEL` 为以下值之一来更改日志级别：`trace`、`debug`、`info`、`warn`、`error`、`critical` 或 `off`。\n- 如果在从 ONNX 模型创建 TensorRT 引擎文件时遇到问题，可以尝试将环境变量 `LOG_LEVEL` 设置为 `trace` 并重新运行应用程序。这将为您提供有关构建过程具体失败位置的更多信息。\n\n### 表达感谢\n如果这个项目对您有所帮助，欢迎您给它点个赞。这将鼓励我保持项目的更新，并快速解决遇到的问题。如果您需要更具体的帮助，我也提供咨询服务。欢迎通过 [LinkedIn](https:\u002F\u002Fwww.linkedin.com\u002Fin\u002Fcyrus-behroozi\u002F) 与我联系。\n\n### 贡献者\n\n\u003C!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->\n\u003C!-- prettier-ignore-start -->\n\u003C!-- markdownlint-disable -->\n\u003Ctable>\n  \u003Ctbody>\n    \u003Ctr>\n      \u003Ctd align=\"center\" valign=\"top\" width=\"14.28%\">\u003Ca href=\"https:\u002F\u002Fltetrel.github.io\u002F\">\u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fcyrusbehr_tensorrt-cpp-api_readme_a29092047009.png\" width=\"100px;\" alt=\"Loic Tetrel\"\u002F>\u003Cbr \u002F>\u003Csub>\u003Cb>Loic Tetrel\u003C\u002Fb>\u003C\u002Fsub>\u003C\u002Fa>\u003Cbr \u002F>\u003Ca href=\"https:\u002F\u002Fgithub.com\u002Fcyrusbehr\u002Ftensorrt-cpp-api\u002Fcommits?author=ltetrel\" title=\"Code\">💻\u003C\u002Fa>\u003C\u002Ftd>\n      \u003Ctd align=\"center\" valign=\"top\" width=\"14.28%\">\u003Ca href=\"https:\u002F\u002Fgithub.com\u002Fthomaskleiven\">\u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fcyrusbehr_tensorrt-cpp-api_readme_3adf31448ad5.png\" width=\"100px;\" alt=\"thomaskleiven\"\u002F>\u003Cbr \u002F>\u003Csub>\u003Cb>thomaskleiven\u003C\u002Fb>\u003C\u002Fsub>\u003C\u002Fa>\u003Cbr \u002F>\u003Ca href=\"https:\u002F\u002Fgithub.com\u002Fcyrusbehr\u002Ftensorrt-cpp-api\u002Fcommits?author=thomaskleiven\" title=\"Code\">💻\u003C\u002Fa>\u003C\u002Ftd>\n      \u003Ctd align=\"center\" valign=\"top\" width=\"14.28%\">\u003Ca href=\"https:\u002F\u002Fgithub.com\u002Fqq978358810\">\u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fcyrusbehr_tensorrt-cpp-api_readme_ef7bcf38b9cc.png\" width=\"100px;\" alt=\"WiCyn\"\u002F>\u003Cbr \u002F>\u003Csub>\u003Cb>WiCyn\u003C\u002Fb>\u003C\u002Fsub>\u003C\u002Fa>\u003Cbr \u002F>\u003Ca href=\"https:\u002F\u002Fgithub.com\u002Fcyrusbehr\u002Ftensorrt-cpp-api\u002Fcommits?author=qq978358810\" title=\"Code\">💻\u003C\u002Fa>\u003C\u002Ftd>\n    \u003C\u002Ftr>\n  \u003C\u002Ftbody>\n\u003C\u002Ftable>\n\n\u003C!-- markdownlint-restore -->\n\u003C!-- prettier-ignore-end -->\n\n\u003C!-- ALL-CONTRIBUTORS-LIST:END -->\n\n### 更改日志\n\n**V6.0**\n\n- 现在实现要求 TensorRT >= 10.0。\n\n**V5.0**\n\n- `Engine` 类已修改为接受一个模板参数，用于指定模型的输出数据类型。现在支持 `float`、`__half`、`int8_t`、`int32_t`、`bool` 和 `uint8_t` 类型的输出。\n- 增加了直接加载 TensorRT 引擎文件的支持，无需从 ONNX 模型编译。然而，强烈建议使用提供的 API 从 ONNX 模型构建引擎文件，而不是直接加载 TensorRT 模型。如果选择直接加载 TensorRT 模型文件，必须手动检查 `Options` 是否已正确设置（例如，如果您的模型是为 FP32 编译的，但您尝试运行 FP16 推理，则会失败，且可能不会给出详细的错误信息）。\n- 添加了命令行解析器。\n\n**V4.1**\n\n- 增加了对固定批大小 > 1 的支持。\n\n**V4.0**\n\n- 增加了对 INT8 精度的支持。\n\n**V3.0**\n\n- 实现已更新为使用 TensorRT 8.6 API（例如 `IExecutionContext::enqueueV3()`）。\n- 可执行文件已从 `driver` 重命名为 `run_inference_benchmark`，现在必须通过命令行参数传递 ONNX 模型路径。\n- 移除了 `Options.doesSupportDynamicBatchSize`。实现现在会自动检测支持的批大小。\n- 移除了 `Options.maxWorkspaceSize`。实现现在在模型构建过程中不限制 GPU 内存，允许使用尽可能多的内存池来存储中间层数据。\n\n**v2.2**\n\n- 将模型名称序列化为引擎文件的一部分。\n\n**V2.1**\n\n- 增加了对多输入模型的支持。现在支持单输入、多输入、单输出、多输出以及批处理的模型。\n\n**V2.0**\n\n- 需要安装 OpenCV CUDA。安装方法请参考 [这里](https:\u002F\u002Fgist.github.com\u002Fraulqf\u002Ff42c718a658cddc16f9df07ecc627be7)。\n- 移除了 `Options.optBatchSizes`，替换为 `Options.optBatchSize`。\n- 支持具有多个输出的模型（例如 SCRFD）。\n- 增加了对不支持批处理推理的模型的支持（第一维输入固定）。\n- 增加了更多的错误检查。\n- 修复了用户在原始 V1.0 版本中经常遇到的一些常见问题。\n- 移除了 GPU 设备名称中的空格。\n\n\u003C!-- MARKDOWN LINKS & IMAGES -->\n\u003C!-- https:\u002F\u002Fwww.markdownguide.org\u002Fbasic-syntax\u002F#reference-style-links -->\n[stars-shield]: https:\u002F\u002Fimg.shields.io\u002Fgithub\u002Fstars\u002Fcyrusbehr\u002Ftensorrt-cpp-api.svg?style=flat-square\n[stars-url]: https:\u002F\u002Fgithub.com\u002Fcyrusbehr\u002Ftensorrt-cpp-api\u002Fstargazers\n[issues-shield]: https:\u002F\u002Fimg.shields.io\u002Fgithub\u002Fissues\u002Fcyrusbehr\u002Ftensorrt-cpp-api.svg?style=flat-square\n[issues-url]: https:\u002F\u002Fgithub.com\u002Fcyrusbehr\u002Ftensorrt-cpp-api\u002Fissues\n[linkedin-shield]: https:\u002F\u002Fimg.shields.io\u002Fbadge\u002F-LinkedIn-black.svg?style=flat-square&logo=linkedin&colorB=555\n[linkedin-url]: https:\u002F\u002Flinkedin.com\u002Fin\u002Fcyrus-behroozi\u002F\n\n## 贡献者 ✨\n\n感谢以下各位优秀的贡献者（[emoji key](https:\u002F\u002Fallcontributors.org\u002Fdocs\u002Fen\u002Femoji-key))：\n\n\u003C!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->\n\u003C!-- prettier-ignore-start -->\n\u003C!-- markdownlint-disable -->\n\u003C!-- markdownlint-restore -->\n\u003C!-- prettier-ignore-end -->\n\u003C!-- ALL-CONTRIBUTORS-LIST:END -->\n\n本项目遵循 [all-contributors](https:\u002F\u002Fgithub.com\u002Fall-contributors\u002Fall-contributors) 规范。欢迎任何形式的贡献！","# TensorRT C++ API 快速上手指南\n\n本指南基于 `tensorrt-cpp-api` 项目，帮助开发者在 Ubuntu 系统上快速构建并使用 TensorRT C++ API 进行高性能 GPU 推理。\n\n## 环境准备\n\n### 系统要求\n- **操作系统**: Ubuntu 20.04 或 22.04 (暂不支持 Windows)\n- **GPU**: 支持 CUDA 的 NVIDIA 显卡\n\n### 前置依赖\n请确保安装以下组件（版本要求严格，请勿随意更改）：\n\n1. **CUDA Toolkit**: 推荐 >= 12.0 (最低 11.0)\n   - 下载地址：[NVIDIA CUDA Downloads](https:\u002F\u002Fdeveloper.nvidia.com\u002Fcuda-downloads)\n2. **cuDNN**: 8.x 版本 (必须 \u003C 9.0，因 OpenCV GPU 支持限制)\n   - 下载地址：[NVIDIA cuDNN](https:\u002F\u002Fdocs.nvidia.com\u002Fdeeplearning\u002Fcudnn\u002Finstall-guide\u002Findex.html#download)\n3. **基础编译工具**:\n   ```bash\n   sudo apt install build-essential\n   sudo snap install cmake --classic\n   sudo apt install libspdlog-dev libfmt-dev\n   ```\n4. **OpenCV (带 CUDA 支持)**:\n   - 推荐版本 >= 4.8\n   - 建议使用项目提供的脚本编译源码以启用 CUDA：\n     ```bash\n     # 进入项目 scripts 目录运行\n     .\u002Fscripts\u002Fbuild_opencv.sh\n     ```\n   - *注意*: 若 cuDNN 安装在非标准路径，需修改脚本中的 `CUDNN_INCLUDE_DIR` 和 `CUDNN_LIBRARY` 变量。\n5. **TensorRT**:\n   - 必须版本 >= 10.0\n   - 下载地址：[NVIDIA TensorRT 10](https:\u002F\u002Fdeveloper.nvidia.com\u002Ftensorrt\u002Fdownload\u002F10x)\n   - 下载后解压，并记录安装路径。\n\n## 安装步骤\n\n### 1. 配置项目\n克隆项目代码后，打开根目录下的 `CMakeLists.txt` 文件，找到 `TODO` 占位符，将其替换为你本地的 TensorRT 安装路径。\n\n### 2. 编译库与可执行文件\n在项目根目录执行以下命令：\n\n```bash\nmkdir build\ncd build\ncmake ..\nmake -j$(nproc)\n```\n\n### 3. 准备测试模型 (Sanity Check)\n若没有自己的 ONNX 模型，可使用 YOLOv8n 进行测试：\n\n1. 安装 ultralytics:\n   ```bash\n   pip3 install ultralytics\n   ```\n2. 转换模型为 ONNX (Python 脚本):\n   ```python\n   from ultralytics import YOLO\n   model = YOLO(\".\u002Fyolov8n.pt\")\n   model.fuse()\n   model.info(verbose=False)\n   model.export(format=\"onnx\", opset=12)\n   ```\n3. 将生成的 `yolov8n.onnx` 放入项目的 `.\u002Fmodels\u002F` 目录。\n4. 确保 `.\u002Finputs\u002F` 目录下有一张测试图片（如 `team.jpg`）。\n\n## 基本使用\n\n### 运行推理\n进入 `build` 目录，执行以下命令加载 ONNX 模型并自动构建 TensorRT 引擎：\n\n```bash\n.\u002Frun_inference_benchmark --onnx_model ..\u002Fmodels\u002Fyolov8n.onnx\n```\n\n*说明：首次运行时会自动从 ONNX 构建 `.engine` 文件，耗时约 5 分钟以上，后续运行将直接加载引擎文件。*\n\n### 指定精度 (可选)\n默认使用 FP16。若需测试 INT8 加速：\n1. 修改 `src\u002Fmain.cpp`：\n   - 将 `options.precision = Precision::FP16;` 改为 `Precision::INT8;`\n   - 设置 `options.calibrationDataDirectoryPath` 为校准数据目录（如 COCO val2017 数据集）。\n2. 重新编译并运行。\n\n### 调试模式\n若构建失败，可通过设置环境变量获取详细日志：\n```bash\nexport LOG_LEVEL=trace\n.\u002Frun_inference_benchmark --onnx_model ..\u002Fmodels\u002Fyolov8n.onnx\n```","某自动驾驶团队需要在嵌入式 Jetson 设备上实时运行 YOLOv8 模型，以毫秒级延迟检测前方车辆与行人。\n\n### 没有 tensorrt-cpp-api 时\n- 开发者被迫依赖 Python 推理脚本，受限于 GIL 锁和解释器开销，帧率难以突破 30 FPS，无法满足高速场景需求。\n- 面对官方晦涩的 C++ 文档，团队需耗费数周手动管理 CUDA 流、显存分配及异步同步逻辑，代码极易出错且难以维护。\n- 难以灵活配置 FP16 或 INT8 量化策略，导致模型体积过大，无法在资源受限的边缘设备上部署。\n- 处理多输入或多输出模型时，数据预处理与后处理逻辑耦合严重，每次调整网络结构都需重构大量底层代码。\n\n### 使用 tensorrt-cpp-api 后\n- 基于该工具提供的成熟 C++ 模板，团队直接构建高性能推理引擎，将检测延迟降低至 15ms 以内，帧率提升至 60+ FPS。\n- 复用其封装好的 CUDA 流管理与显存操作模块，无需重复造轮子，三天内即可完成从模型转换到端侧部署的全流程。\n- 通过简单的配置文件即可切换 FP32\u002FFP16\u002FINT8 精度，在几乎不损失精度的前提下，将显存占用减少 50%。\n- 借助其对动态 Batch 及多输入输出的原生支持，轻松适配复杂的多任务感知网络，后续迭代开发效率提升 3 倍。\n\ntensorrt-cpp-api 通过屏蔽底层复杂的 GPU 编程细节，让开发者能专注于业务逻辑，真正实现高性能模型在边缘端的落地。","https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fcyrusbehr_tensorrt-cpp-api_e3e3ef34.png","cyrusbehr","Cyrus Behroozi","https:\u002F\u002Foss.gittoolsai.com\u002Favatars\u002Fcyrusbehr_f898bf6a.png","The code... it speaks to me ","Trueface","California",null,"cyrusbehr.com","https:\u002F\u002Fgithub.com\u002Fcyrusbehr",[82,86,90,94],{"name":83,"color":84,"percentage":85},"C++","#f34b7d",90.1,{"name":87,"color":88,"percentage":89},"CMake","#DA3434",6.8,{"name":91,"color":92,"percentage":93},"Shell","#89e051",1.8,{"name":95,"color":96,"percentage":97},"C","#555555",1.4,798,104,"2026-04-05T15:39:41","MIT",4,"Linux (Ubuntu 20.04, 22.04)","必需 NVIDIA GPU，支持 CUDA 11.0+ (推荐 >=12.0)，需安装 cuDNN (>=8, \u003C9)，显存大小取决于模型和批处理大小（INT8 校准若报错需减小 batch size 以适应显存）","未说明",{"notes":107,"python":108,"dependencies":109},"目前不支持 Windows；首次运行会由 ONNX 模型构建 TensorRT 引擎文件，耗时较长（可能超过 5 分钟）；若使用 INT8 精度，需提供至少 1000 张代表性校准图片；若遇到显存不足错误，需减小校准批处理大小；项目主要作为 C++ API 教程，实际集成可参考作者其他的 YOLOv8\u002Fv9 项目。","未说明 (仅用于模型转换脚本，推理核心为 C++)",[110,111,112,113,87,114,115,116],"TensorRT >= 10.0","CUDA >= 11.0 (推荐 >= 12.0)","cuDNN >= 8.0 (\u003C 9.0)","OpenCV >= 4.8 (需编译开启 CUDA 支持)","build-essential","libspdlog-dev","libfmt-dev",[15,14],[119,120,121,122,123],"computer-vision","cpp","inference","machine-learning","tensorrt","2026-03-27T02:49:30.150509","2026-04-18T00:38:02.157736",[127,132,137,142,147,152],{"id":128,"question_zh":129,"answer_zh":130,"source_url":131},38011,"编译时出现 'NvInfer.h: No such file or directory' 错误怎么办？","这通常是因为编译器找不到 TensorRT 的头文件路径。虽然 NvInfer.h 存在于您的安装目录（如 \u002Fhome\u002Fubuntu\u002FTensorRT-8.6.1.6\u002Finclude），但需要确保构建系统能定位到它。如果是直接编译，需添加 -I 参数指定包含路径。此外，如果遇到关于 CUDA lazy loading 的警告或相关版本问题，请尝试导出环境变量或调整详细级别重新编译。确保您的 TensorRT 和 CUDA 版本匹配，并参考项目的调试指南获取完整输出以进一步排查。","https:\u002F\u002Fgithub.com\u002Fcyrusbehr\u002Ftensorrt-cpp-api\u002Fissues\u002F14",{"id":133,"question_zh":134,"answer_zh":135,"source_url":136},38012,"编译时报错 'Cuda declarations were not declared in this scope' 如何解决？","此错误通常是因为缺少 CUDA 运行时头文件的包含声明。解决方案如下：\n1. 在 engine.h 文件中显式添加 #include \u003Ccuda_runtime.h>。\n2. 检查您的 CMakeLists.txt，确保 CUDA 库和头文件的路径配置正确（不同设备的安装路径可能不同）。\n3. 如果使用的是较旧的 CUDA 版本（如 10.2），尝试升级到 CUDA 11 或在 Docker 容器中测试，因为新版本兼容性更好。\n4. 确保 TensorRT 版本与 CUDA 版本相匹配。","https:\u002F\u002Fgithub.com\u002Fcyrusbehr\u002Ftensorrt-cpp-api\u002Fissues\u002F24",{"id":138,"question_zh":139,"answer_zh":140,"source_url":141},38013,"如何在项目中加载和使用自定义 TensorRT 插件（Plugin Layers）？","如果您的 ONNX 模型包含自定义插件层（如 TRTBatchedNMS），在反序列化引擎时会因找不到插件创建器而报错。解决方法有两种：\n1. 推荐方法：使用 dlopen() 动态加载插件的 .so 文件。例如：\n   void* pluginHandle = dlopen(\"path\u002Fto\u002Flibmmdeploy_tensorrt_ops.so\", RTLD_LAZY);\n   如果加载失败，使用 dlerror() 查看具体错误。\n2. 尝试方法：在初始化引擎前调用 initLibNvInferPlugins()，并通过 setenv(\"LD_LIBRARY_PATH\", \"path\u002Fto\u002Fplugin\u002Ffolder\", 1) 设置环境变量指向插件所在目录。注意，内置插件通常已自动加载，此方法主要针对额外插件。","https:\u002F\u002Fgithub.com\u002Fcyrusbehr\u002Ftensorrt-cpp-api\u002Fissues\u002F88",{"id":143,"question_zh":144,"answer_zh":145,"source_url":146},38014,"设置 Batch Size 大于 1 时出现 'Error, not all required dimensions specified' 错误怎么办？","当自定义模型（如基于 YoloV8 的 HypNet）在 TensorRT 中设置 optBatchSize 和 maxBatchSize 大于 1 时报错，通常是因为模型输入维度未正确配置为动态批次。维护者建议创建一个支持动态批次大小的分支（如 i-80 分支）用于调试。请检查 ONNX 模型的输入节点是否标记为动态轴（dynamic axes），并确保在构建 Engine 时 Options 配置正确。如果问题依旧，可能需要调整预处理逻辑中图像重塑（reshape）的方式以适配批量输入。","https:\u002F\u002Fgithub.com\u002Fcyrusbehr\u002Ftensorrt-cpp-api\u002Fissues\u002F80",{"id":148,"question_zh":149,"answer_zh":150,"source_url":151},38015,"该项目是否支持 Windows 平台？如何配置？","是的，该项目支持 Windows 平台。用户已成功在以下环境中编译和运行：\n- Visual Studio 2017\u002F2022\n- C++ 11\n- CUDA 11.8\n- cuDNN 8.8.1.3\n- OpenCV 4.7.0\n- TensorRT 8.6.1.6\n为了更方便地集成，社区成员计划修改 CMakeLists.txt 以增强跨平台支持。目前语义分割任务在使用 INT8 精度时可能存在已知问题，建议优先测试对象检测任务或使用 FP16\u002FFP32 精度。","https:\u002F\u002Fgithub.com\u002Fcyrusbehr\u002Ftensorrt-cpp-api\u002Fissues\u002F18",{"id":153,"question_zh":154,"answer_zh":155,"source_url":146},38016,"遇到特征向量维度不正确（The feature vector has incorrect dimensions!）的错误如何处理？","该错误通常发生在推理输出阶段，表明模型输出的张量维度与代码预期的不一致（例如期望 -1 x 6 x 1 x 1280 但实际不符）。这往往与 Batch Size 设置不当或模型输入\u002F输出定义不匹配有关。请检查：\n1. 构建 Engine 时的 optBatchSize 和 maxBatchSize 设置是否与推理时的输入批次一致。\n2. 预处理步骤中图像的尺寸重塑（reshape）是否正确。\n3. 如果是自定义模型，确认 ONNX 导出时的输出节点维度定义。建议启用动态批次大小支持并进行调试。",[]]