本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
TensorFlow 2
本教程介绍如何在运行 采用 Conda 的 Deep Learning AMI (DLAMI on Conda) 的实例上激活 TensorFlow 2 并运行 TensorFlow 2 程序。
当框架的稳定的 Conda 程序包发布时,它会在 DLAMI 上进行测试并预安装。如果您希望运行最新的、未经测试的每日构建版本,您可以手动安装 TensorFlow 2 的每日构建版本(试验)。
激活 TensorFlow 2
在 DLAMI with Conda 上运行 TensorFlow
-
要激活 TensorFlow 2,请打开带有 Conda 的 DLAMI 的 Amazon Elastic Compute Cloud (Amazon EC2) 实例。
-
对于具有 CUDA 10.0 和 MKL-DNN 的 Python 3 上的 TensorFlow 2 和 Keras 2,运行以下命令:
$
source activate tensorflow2_p36 -
对于具有 CUDA 10.0 和 MKL-DNN 的 Python 2 上的 TensorFlow 2 和 Keras 2,运行以下命令:
$
source activate tensorflow2_p27
-
-
启动 iPython 终端:
(tensorflow2_p36)$
ipython -
运行 TensorFlow 2 程序以验证其是否正常运行:
import tensorflow as tf hello = tf.constant('Hello, TensorFlow!') tf.print(hello)
Hello, TensorFlow!
应显示在您的屏幕上。
安装 TensorFlow 2 的每日构建版本(试验)
您可以将最新的 TensorFlow 2 版本安装到您的 采用 Conda 的 Deep Learning AMI 上的任一或两个 TensorFlow 2 Conda 环境。
从每日构建版本安装 TensorFlow
-
-
对于 Python 3 TensorFlow 2 环境,运行以下命令:
$
source activate tensorflow2_p36 -
对于 Python 2 TensorFlow 2 环境,运行以下命令:
$
source activate tensorflow2_p27
-
-
删除当前安装的 TensorFlow。
注意 其余步骤假定您使用的是
tensorflow2_p36
环境。(tensorflow2_p36)$
pip uninstall tensorflow -
安装 TensorFlow 的最新每日构建版本。
(tensorflow2_p36)$
pip install tf-nightly -
要验证您是否已成功安装最新的每日构建版本,请启动 IPython 终端并检查 TensorFlow 版本。
(tensorflow2_p36)$
ipythonimport tensorflow print (tensorflow.__version__)
输出应类似于以下内容:
2.1.0-dev20191122
更多教程
有关教程,请参阅 DLAMI 的主目录中名为 采用 Conda 的 Deep Learning AMI tutorials
的文件夹。
有关更多教程和示例,请参阅 TensorFlow Python API