# TensorFlow

**TensorFlow**是一个开源机器学习框架，由谷歌（Google）于2015年11月首次发布，采用Apache 2.0许可证。它将机器学习算法表达为数据流图，并在从手机到GPU集群和张量处理单元（TPU）的异构硬件上执行这些算法。<sup>[1](https://arxiv.org/abs/1603.04467)</sup><sup> • </sup><sup>[2](https://arxiv.org/abs/1605.08695)</sup>它提供稳定的Python和C++ API，并为其他语言提供额外的、不保证向后兼容的API。<sup>[3](https://github.com/tensorflow/tensorflow)</sup>

| 关键事实 | 详情 |
|---|---|
| 首次发布 | API及参考实现于2015年11月以Apache 2.0许可证开源发布<sup>[1](https://arxiv.org/abs/1603.04467)</sup> |
| 前身 | DistBelief，谷歌大脑（Google Brain）第一代分布式训练与推理系统，自2011年开始构建<sup>[1](https://arxiv.org/abs/1603.04467)</sup> |
| 执行模型 | 以数据流图表示计算、共享状态以及改变该状态的操作，并映射到包括多核CPU、GPU和TPU在内的多台机器和设备上<sup>[2](https://arxiv.org/abs/1605.08695)</sup> |
| 高层API | Keras，TensorFlow平台的高层API，覆盖从数据处理到部署的完整工作流<sup>[4](https://www.tensorflow.org/guide/keras?authuser=57)</sup> |
| TensorFlow 2.0 | 默认采用即时执行，通过`tf.function`将Python程序转换为TensorFlow图<sup>[5](https://blog.tensorflow.org/2019/01/whats-coming-in-tensorflow-2-0.html)</sup> |
| 仓库规模 | GitHub上约201,000颗星、79,200次复刻，采用Apache-2.0许可证<sup>[3](https://github.com/tensorflow/tensorflow)</sup> |
| 当前版本 | TensorFlow 2.21.0，取消对Python 3.9的支持并移除TensorBoard依赖<sup>[6](https://github.com/tensorflow/tensorflow/releases)</sup> |

## 在谷歌的起源

[谷歌大脑](https://www.edgepedia.org/zh/google-brain)项目始于2011年，旨在探索超大规模深度神经网络，用于研究和谷歌产品。其第一代系统DistBelief服务于这项工作，但将共享状态的管理内嵌于系统本身。TensorFlow的设计则使开发者能够试验新颖的优化方法和训练算法。<sup>[1](https://arxiv.org/abs/1603.04467)</sup><sup> • </sup><sup>[2](https://arxiv.org/abs/1605.08695)</sup>2015年的白皮书将TensorFlow描述为既是表达机器学习算法的接口，又是执行这些算法的实现，同一计算只需极少改动甚至无需改动，即可在从手机到由数百台机器和数千块GPU卡组成的分布式集群上运行。<sup>[1](https://arxiv.org/abs/1603.04467)</sup>

在发布时，谷歌报告称TensorFlow已在十多个领域的生产环境中使用，包括语音识别、计算机视觉、机器人学、信息检索、自然语言处理、地理信息抽取和计算药物发现。<sup>[1](https://arxiv.org/abs/1603.04467)</sup>

## 编程模型

**张量与变量。** TensorFlow对称为张量的多维数组进行运算，以`tf.Tensor`对象表示，这些对象不可变。模型权重等可变状态存储在`tf.Variable`对象中，通过`assign`和`assign_add`等方法更新。<sup>[7](https://www.tensorflow.org/guide/basics)</sup>

**自动微分。** TensorFlow实现自动微分以计算梯度，通常是模型损失相对于其权重的梯度。`tf.GradientTape`在前向传播过程中记录操作，并按需计算导数；它可以同时对任意数量的非标量张量求导。<sup>[7](https://www.tensorflow.org/guide/basics)</sup>

**图与tf.function。** TensorFlow 1.x要求用户手动构建操作的抽象语法树，并通过`session.run()`调用执行。TensorFlow 2.0像普通Python一样即时执行，而`tf.function`注解标记出要编译为单个图的Python函数，从而恢复图模式的性能优势：节点剪枝和内核融合等优化，以及通过导出和重新导入为SavedModel实现的可移植性。<sup>[5](https://blog.tensorflow.org/2019/01/whats-coming-in-tensorflow-2-0.html)</sup><sup> • </sup><sup>[8](https://blog.tensorflow.org/2019/02/effective-tensorflow-20-best-practices.html)</sup>`tf.function`会追踪一次Python代码以构建图，然后在后续调用中重新执行追踪得到的图，因此打印或修改列表等Python副作用只在追踪期间运行；要确保代码在每次调用时都运行，应使用`tf.print`和`tf.Variable.assign`等TensorFlow API。<sup>[9](https://www.tensorflow.org/guide/function)</sup>`tf.function`还仅支持在首次调用时创建并在之后复用的单例`tf.Variable`对象。<sup>[9](https://www.tensorflow.org/guide/function)</sup>

**数据输入。** `tf.data` API由可复用的组件构建输入流水线：`tf.data.Dataset`表示元素序列，可从内存数据、TFRecord文件、CSV文件或文本构建，并通过`Dataset.map`和`Dataset.batch`等链式方法进行转换。<sup>[10](https://www.tensorflow.org/guide/data?authuser=0)</sup>

## Keras与API栈

[Keras](https://www.edgepedia.org/zh/keras)是TensorFlow平台的高层API，覆盖机器学习工作流的每一步，从数据处理到超参数调优再到部署。其核心结构是层和模型：每个层封装权重和计算，模型则将层分组，并提供内置的`fit`、`predict`和`evaluate`方法，支持回调、分布式训练和TensorBoard监控。<sup>[4](https://www.tensorflow.org/guide/keras?authuser=57)</sup>

自TensorFlow 2.16起，安装TensorFlow会默认安装Keras 3。<sup>[11](https://keras.io/getting_started/)</sup>Keras 3是多后端框架：相同的Keras模型和组件可在TensorFlow、JAX或PyTorch上运行，Keras模型既可以在使用`tf.GradientTape`和`tf.distribute`的底层TensorFlow循环中训练，也可以在JAX和PyTorch训练循环中训练。<sup>[12](https://keras.io/keras_3/)</sup>

## 部署生态系统

**SavedModel。** SavedModel包含完整的TensorFlow程序，包括训练好的参数和计算，运行时无需原始模型构建代码。它是与TensorFlow Lite、TensorFlow.js、TensorFlow Serving和TensorFlow Hub配合部署的交换格式。<sup>[13](https://www.tensorflow.org/guide/saved_model)</sup>

**TensorFlow Serving。** TensorFlow Serving是面向机器学习模型的服务系统，专为生产环境设计；它使用SavedModel，并通过REST或gRPC接口接受推理请求。<sup>[14](https://www.tensorflow.org/tfx/guide)</sup>谷歌将其描述为用于在谷歌内部提供模型服务的系统，可在云端和通过开源获取。<sup>[15](https://arxiv.org/abs/1712.06139)</sup>

**TFX。** TFX是谷歌生产规模的基于TensorFlow的机器学习平台，提供配置框架和共享库，用于在生产环境中构建和管理机器学习工作流。TFX流水线是一系列组件，如ExampleGen、StatisticsGen、SchemaGen、ExampleValidator、Transform、Trainer和Tuner，可在[Apache Airflow](https://www.edgepedia.org/zh/apache-airflow)、Apache Beam和Kubeflow Pipelines等平台上编排。<sup>[14](https://www.tensorflow.org/tfx/guide)</sup>

**端侧推理。** TensorFlow Lite于2017年推出，将模型带到移动和嵌入式设备上；到2024年，谷歌报告其已在27亿台设备上的超过10万个应用中使用。2024年9月，它作为Google AI Edge套件的一部分更名为[LiteRT](https://www.edgepedia.org/zh/litert)，现在也支持用PyTorch、JAX和Keras编写的模型。`tf.lite` API已弃用，转而使用独立的LiteRT仓库，`tf.lite.Interpreter`计划在TensorFlow 2.20中删除。<sup>[16](https://discuss.ai.google.dev/t/tensorflow-lite-is-now-litert/38162)</sup><sup> • </sup><sup>[6](https://github.com/tensorflow/tensorflow/releases)</sup>

## 版本与平台支持

TensorFlow 2.0于2019年发布，将即时执行设为默认模式，统一采用Keras作为核心高层API，并以`tf.function`取代会话。<sup>[5](https://blog.tensorflow.org/2019/01/whats-coming-in-tensorflow-2-0.html)</sup><sup> • </sup><sup>[8](https://blog.tensorflow.org/2019/02/effective-tensorflow-20-best-practices.html)</sup>官方pip包支持64位Python 3.9至3.12，运行于Ubuntu 16.04或更高版本、[Windows 7](https://www.edgepedia.org/zh/windows-7)或更高版本以及macOS 10.12.6或更高版本，并为Linux和WSL2提供GPU包；macOS没有官方GPU支持。<sup>[17](https://www.tensorflow.org/install)</sup>原生Windows GPU支持在TensorFlow 2.10终止；从2.11起，Windows上不支持CUDA构建，使用GPU需要WSL2或TensorFlow-DirectML-Plugin。<sup>[18](https://www.tensorflow.org/install/source_windows?authuser=0)</sup>

发布活动仍在继续：TensorFlow 2.20.0将`tensorflow-io-gcs-filesystem`包设为可选，并弃用`tf.lite`转而使用LiteRT；2.21.0取消对Python 3.9的支持并移除TensorBoard依赖。<sup>[6](https://github.com/tensorflow/tensorflow/releases)</sup>TensorFlow Lite拥有独立于主TensorFlow版本的版本号，未来可能会分化。<sup>[19](https://www.tensorflow.org/guide/versions?hl=en)</sup>

## References

1. [Martín Abadi and colleagues (2015). TensorFlow: Large-Scale Machine Learning on Heterogeneous Distributed Systems. arXiv.](https://arxiv.org/abs/1603.04467)
2. [Martín Abadi and colleagues (2016). TensorFlow: A system for large-scale machine learning. arXiv.](https://arxiv.org/abs/1605.08695)
3. [tensorflow/tensorflow on GitHub](https://github.com/tensorflow/tensorflow)
4. [Keras: The high-level API for TensorFlow, TensorFlow Core guide](https://www.tensorflow.org/guide/keras?authuser=57)
5. [What's coming in TensorFlow 2.0, The TensorFlow Blog (January 2019)](https://blog.tensorflow.org/2019/01/whats-coming-in-tensorflow-2-0.html)
6. [Releases, tensorflow/tensorflow on GitHub](https://github.com/tensorflow/tensorflow/releases)
7. [TensorFlow basics, TensorFlow Core guide](https://www.tensorflow.org/guide/basics)
8. [Effective TensorFlow 2.0: Best Practices and What's Changed, The TensorFlow Blog (February 2019)](https://blog.tensorflow.org/2019/02/effective-tensorflow-20-best-practices.html)
9. [Better performance with tf.function, TensorFlow Core guide](https://www.tensorflow.org/guide/function)
10. [tf.data: Build TensorFlow input pipelines, TensorFlow Core guide](https://www.tensorflow.org/guide/data?authuser=0)
11. [Getting started with Keras, keras.io](https://keras.io/getting_started/)
12. [Keras 3: Deep Learning for humans, keras.io](https://keras.io/keras_3/)
13. [Using the SavedModel format, TensorFlow Core guide](https://www.tensorflow.org/guide/saved_model)
14. [The TFX User Guide, TensorFlow](https://www.tensorflow.org/tfx/guide)
15. [TensorFlow-Serving: Flexible, High-Performance ML Serving. arXiv.](https://arxiv.org/abs/1712.06139)
16. [TensorFlow Lite is now LiteRT, Google AI Developers Forum (September 2024)](https://discuss.ai.google.dev/t/tensorflow-lite-is-now-litert/38162)
17. [Install TensorFlow 2, TensorFlow](https://www.tensorflow.org/install)
18. [Build from source on Windows, TensorFlow](https://www.tensorflow.org/install/source_windows?authuser=0)
19. [TensorFlow version compatibility, TensorFlow Core guide](https://www.tensorflow.org/guide/versions?hl=en)

---
*Initially written Sep 17, 2026 · Reviewed: Sep 30, 2026; Oct 15, 2026 · Edited: Sep 30, 2026; Oct 15, 2026 · Last review: Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 人工智能与数据 › Machine learning and neural computation › Neural networks and deep learning › Deep learning software and hardware › Deep learning frameworks and libraries

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/tensorflow

English original: https://www.edgepedia.org/tensorflow
