跳至内容

Export to TF.js Model Format From a YOLO11 Model Format

Deploying machine learning models directly in the browser or on Node.js can be tricky. You'll need to make sure your model format is optimized for faster performance so that the model can be used to run interactive applications locally on the user's device. The TensorFlow.js, or TF.js, model format is designed to use minimal power while delivering fast performance.

The 'export to TF.js model format' feature allows you to optimize your Ultralytics YOLO11 models for high-speed and locally-run object detection inference. In this guide, we'll walk you through converting your models to the TF.js format, making it easier for your models to perform well on various local browsers and Node.js applications.

为什么要导出到TF.js?

将机器学习模型导出到TensorFlow.js(由TensorFlow 团队开发,是更广泛的TensorFlow 生态系统的一部分)为部署机器学习应用提供了众多优势。它将敏感数据保存在设备上,有助于提高用户隐私和安全性。下图显示了TensorFlow.js 架构,以及机器学习模型如何在网络浏览器和 Node.js 上转换和部署。

TF.js 架构

Running models locally also reduces latency and provides a more responsive user experience. TensorFlow.js also comes with offline capabilities, allowing users to use your application even without an internet connection. TF.js is designed for efficient execution of complex models on devices with limited resources as it is engineered for scalability, with GPU acceleration support.

TF.js 的主要功能

以下是使TF.js 成为开发人员强大工具的主要功能:

  • 跨平台支持: TensorFlow.js 可在浏览器和 Node.js 环境中使用,提供了跨平台部署的灵活性。它能让开发人员更轻松地构建和部署应用程序。

  • 支持多种后端: TensorFlow.js 支持多种计算后端,包括CPU 、用于GPU 加速的 WebGL、用于接近本地执行速度的 WebAssembly (WASM) 以及用于基于浏览器的高级机器学习功能的 WebGPU。

  • 离线功能:通过TensorFlow.js,模型可以在浏览器中运行,无需互联网连接,从而使离线开发应用程序成为可能。

TensorFlow.js 的部署选项

Before we dive into the process of exporting YOLO11 models to the TF.js format, let's explore some typical deployment scenarios where this format is used.

TF.js 提供了一系列部署机器学习模型的选项:

  • 浏览器内的 ML 应用程序:您可以构建直接在浏览器中运行机器学习模型的网络应用程序。这样就不需要服务器端计算,也减轻了服务器负载。

  • Node.js 应用程序 TensorFlow.js 还支持在 Node.js 环境中部署,从而能够开发服务器端机器学习应用程序。它对于需要服务器处理能力或访问服务器端数据的应用程序尤其有用。

  • Chrome 浏览器扩展:一个有趣的部署场景是使用TensorFlow.js 创建 Chrome 浏览器扩展。例如,您可以开发一个扩展,允许用户右键单击任何网页中的图片,使用预先训练好的 ML 模型对其进行分类。TensorFlow.js 可以集成到日常网页浏览体验中,提供基于机器学习的即时见解或增强功能。

Exporting YOLO11 Models to TensorFlow.js

You can expand model compatibility and deployment flexibility by converting YOLO11 models to TF.js.

安装

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

安装

# 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.js format
model.export(format="tfjs")  # creates '/yolo11n_web_model'

# Load the exported TF.js model
tfjs_model = YOLO("./yolo11n_web_model")

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

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

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

Deploying Exported YOLO11 TensorFlow.js Models

Now that you have exported your YOLO11 model to the TF.js format, the next step is to deploy it. The primary and recommended first step for running a TF.js is to use the YOLO("./yolo11n_web_model") method, as previously shown in the usage code snippet.

不过,有关部署TF.js 模型的深入说明,请参阅以下资源:

摘要

In this guide, we learned how to export Ultralytics YOLO11 models to the TensorFlow.js format. By exporting to TF.js, you gain the flexibility to optimize, deploy, and scale your YOLO11 models on a wide range of platforms.

有关使用的详细信息,请访问TensorFlow.js 官方文档

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

常见问题

How do I export Ultralytics YOLO11 models to TensorFlow.js format?

Exporting Ultralytics YOLO11 models to TensorFlow.js (TF.js) format is straightforward. You can follow these steps:

使用方法

from ultralytics import YOLO

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

# Export the model to TF.js format
model.export(format="tfjs")  # creates '/yolo11n_web_model'

# Load the exported TF.js model
tfjs_model = YOLO("./yolo11n_web_model")

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

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

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

Why should I export my YOLO11 models to TensorFlow.js?

Exporting YOLO11 models to TensorFlow.js offers several advantages, including:

  1. 本地执行:模型可直接在浏览器或 Node.js 中运行,从而减少延迟并增强用户体验。
  2. 跨平台支持: TF.js 支持多种环境,可灵活部署。
  3. 脱机功能:使应用程序能够在没有互联网连接的情况下运行,确保可靠性和私密性。
  4. GPU 加速:利用 WebGL 实现GPU 加速,优化资源有限设备的性能。

有关全面概述,请参阅我们的集成TensorFlow.js

TensorFlow.js 如何使基于浏览器的机器学习应用受益?

TensorFlow.js 专为在浏览器和 Node.js 环境中高效执行 ML 模型而设计。以下是它如何为基于浏览器的应用带来益处:

  • 减少延迟:在本地运行机器学习模型,无需依赖服务器端计算,即可提供即时结果。
  • 改善隐私:将敏感数据保存在用户设备上,将安全风险降至最低。
  • 可离线使用:机型可以在没有互联网连接的情况下运行,确保功能的一致性。
  • 支持多种后端:可灵活使用CPU 、WebGL、WebAssembly (WASM) 和 WebGPU 等后端,满足不同的计算需求。

有兴趣了解有关TF.js 的更多信息?请查看 TensorFlow.js 官方指南

What are the key features of TensorFlow.js for deploying YOLO11 models?

TensorFlow.js 的主要功能包括

  • 跨平台支持: TF.js 可在网络浏览器和 Node.js 中使用,提供广泛的部署灵活性。
  • 多种后端:支持CPU 、用于GPU 加速的 WebGL、WebAssembly (WASM) 和用于高级操作的 WebGPU。
  • 离线功能:模型可直接在浏览器中运行,无需连接互联网,因此非常适合开发响应式网络应用程序。

有关部署方案和更深入的信息,请参阅我们的 TensorFlow.js 部署选项部分。

Can I deploy a YOLO11 model on server-side Node.js applications using TensorFlow.js?

Yes, TensorFlow.js allows the deployment of YOLO11 models on Node.js environments. This enables server-side machine learning applications that benefit from the processing power of a server and access to server-side data. Typical use cases include real-time data processing and machine learning pipelines on backend servers.

要开始部署 Node.js,请参阅TensorFlow在 Node.js 中运行TensorFlow.js指南。

📅 Created 6 months ago ✏️ Updated 20 days ago

评论