Inference Engine
发现推理引擎如何优化像 Ultralytics YOLO26 这样的机器学习模型以实现实时部署。立即探索边缘 AI 的性能提升技巧。
An inference engine is a specialized software component designed to execute trained machine learning models and generate predictions from new data. Unlike the training phase, which focuses on learning patterns through computationally intensive processes like backpropagation, an inference engine is strictly optimized for the operational phase known as model deployment. Its primary goal is to run computations as efficiently as possible, minimizing inference latency and maximizing throughput on target hardware, whether that be a scalable cloud server or a battery-powered Edge AI device. By stripping away the overhead required for training, these engines allow complex neural networks to function in real-time applications.
Link to this section推理引擎如何优化性能#
从训练环境到推理引擎的转换通常涉及几个优化步骤,以简化模型结构。由于模型不再需要学习,引擎可以丢弃梯度更新所需的数据,从而有效地冻结 model weights。推理引擎使用的常用技术包括层融合(layer fusion),即将多个操作合并为一个步骤以减少内存访问,以及 model quantization,它将权重从高精度浮点格式转换为低精度整数(例如 INT8)。
这些优化使得像 Ultralytics YOLO26 这样的高级架构能够在不显著损失 accuracy 的情况下以极高的速度运行。不同的引擎通常针对特定的硬件生态系统进行定制,以释放最大性能:
- NVIDIA TensorRT:通过利用特定于硬件的内核并优化网络图,在 NVIDIA GPUs 上提供高性能推理。
- Intel OpenVINO: Optimizes deep learning performance on Intel architectures, including CPUs and integrated graphics, making it ideal for edge computing.
- ONNX Runtime:一种跨平台加速器,支持 ONNX 格式的模型,为不同框架和硬件后端之间架起了桥梁。
Link to this section实际应用#
推理引擎是许多现代 AI 便利功能背后的隐形驱动力,使 computer vision 系统能够即时响应周围环境。
-
自动驾驶汽车:在自动驾驶汽车中,object detection 模型必须在毫秒内识别行人、交通标志和其他车辆。在汽车硬件上本地运行的推理引擎可确保此处理以 real-time inference 速度进行,因为依赖云连接会引入危险的延迟。
-
智能制造:工厂利用 industrial IoT 摄像头检查装配线上的产品。推理引擎处理视频流以执行 anomaly detection,从而即时标记缺陷。这种自动化减少了浪费并确保了严格的质量控制,同时不会减慢生产速度。
Link to this section推理引擎与训练框架对比#
区分用于创建模型的软件和用于运行它的引擎是很有帮助的。训练框架(如 PyTorch 或 TensorFlow)提供了用于设计架构、计算损失以及通过 supervised learning 更新参数的工具。它优先考虑灵活性和调试能力。
相比之下,推理引擎获取训练框架完成后的产物,并优先考虑执行速度和内存效率。虽然你可以在训练框架内运行推理,但它通常不如使用专用引擎高效,特别是在通过 TensorFlow Lite 或 Apple Core ML 等工具在手机或嵌入式设备上进行部署时。
Link to this section将推理引擎与 YOLO26 结合使用#
ultralytics 软件包抽象了推理引擎的大部分复杂性,允许用户无缝运行预测。在底层,它处理图像预处理和模型执行。对于寻求扩展的用户,Ultralytics Platform 简化了训练和导出模型的过程,使其导出为与各种推理引擎兼容的优化格式。
以下示例演示了如何加载预训练的 YOLO26 模型并在图像上运行推理:
from ultralytics import YOLO
# Load the YOLO26n model (nano version for speed)
model = YOLO("yolo26n.pt")
# Run inference on an image from a URL
# The 'predict' method acts as the interface to the inference process
results = model.predict("https://ultralytics.com/images/bus.jpg")
# Display the results
results[0].show()





