Skip to Content
构建机器学习管道
book

构建机器学习管道

by Hannes Hapke, Catherine Nelson
May 2025
Intermediate to advanced
366 pages
4h 36m
Chinese
O'Reilly Media, Inc.
Content preview from 构建机器学习管道

第 10 章. 高级 TensorFlow 扩展

本作品已使用人工智能进行翻译。欢迎您提供反馈和意见:translation-feedback@oreilly.com

通过前面两章对模型部署的介绍,我们完成了对各个管道组件的概述。 在深入了解如何协调这些管道组件之前,我们想暂停一下,在本章中介绍一下 TFX 的高级概念。

利用我们迄今为止介绍的管道组件,我们可以为大多数问题创建机器学习管道。不过,有时我们需要构建自己的 TFX 组件或更复杂的管道图。因此,在本章中,我们将重点介绍如何构建自定义 TFX 组件。我们将以一个自定义摄取组件引入主题,该组件可直接为计算机视觉 ML 管道摄取图像。此外,我们还将介绍管道结构的高级概念:同时生成两个模型(例如,用于 TensorFlow Serving 和 TFLite 的部署),以及在管道工作流中添加人工审核员。

持续发展

在撰写本文时,,我们介绍的一些概念仍在开发中,因此可能会在未来进行更新。在编写本出版物的整个过程中,我们已尽力根据 TFX 功能的变化更新代码示例,所有示例均可在 TFX 0.22 版本上运行。TFX API 的更新可在TFX 文档中找到。

先进的管道概念

在本节中,我们将讨论另外三个概念,以推进管道设置。到目前为止,我们讨论过的所有流水线概念都包含一个入口和一个出口的线性图。在第 1 章中,我们讨论了有向无环图的基本原理。只要我们的流水线图是有向的,并且不产生任何循环连接,我们就可以创造性地进行设置。在接下来的章节中,我们将重点介绍一些概念,以提高流水线的工作效率:

  • 同时训练多个模型

  • 为移动部署导出模型

  • 热启动模型训练

同时训练多个模型

如前所述,您可以同时训练多个模型。 从同一管道训练多个模型的常见用例是,当您想训练不同类型的模型(例如更简单的模型),但又想确保训练的模型得到完全相同的转换数据和完全相同的转换图时。图 10-1展示了这种设置的工作原理。

Training multiple models simultaneously
图 10-1. 同时训练多个模型

如以下代码示例所示,您可以通过定义多个Trainer 组件,用 TFX 组装这样的图形:

def set_trainer(module_file, instance_name,
                train_steps=5000, eval_steps=100): 1
    return Trainer(
        module_file=module_file,
        custom_executor_spec=executor_spec.ExecutorClassSpec(
            GenericExecutor),
        examples=transform.outputs['transformed_examples'],
        transform_graph=transform.outputs['transform_graph'],
        schema=schema_gen.outputs['schema'],
        train_args=trainer_pb2.TrainArgs(num_steps=train_steps),
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

What Successful Brick-and-Mortar Retailers Get Right

What Successful Brick-and-Mortar Retailers Get Right

Rob Angell
Search Marketing

Search Marketing

Kelly Cutler
What Successful Project Managers Do

What Successful Project Managers Do

W. Scott Cameron, Jeffrey S. Russell, Edward J. Hoffman, Alexander Laufer

Publisher Resources

ISBN: 9798341659292