Check Tensorflow Version

Photo of author

By Vijay Singh Khatri

TensorFlow is a machine learning package that is used by developers to create large-scale neural networks with many layers. Finding out the version of the TensorFlow is quite vital as different versions have their own set of options and settings which can be used in programming a machine learning application. There are multiple ways for an individual to find the TensorFlow version. This article will talk about the methods to find the version of TensorFlow and ensure that you have the right one to fulfill your requirements.

What is TensorFlow?

TensorFlow is an end-to-end platform that is used in creating machine learning applications. It is an open-source symbolic math library that uses programming methodologies like dataflow and differentiable to perform specific tasks that are focused on training the deep neural networks. With the use of TensorFlow, a developer gets the advantage of using various tools, libraries, and community build resources for their machine learning application.

Moreover, right now in the world, Google’s approach to TensorFlow is the most famous deep learning library. Because Google uses deep learning and machine learning techniques with almost all of its products, some of the examples of Google’s TensorFlow usage can be seen in the search engine, translation of languages, image capturing and searching, and providing recommendations to users.

History of TensorFlow

The TensorFlow package was built by Google when they found out that deep learning outperforms machine learning when given massive amounts of data. Google thought of it as an opportunity to improve its services using deep neural networks. The services which are currently using deep learning TensorFlow in its applications are Gmail, Google Photos, and Google Search Engine.

TensorFlow allows researchers and developers to work together on a single AI model. Once TensorFlow was developed, it was given open-source accessibility so that every developer can use it according to their needs, and scale it depending on the project’s requirement. The first package was released in the fourth quarter of 2015, and the first stable version of TensorFlow surfaced in 2017. Being an open-source package TensorFlow is licensed by Apache Open Source License. A developer can use it, modify it, and redistribute it for free without actually paying anything to Google.

How TensorFlow Works

TensorFlow enables a developer to create dataflow graphs and structures that depict how the data moves from a series of processing nodes. Every single node present in the graph represents a mathematical operation. In addition to this, each connection or edge in between the two nodes is a multidimensional data array or, in simple words, a Tensor. All this functionality is provided to developers in the form of Python language, which is easy to understand and work with. It allows convenient methods to showcase high-level abstractions and how they can be coupled together.

Mathematical Operations

But one thing to keep in mind, it’s that actual math operations are not performed using Python language. The libraries which are used for the transformations and are available through TensorFlow are written in high-performance using C++ binaries. Python only directs the traffic between the pieces and provides high-level programming abstractions to combine them.

Latest TensorFlow 2.0 Features

The latest TensorFlow package was released in 2019, which has overhauled the framework in several ways but mainly based on users’ feedback. This allows the package to be much easier to work with. Now Keras API can be used for training models based on the TensorFlow package. The new API has made it much easier to run distributed training. Also, the support of TensorFlow Lite allows developers to deploy models on a greater variety of platforms.

On the other hand, the codes which are written for the earlier version of TensorFlow 1.x needs to be re-written if you want to use new TensorFlow 2.0 packages. The re-written part could be a small, or significant change in the code depending on its usage in the application.

Things You Need to Install to Use TensorFlow

  • First, you need to have a Python 2 or Python 3 version to be able to use TensorFlow machine learning packages. Anything below Python 2 will not work with TensorFlow packages.
  • Installation of TensorFlow packages in your system.
  • Finally, you should have administrator authority over the system to access the command line (CLI).

Steps to Find Out Different Types of TensorFlow Versions

There are a total of eight different methods to find out the TensorFlow version installed in your system, and we will discuss each of them in a step-by-step manner. Here are the steps:

1. Finding TensorFlow Version in Python

One of the easiest methods to find out the TensorFlow version is by using Python’s IDE or the inbuilt code editor. Python’s library comes with built-in methods to help users display the essential information. To find out the TensorFlow version, you need to enter the below-given command.

import TensorFlow as tf

print(tf.__version__)

With TensorFlow 2.x versions, users get to print the version of the package using the given below command in IDE.

import TensorFlow as tf

print(tf.version.VERSION)

2. Finding TensorFlow Version in Python Using Command Line (CLI)

The TensorFlow version can also be viewed by using the command line where the user has to perform the Python command and use “-c” for executing the command.

In case a system has installed different versions of Python, then the user needs to write the python<version> command.

3. Finding TensorFlow Version Using Terminal for Linux OS

Find out the TensorFlow version of the package installed using the command in the terminal:

python -c ‘import TensorFlow as tf; print(tf.__version__)’

On the other hand, if you have multiple versions of Python in the machine, then use:

python<version> -c ‘import TensorFlow as tf; print(tf.__version__)’

4. Finding TensorFlow Version in Windows Using Command Line

To find the version of TensorFlow in Windows 7, 8, 10, you need to write the below-given command in the command line:

python -c “import TensorFlow as tf; print(tf.__version__)”

Likewise, to find the specific version of the Python, you need to add a version number to the python command using the command:

python<version> -c “import TensorFlow as tf; print(tf.__version__)”

5. Check the TensorFlow version with pip

Installing Python libraries using the pip package manager is quite common. With the use of pip, there are two methods to find out the TensorFlow version.

1st Method: From pip show

With the use of the pip show command, the user will get the output of any installed package. To use the pip show to find out the TensorFlow version, you need to write.

pip show TensorFlow

2nd Method: Using pip list

The pip list command will show the list of all the packages installed in the given system. This command can also be used with a filter using the grep command; this filter command can only be used in Linux OS.

pip list | grep TensorFlow

For finding the version of TensorFlow using Pip in Windows with a filter, you need to use the following command.

pip list | findstr “TensorFlow”

6. Finding the TensorFlow Version in Virtual Machines

To find out the TensorFlow version in a virtual environment, you first need to have a virtual machine program present in your system, which is running operating systems like Linux and Windows virtually.

Step 1: Activating the virtual environment

To activate the virtual environment in your machine, use the commands given below for the appropriate OS.

  • For Linux OS, write the command: virtualenv <environment name>
  • For Windows, use: <environment name>\Scripts\activate

Step 2: Finding the version

To find the version in the virtual environment, you can use both python -c or pip show command.

7. Finding TensorFlow Version in Anaconda

Anaconda is a famous distributor platform for Python. In other words, it is Python with added data science packages that users can manipulate and find information in data. Moreover, it makes the managing of the different Python packages easier. As a result, a lot of Python developers prefer Anaconda Python over the simple Python version.

To find the TensorFlow version in the Anaconda platform, you need to add it to the command conda list. This will show you all the different libraries which are installed in the Conda.

  • To find out the version in Linux, the command is:

conda list | grep TensorFlow

  • For Windows, a user has to combine conda list and findstr commands to display the TensorFlow version:

conda list | findstr “TensorFlow”

8. Finding TensorFlow Version in Jupyter Notebook

Jupyter Notebook is a web application that is used to create and share documents that contain live code, equations, and text. The Notebook is an open-source application maintained and managed by Project Jupyter. In a lot of terms, Jupyter Notebooks are the spin-off made from the IPython project, which has its own IPython Notebook project. There are two ways to check the TensorFlow version in Jupyter Notebook.

1st Method: By Importing the TensorFlow library

A user imports the TensorFlow library and prints out the version by running these commands.

import TensorFlow as tf

print(tf.__version__)

2nd Method: Using pip

With the exclamation point with pip command, a user can find out the TensorFlow version.

!pip show TensorFlow

How to Manage Different TensorFlow Versions Using TensorFlow Serving

When you have multiple TensorFlow deep learning models that are based on different architectures or trained in different hyperparameters, then to test them locally or in production, you need to use the Model Server config file.

A Model Server config file is a protocol buffer file, which is language and platform-neutral. Thus, making the process of serializing the structure data easier. Given below are the steps which a developer needs to follow to manage different versions of TensorFlow.

Creating a Model Config file

To create a Model Config file that will work with every TensorFlow version present in the system, you need to use the below-given command where “MNIST” is the group of models:

model_config_list {

config {

name: ‘mnist’

base_path: ‘/models/mnist/’

model_platform: ‘TensorFlow’

model_version_policy: {all: {}}

}

}

From the above command, each ModelConfig specifies one model to be served with the following parameters.

  • Name – A servable model name.
  • Base_path – It specifies the path to look for versions of the servable.
  • Model_platform – Platform used to develop the model.

model_version_policy – It indicates which model needs to be loaded and served to the client. By default, it will serve the latest version. But the default configuration can be overridden by using the model_version_policy.

Loading Model Config File

To load the model config file, you first need to load the TensorFlow Serving Docker container on Windows 10 using the following command:

docker run -p 8501:8501 –mount

type=bind,

source=C:\TF_serv\TF_model, target=/models/mnist -e

MODEL_NAME=mnist -t TensorFlow/serving

To find out all the running Docker containers, write the following command:

docker container list

Or

docker ps

Now the user needs to copy the models.config file from the source to the target where the Docker image is present. Moreover, when you are copying the file to the docker container, provide the container ID (ba978f5a9475), as shown below:

docker cp \TF_serv\TF_model\models.config ba978f5a9475:/models/mnist

To stop the list of Docker containers, use the Docker container name or the container ID.

docker stop ba978f5a9475

After that, load the Model Config file using a flag (–model_config_file_poll_wait_seconds) that instructs the server to check for the file in a new config file at the path specified by using –model_config_file every 30 seconds.

docker run

-p 8501:8501

–mount type=bind,source=C:\TF_serv\TF_model,target=/models/mnist

-e MODEL_NAME=mnist

-t TensorFlow/serving

–model_config_file_poll_wait_seconds=60

–model_config_file=/models/mnist/models.config

Conclusion

So, these were the methods that a developer can use to find out the version of the installed TensorFlow. In this article, we have covered almost every method to find the TensorFlow version, but if we missed something, we would like our readers to help us out in the comment section. These commands might seem complicated to look at, but once you get used to their working, you will master them in no time.

Leave a Comment