跳至内容

How to Export to TF GraphDef from YOLO11 for Deployment

When you are deploying cutting-edge computer vision models, like YOLO11, in different environments, you might run into compatibility issues. Google's TensorFlow GraphDef, or TF GraphDef, offers a solution by providing a serialized, platform-independent representation of your model. Using the TF GraphDef model format, you can deploy your YOLO11 model in environments where the complete TensorFlow ecosystem may not be available, such as mobile devices or specialized hardware.

In this guide, we'll walk you step by step through how to export your Ultralytics YOLO11 models to the TF GraphDef model format. By converting your model, you can streamline deployment and use YOLO11's computer vision capabilities in a broader range of applications and platforms.

TensorFlow GraphDef

为什么要导出到TF GraphDef ?

TF GraphDef is a powerful component of the TensorFlow ecosystem that was developed by Google. It can be used to optimize and deploy models like YOLO11. Exporting to TF GraphDef lets us move models from research to real-world applications. It allows models to run in environments without the full TensorFlow framework.

GraphDef 格式将模型表示为序列化计算图。这使得各种优化技术成为可能,如常数折叠、量化和图转换。这些优化可确保高效执行、减少内存使用和加快推理速度。

GraphDef models can use hardware accelerators such as GPUs, TPUs, and AI chips, unlocking significant performance gains for the YOLO11 inference pipeline. The TF GraphDef format creates a self-contained package with the model and its dependencies, simplifying deployment and integration into diverse systems.

TF GraphDef 型号的主要特点

TF GraphDef offers distinct features for streamlining model deployment and optimization.

下面来看看它的主要特点:

  • 模型序列化:TF GraphDef 提供了一种以独立于平台的格式序列化和存储TensorFlow 模型的方法。通过这种序列化表示,您可以在没有原始Python 代码库的情况下加载和执行模型,从而使部署变得更加容易。

  • 图形优化:TF GraphDef 可对计算图形进行优化。这些优化可以通过简化执行流程、减少冗余和调整操作以适应特定硬件来提高性能。

  • 部署灵活:导出为GraphDef 格式的模型可用于各种环境,包括资源受限的设备、网络浏览器和具有专用硬件的系统。这为更广泛地部署TensorFlow 模型提供了可能。

  • 生产重点:GraphDef 专为生产部署而设计。它支持高效执行、序列化功能以及与实际用例相一致的优化。

部署选项TF GraphDef

Before we dive into the process of exporting YOLO11 models to TF GraphDef, let's take a look at some typical deployment situations where this format is used.

下面介绍如何通过TF GraphDef 在各种平台上高效部署。

  • TensorFlow 服务:该框架设计用于在生产环境中部署TensorFlow 模型。TensorFlow Serving 提供模型管理、版本管理和基础架构,以实现大规模的高效模型服务。这是一种无缝方式,可将基于GraphDef 的模型集成到生产网络服务或 API 中。

  • 移动和嵌入式设备:利用TensorFlow Lite 等工具,您可以将TF GraphDef 模型转换为针对智能手机、平板电脑和各种嵌入式设备优化的格式。然后,您的模型可用于设备推理,在本地执行,通常可提高性能并提供离线功能。

  • Web Browsers: TensorFlow.js enables the deployment of TF GraphDef models directly within web browsers. It paves the way for real-time object detection applications running on the client side, using the capabilities of YOLO11 through JavaScript.

  • 专用硬件: TF GraphDef 与平台无关的特性使其可以使用定制硬件,如加速器和 TPU(Tensor Processing Units)。这些设备可以为计算密集型模型提供性能优势。

Exporting YOLO11 Models to TF GraphDef

You can convert your YOLO11 object detection model to the TF GraphDef format, which is compatible with various systems, to improve its performance across platforms.

安装

要安装所需的软件包,请运行

安装

# Install the required package for YOLO11
pip install ultralytics

For detailed instructions and best practices related to the installation process, check our Ultralytics Installation guide. While installing the required packages for YOLO11, if you encounter any difficulties, consult our Common Issues guide for solutions and tips.

使用方法

Before diving into the usage instructions, it's important to note that while all Ultralytics YOLO11 models are available for exporting, you can ensure that the model you select supports export functionality here.

使用方法

from ultralytics import YOLO

# Load the YOLO11 model
model = YOLO("yolo11n.pt")

# Export the model to TF GraphDef format
model.export(format="pb")  # creates 'yolo11n.pb'

# Load the exported TF GraphDef model
tf_graphdef_model = YOLO("yolo11n.pb")

# Run inference
results = tf_graphdef_model("https://ultralytics.com/images/bus.jpg")
# Export a YOLO11n PyTorch model to TF GraphDef format
yolo export model=yolo11n.pt format=pb  # creates 'yolo11n.pb'

# Run inference with the exported model
yolo predict model='yolo11n.pb' source='https://ultralytics.com/images/bus.jpg'

有关支持的导出选项的详细信息,请访问Ultralytics 部署选项文档页面

Deploying Exported YOLO11 TF GraphDef Models

Once you've exported your YOLO11 model to the TF GraphDef format, the next step is deployment. The primary and recommended first step for running a TF GraphDef model is to use the YOLO("model.pb") method, as previously shown in the usage code snippet.

不过,要了解有关部署TF GraphDef 模型的更多信息,请参阅以下资源:

  • TensorFlow Serving: A guide on TensorFlow Serving that teaches how to deploy and serve machine learning models efficiently in production environments.

  • TensorFlow 精简版:本页介绍如何使用TensorFlow Lite 将机器学习模型转换为针对设备上推理而优化的格式。

  • TensorFlow.js:模型转换指南,教您如何将TensorFlow 或 Keras 模型转换为TensorFlow.js 格式,以便在网络应用程序中使用。

摘要

In this guide, we explored how to export Ultralytics YOLO11 models to the TF GraphDef format. By doing this, you can flexibly deploy your optimized YOLO11 models in different environments.

有关使用的更多详情,请访问TF GraphDef 官方文档

For more information on integrating Ultralytics YOLO11 with other platforms and frameworks, don't forget to check out our integration guide page. It has great resources and insights to help you make the most of YOLO11 in your projects.

常见问题

How do I export a YOLO11 model to TF GraphDef format?

Ultralytics YOLO11 models can be exported to TensorFlow GraphDef (TF GraphDef) format seamlessly. This format provides a serialized, platform-independent representation of the model, ideal for deploying in varied environments like mobile and web. To export a YOLO11 model to TF GraphDef, follow these steps:

使用方法

from ultralytics import YOLO

# Load the YOLO11 model
model = YOLO("yolo11n.pt")

# Export the model to TF GraphDef format
model.export(format="pb")  # creates 'yolo11n.pb'

# Load the exported TF GraphDef model
tf_graphdef_model = YOLO("yolo11n.pb")

# Run inference
results = tf_graphdef_model("https://ultralytics.com/images/bus.jpg")
# Export a YOLO11n PyTorch model to TF GraphDef format
yolo export model="yolo11n.pt" format="pb"  # creates 'yolo11n.pb'

# Run inference with the exported model
yolo predict model="yolo11n.pb" source="https://ultralytics.com/images/bus.jpg"

有关不同导出选项的更多信息,请访问Ultralytics 有关模型导出的文档

What are the benefits of using TF GraphDef for YOLO11 model deployment?

Exporting YOLO11 models to the TF GraphDef format offers multiple advantages, including:

  1. 平台独立性:TF GraphDef 提供与平台无关的格式,允许在包括移动和网络浏览器在内的各种环境中部署模型。
  2. 优化:该格式可进行多种优化,如常数折叠、量化和图形转换,从而提高执行效率并减少内存使用量。
  3. 硬件加速:TF GraphDef 格式的模型可利用 GPU、TPU 和人工智能芯片等硬件加速器提高性能。

如需了解更多益处,请参阅我们文档中的TF GraphDef 部分

Why should I use Ultralytics YOLO11 over other object detection models?

Ultralytics YOLO11 offers numerous advantages compared to other models like YOLOv5 and YOLOv7. Some key benefits include:

  1. State-of-the-Art Performance: YOLO11 provides exceptional speed and accuracy for real-time object detection, segmentation, and classification.
  2. 易于使用:具有用户友好的应用程序接口,可用于模型训练、验证、预测和导出,使初学者和专家都能使用。
  3. 广泛的兼容性:支持多种导出格式,包括ONNX 、TensorRT 、CoreML 和TensorFlow ,提供多种部署选项。

Explore further details in our introduction to YOLO11.

How can I deploy a YOLO11 model on specialized hardware using TF GraphDef?

Once a YOLO11 model is exported to TF GraphDef format, you can deploy it across various specialized hardware platforms. Typical deployment scenarios include:

  • TensorFlow 服务:使用TensorFlow Serving 在生产环境中进行可扩展的模型部署。它支持模型管理和高效服务。
  • 移动设备:将TF GraphDef 模型转换为TensorFlow Lite,针对移动和嵌入式设备进行了优化,可实现设备上推理。
  • 网络浏览器:使用TensorFlow.js 部署模型,以便在网络应用程序中进行客户端推理。
  • 人工智能加速器:利用 TPU 和定制 AI 芯片进行加速推理。

详细信息请查看部署选项部分。

Where can I find solutions for common issues while exporting YOLO11 models?

For troubleshooting common issues with exporting YOLO11 models, Ultralytics provides comprehensive guides and resources. If you encounter problems during installation or model export, refer to:

These resources should help you resolve most issues related to YOLO11 model export and deployment.


📅创建于 6 个月前 ✏️已更新 8 天前

评论