Updated April 20, 2023
Introduction to Tensorflow
Tensorflow is open-source software and a library. It was developed by the Google Brain team built by a deep learning artificial intelligence research team at Google 2010. Google was using it for internal use after that it was released under Apache2.0 Open source – 2015. In this topic, we are going to learn about TensorFlow Basics.
Tensorflow is Google brain’s second-generation system. Version 1 was released on Feb 11, 2017. Tensorflow 1.0 now had Python API and API for Java and GO language is also added to version 1.0. Tensorflow operations neural network performed on a multidimensional data array, which is referred to as a tensor. It works with Tensors. It is a software library for deep learning and mainly works for numerical computation using data flow graphs.
What are Tensorflow Basics?
Tensors are objects that describe the linear relation between vectors, scalars, and other tensors. Tensors are nothing but multidimensional arrays. Tensorflow provides support to write the code according to your requirements and access to different kinds of tools. For example, we can write code in C++ and can call C++ code from python. Or we can write Python code and call it by C++.
The lowest layer it supports two languages first is Python language and the second C++ language. You can write it in any language in your comfort zone. It has a collection of different math libraries that help to create math functions easily.
It also provides support for processing like CPU, GPU, and TPU and also runs on Android mobiles.
- Tf.layers: tf.layers are used for method abstract so that you can customize the layers of neural networks.
- Tf.estimator: most commonly used API in TensorFlow is the tf.estimator. It helps in create and train, test your model.
Installation of Tensorflow
- First, check your pip version; if not the latest, then run the following command to upgrade pip.
pip install –upgrade pip
- Run the below code to install the simpler version of Tensorflow.
pip install tensorflow / conda install tensorflow (Anaconda)
- This will install Tensorflow with GPU supported configurations.
pip install Tensorflow-gpu
Example of tf.estimator to Use Classifier by 3 Lines of Code
import tensorflow as tf classifier = tf.estimator.LinearClassifier(feature_columns) classifier.train(input_fn=train_input_function, steps=2000) predictions = classifier.predict(input_fn=predict_input_function)
Basic Data Types of Tensorflow
The basic data types in the Tensorflow framework (Tensors).
Below shows each dimension of tensors:
- Scalar – O Dimensional Array
- Vector – 1 Dimensional Array
- Matrix – 2 Dimensional Array
- 3D Tensor – 3 Dimensional Array
- N – D Tensor – N-dimensional array
Given below are constant tensors:
tf.Variable class, for creating a variable in TensorFlow and calling the tf.get_variable function.
To initialize the variables, By calling tf.global_variables_initializer, we can initialize all the variables.
A simple example of variable and Math expression
a = 3.0, b = 8*a +10
c = tf.Variable (tf.add (tf.multiply (X, a), b)
Every line in our code written in TensorFlow is converted into an underlying chart.
- Nodes: It represents mathematical operations.
- Edges: it represents the multidimensional array (Tensors) and shows how they communicate between them.
3. Tensorflow 2.0
- In the second version of Tensorflow, they focused on making the API simpler and easy to use.
- The API components integrate better with Keras; by default, the eager execution mode is activated.
- Eager Mode: Eager execution is a run interface where operations are executed immediately as they are called Python.
- We can use eager mode instead of graph mode. We can compute what we need to compute, and we can get results right away. This will make Tensorflow as easy as Pytorch.
- Focusing on removing duplication APIs.
- Tensorflow provides a high-level API for building and training deep learning models. This was not included in TensorFlow, but in the latest release, Keras has been included in Tensorflow 2.0.
- User-friendly: Keras provides a simple, consistent interface for common use cases.
- Modular and composable: Keras models are made by connecting building blocks together.
- Easy to extend: Create or update new layers, metrics, loss functions.
- Use tf.keras for using Keras models.
5. Tensorflow Lite
- In 2017, Google announced software that is specifically built for mobile development, Tensorflow Lite.
- Tensorflow Lite (TFLite) is a lightweight solution for on- Mobile device inference.
- We can also use it for IOS and Android by creating C++ API, as well as we can also use the Java wrapper class for Android Developers.
List of Algorithm that Tensorflow Supports
Given below is the list mentioned:
1. For Regression
- Linear Regression (tf.estimator. Linear Regression)
- Booster tree Regression (tf.estimator. Boosted Tree Regressor)
2. For Classification
- Classification (tf.estimator. Linear Classifier)
- Deep Learning Combined (tf.estimator. DNNLinearCombinedClassifier)
- Boosted tree classifier (tf.estimator. Boosted Tree Classifier)
Features of Tensorflow
Given below are the features mentioned:
- Tensorflow works Efficiently with different types of mathematical expressions involving Multidimensional arrays(Tensors).
- It also provides support for deep learning neural networks and other machine learning concepts.
- Tensorflow can run on multiple CPUs and GPUs.
- It also provides its own processing power that is the Tensor Processing Unit.
Tensor Processing Unit (TPU)
- Google announced its Tensor processing unit(TPU), an application-specific integrated circuit(Hardware Chip), built specifically for Machine Learning and tailored for Tensorflow.
- In 2017, Google announced the second version of Tensorflow and the availability of the TPUs in google cloud.
- TPU is a programmable AI accelerator and built for using or running models. Google running TPUs inside their data centres for more than a year.
- Edge TPU is a chip that googles built to design and run TensorFlow Lite machine learning (ML) models on small computing devices such as smartphones.
- High scalability for computing huge datasets.
- It can also train and serve models in a live model. Rewriting of code I not required.
Conclusion – Tensorflow Basics
Tensorflow is a very commonly used deep learning library. That is mostly used in creating neural networks, also used by startup companies, big companies. As seen above, Google is also using TensorFlow for its internal purpose; it is still used in mostly all kinds of products like Gmail and google search engine.
We hope that this EDUCBA information on “Tensorflow Basics” was beneficial to you. You can view EDUCBA’s recommended articles for more information.