In this short tutorial, we are going to install TensorFlow on a Windows Platform and write first TensorFlow code within a Jupyter Notebook. TensorFlow is an open source machine learning framework that is being developed by Google. TensorFlow allows executing high-performance numerical computations on a variety of platforms (e.g. CPUs, GPUs) and system configurations (e.g. single desktop PC or cluster). With increasing popularity of deep learning and machine learning, TensorFlow became an obligatory tool in many scientific domains.
We will install TensorFlow using Anaconda Distribution, which contains Python, Jupyter Notebook and other popular tools and libraries for data science. Download Anaconda first, for that you have to choose between the Python 3.6 and Python 2.7 Versions. If you are not going to work with any older libraries that functions with Python 2 only than I would suggest going for the Python 3.6 Version.
After you have downloaded the Anaconda Installer, execute it, accept the license agreement, select if you want to install it for yourself only or for all users on your machine, select a destination folder, leave the advanced options as they are and click Install. At the end of the installation process, Anaconda will offer you to install the Microsoft VSCode Editor. You can skip the step for this tutorial since we will use Jupyter Notebook. You can also install VSCode any time later from the Anaconda Navigator. Click Finish to complete the installation.
Now, with Anaconda installed, we will install TensorFlow and Jupyther Notebook. For that, search and execute Anaconda Prompt in the Windows Start Menu. Next, we will create a new Anaconda environment using conda tool, which is a tool for deploying applications, environments, and packages. For that, the create command has to be executed:
conda create -n tensorflow pip python=3.6 tensorflow jupyter
The command creates a new environment with the name tensorflow and installs the packages pip, python version 3.6, tensorflow, and jupyter within this environment. After the environment has been deployed you have to activate it with the following command:
conda activate tensorflow
Next, we will start the jupyter notebook to write our first tensorflow application. To start the notebook use the following command:
The jupyter notebook will start in your browser. To create a new notebook, click on the New button in the top right corner and select Python from the drop-down menu. In the first cell of the notebook write the following code:
import tensorflow as tf hello = tf.constant("Hi") sess = tf.Session() sess.run(hello)
Now click on the run button. If everything was done correctly, then the word “Hi” should appear in the output cell.