×

PyPi TensorFlow

It is a free open-source library for high-performative numerical computations. The architecture of TensorFlow allows us for easy deployment and computing across a varied number of platforms and from desktops to clusters servers of mobile and edge devices.

It is developed by the Google Brain team of engineers and researchers from Google's AI organization. It comes along with strong support for deep learning, machine learning, and varied numerical computation is used across many domains.

Features

  • It has features that define, optimize and calculate mathematical expressions using multi-dimensional arrays called tensors.
  • It includes good support for the development of machine learning and deep learning neural networks.
  • It has high scalable features for computation with various datasets.
  • It uses GPU computing automating management and a unique feature for optimization of memory and dataset.

Installation of TensorFlow

"python" is mandatory to install TensorFlow in our system.

In the windows operating system, follow the below steps to install TensorFlow.

Step 1: python version presented in the system should be verified.

PyPi TensorFlow

Step 2: Any mechanism can be used to install TensorFlow but it is advised to use "Anaconda" and "pip". The command "pip" is used to install modules in python.

Anaconda framework should be installed previously to TensorFlow.

PyPi TensorFlow

After installation, check with the "conda" command. The command execution is displayed as:

PyPi TensorFlow

Step 3: To install TensorFlow execute the below command.

conda create --name tensorflow python = 3.5
PyPi TensorFlow

It downloads all the necessary packages for the setup

Step 4: After successful set up of the environment we should activate TensorFlow.

activate tensorflow
PyPi TensorFlow

Step 5: We use pip for installing TensorFlow in the system.

pip install tensorflow
PyPi TensorFlow

TensorFlow

TensorFlow is a basic software library for numerical computing using dataflow graphs where,

  • Node: It represents mathematical operations.
  • Edge: It represents a multi-dimensional array called Tensors.

Note: A tensor is a central unit of data in TensorFlow

Consider the below diagram:

PyPi TensorFlow

Here, mul is a node that represents multiplication operation. Here, a and b are called as input (or) incoming tensors, and c is the resulting (or) output tensor.

The flexible architecture of tensors allows us to compute on more than one CPU or GPU in a system or server or a mobile application with a single API.

APIs in TensorFlow

TensorFlow provides us with many APIs (Application Programming Interface). But they can be classified majorly into two categories:

  1. Low-level API
  2. High-level API

1. Low-level API

  • It has complete programming control.
  • It is recommended mostly for machine learning researchers.
  • It provides us with fine levels of control over the modules.
  • TensorFlow Core is an example of a low-level API.

2. High-level API

  • It is built on top of the other low-level APIs.
  • It is easier to learn and use than other low-level APIs.
  • Between multiple users, it makes repetition easier and more consistent.

Let us consider an example program in python using TensorFlow.

Example

# importing tensorflow
import tensorflow as tf
# creating nodes of computational graphs
node_a = tf.constant ( 4, dtype = tf.int32 )
node_b = tf.constant ( 5, dtype = tf.int32 )
node_c = tf.add ( node_a, node_b )
# creating object for tensorflow session
s = tf.Session()
# evaluating node_c and printing of result
print( " addtion of node_a and node_b is :  ", s.run(node_c) )
# closing the session object
s.close()

Output

sum of node_a and node_b is : 9

Explanation of above code

Step 1: Creating a computational graph.

Creating a computational graph means defining the nodes. TensorFlow provides us with different types of nodes for different types of tasks. Each node takes zero or more tensors as inputs and produces an output as a tensor.

  • In the above program, the nodes node_a and node_b are of tf.constant type. A node that takes no inputs is called a constant node. It outputs value is stored internally.

NOTE: dtype argument is used to specify the data type of the output

node_a = tf.constant ( 4, dtype = tf.int32 )
node_b = tf.constant ( 5, dtype = tf.int32 )
  • The node node_c is of tf.add type which, takes two tensors as input and gives the resultant value as the output tensor.
node_c = tf.add ( node_a, node_b )

Step 2: Running of a computational graph

A session must be created to run a computational graph.

s = tf.Session()

Now, we should use run method for performing computations

print( " addtioon of node_a and node_b is :  ", s.run(node_c) )

Finally, we should use close method to close the method.

s.close()

Related Topics

Python JSON

In this tutorial, we will learn about JSON in the Python programming language. We will focus on its features, Guidelines to be kept in mind while writing its syntax, the...

3 minutes read.

Python List remove() method

Python List remove() method The list.remove () method in Python removes the item at the specified position in the given list. Syntax list.remove(x) Parameter x: This parameter represents the element you want to remove and accepts any type...

1 minute read.

How to Declare a Variable in Python?

The concept of constants and variables is something that we are studying right from our primary classes. We know that constants are the fixed values whereas variables are those whose...

4 minutes read.

Python Num2words

Python: Python programming language is one of the most used programming languages, as it is used widely in the field of software and data analysis, web development, etc. It is said...

3 minutes read.

What is Python compiler GDB?

The source code of one programming language is converted into machine code, bytecode, or another programming language by a compiler, a specialised software. A compiler is a tool that converts high-level...

3 minutes read.

Python Typing Module

An Introduction to the Typing Module The typing module is introduced in Python version 3.5 and used to provide hinting method types in order to support static type checkers and linters...

10 minutes read.

Selection Sort Using Python

Selection sort is a type of sorting algorithm which is based on sorting elements in increasing order or ascending order through comparison. This sorting technique does not take extra space...

3 minutes read.

Python Line Break

Introduction In this tutorial, you will learn line breaks in python.In Python, the new line character is used to indicate the start of a new line and the end of an...

5 minutes read.

Python | Read csv using pandas.read_csv()

Python is an excellent language for performing information analysis, owing to the fantastic biological system of information-driven python packages. Pandas is one of those packages that make taking in and...

4 minutes read.

Python List count() method

Python List count() method The list.count() method returns the number of times x appears in the list. Syntax list.count(x) Parameter x: This parameter represents the value to search for and can contain any iterable (list, set, tuple, etc.) Return This method returns the...

1 minute read.

Python Linear regression

In this tutorial, we will understand the meaning, usage, and types of Linear Regression. Further, we will comprehend the terms cost function and Optimization. Linear Regression is the widely used Machine...

3 minutes read.

Uint8 Python

Python: Python programming language is one of the most used programming languages, as it is used widely in the field of software and data analysis, web development, etc. It is said...

3 minutes read.

Scrimba python

Scrimba allows you to study whenever and wherever the topics or concepts you want. It also replaces classroom instruction with interactive screencasts, live events, and student-to-student help. Scrimba is an interactive...

3 minutes read.

Python Web Development projects

What is Python? Python is currently one of the most widely used computer programming languages. This isn't just an exaggeration; Python is the second-most famous programming language on the software development...

3 minutes read.

Difference between Module and Package in Python

The main difference between the module and the package in Python is that the module can be a simple file in Python that contains the different functions and collection of...

4 minutes read.

Front end in python

Python : Python is an object oriented programming language which is highly interpreted and is highly interactive. Python was created by Guido van Rossum in the year 1985 – 1990 .The...

4 minutes read.

Python issubclass() Function

Python issubclass() Function The issubclass() function in Python returns a boolean value ‘True’ if the given object is a subclass of classinfo, else it returns False. Syntax issubclass(class, classinfo) Parameter class: It is a required parameter which represents a tuple...

1 minute read.

Python Operator Precedence

Before knowing about the operator precedence in Python, we have to know about the operators in Python. So let's have a look at it. According to one definition, the operator is...

3 minutes read.

Python variance() function

Variance The variance is the average of the square deviations from the mean. The variance will measure the spread of the dataset from its mean or median value. The greater the...

4 minutes read.

Python bin() function

Python bin() function The bin() function in Python returns the binary version for the specified integer. Syntax bin(x) Parameter n: This parameter represents an integer or int value. Return This function returns a binary string for the specified integer...

1 minute read.