Tensorflow 简明教程

TensorFlow - Installation

要安装 TensorFlow,系统中必须先安装“Python”。通常认为 3.4+ 版本的 Python 最适合于开始 TensorFlow 安装。

To install TensorFlow, it is important to have “Python” installed in your system. Python version 3.4+ is considered the best to start with TensorFlow installation.

请考虑以下步骤在 Windows 操作系统中安装 TensorFlow。

Consider the following steps to install TensorFlow in Windows operating system.

Step 1 − 验证已安装的 Python 版本。

Step 1 − Verify the python version being installed.

python version installed

Step 2 − 用户可以选择任何一种机制来在系统中安装 TensorFlow。我们推荐使用“pip”和“Anaconda”。Pip 是用于执行和安装 Python 模块的命令。

Step 2 − A user can pick up any mechanism to install TensorFlow in the system. We recommend “pip” and “Anaconda”. Pip is a command used for executing and installing modules in Python.

在安装 TensorFlow 之前,我们需要在系统中安装 Anaconda 框架。

Before we install TensorFlow, we need to install Anaconda framework in our system.

install anaconda

安装成功后,请通过“conda”命令在命令提示符中执行检查。命令的执行如下所示 −

After successful installation, check in command prompt through “conda” command. The execution of command is displayed below −

conda command execution

Step 3 − 执行以下命令以初始化 TensorFlow 安装 −

Step 3 − Execute the following command to initialize the installation of TensorFlow −

conda create --name tensorflow python = 3.5
installation of tensorflow

它将下载 TensorFlow 设置所需的必要程序包。

It downloads the necessary packages needed for TensorFlow setup.

Step 4 − 环境设置成功后,重要的是激活 TensorFlow 模块。

Step 4 − After successful environmental setup, it is important to activate TensorFlow module.

activate tensorflow
environmental setup

Step 5 − 在系统中使用 pip 安装“Tensorflow”。用于安装的命令如下所示 −

Step 5 − Use pip to install “Tensorflow” in the system. The command used for installation is mentioned as below −

pip install tensorflow

并且,

And,

pip install tensorflow-gpu
pip to install
pip to install tensorflow

安装成功后,重要的是了解 TensorFlow 的示例程序执行。

After successful installation, it is important to know the sample program execution of TensorFlow.

以下示例有助于我们了解 TensorFlow 中的基本程序创建“Hello World”。

Following example helps us understand the basic program creation “Hello World” in TensorFlow.

hello world example

第一版程序实现的代码如下所示 −

The code for first program implementation is mentioned below −

>> activate tensorflow
>> python (activating python shell)
>> import tensorflow as tf
>> hello = tf.constant(‘Hello, Tensorflow!’)
>> sess = tf.Session()
>> print(sess.run(hello))