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