
上QQ阅读APP看书,第一时间看更新
1.3 TensorFlow 2.0有哪些重要的改动
TensorFlow 2.0包含大量的改动。Keras现在已经是TensorFlow的一部分。tf.keras
是TensorFlow对Keras的具体实现,使用它替换掉Keras,可以更好地与其他TensorFlow API(比如动态图tf.data
)集成,还有很多其他好处。这点我们将在第2章中详细讨论。
TensorFlow[1]可以使用pip
安装。
更多TensorFlow安装选项可参考
https://www.tensorflow.org/install
。
支持CPU版本:

支持GPU版本:

为了理解TensorFlow 2.0有哪些新特性,首先可以看一看在TensorFlow 1.0中编写神经网络的传统方法:

下面安装TensorFlow 2.0。
支持CPU版本:

支持GPU版本:

在TensorFlow 2.0中编写神经网络的代码实现如下所示:

很明显,代码更加简洁美观。事实上,TensorFlow 2.0的核心思想是使TensorFlow更易学易用。若你直接开始学习TensorFlow 2.0,则你是幸运的。如果你已经很熟悉1.x,那么就需要理解两者间的不同点,同时,你可能还需要借助一些自动化迁移工具来重写代码,这一点将会在第2章中讨论。现在,我们先介绍TensorFlow支持的最强大的学习范式之一:神经网络。
[1]此处指TensorFlow 1.x的安装。——译者注