When it comes to deep learning using Python the two most widely used libraries are Keras and TensorFlow. Both these libraries are very powerful. A whole community of developers are at work to make these two more and more useful day-by-day.
In this post, we will discuss what are these libraries, how to install them, what are their pros and cons. So a lot to learn; a lot to discuss; let’s get started.
What is Keras?
Keras is a python library that was developed to make the implementation of deep learning modular, fast and easy. It is widely used in the field of research and development. It can be used in Python 2.7 or 3.5.
Keras is an open-source library and can be used on top of TensorFlow or Theano. It was developed by a Google engineer named Francois Chollet.
Keras does not perform its low-level computations. Instead, it uses another library to perform this called “Backend”. So Keras is a high-level API that can run over low-level API like TensorFlow, Theano or CNTK.
What is Backend?
Backend is used to perform all low-level computations in Keras like tensor products and convolutions. It makes use of libraries like TensorFlow and Theano.
So in simple terms “backend engine” is tasked with performing development and computation of models.
The default backend engine is TensorFlow, but we can change it as per the requirements.
How to Install Keras on Windows?
Before you can install Keras you have to install Python on your system. After installing Python install pip and virtualenv. These installations are beyond the scope of this article. You can refer to YouTube videos for more information.
After you have installed all three, you are now all set to install Keras in your system.
Type the following command on your terminal:
Pip install Keras
This will begin installing Keras and all its dependencies.
Now Keras is installed in your system. Let’s verify it.
Before you can use Keras, you need to find out which backend it is using.
Type the following command in the terminal:
gedit ~/.keras /keras.json
You should see something like this:
“floatx” : “float32”,
“epsilon” : 1e-07,
“backend” : “tensor-flow”,
“image_data_format” : “channels_last”
As you can clearly see, the backend is using TensorFlow.
You can now run it on your system by using the following code:
Let us now discuss the pros and cons of using Keras.
What are the advantages of Keras?
Fast and Easy
When it comes to the speed of making a network model, nothing comes closer to Keras. If you wish to make a simple model with only a few lines of code, Keras is the go-to option. The friendly API makes it easy to understand.
Large Community Support
There is a huge group of AI communities working on research and implementation of AI. Many of them publish their codes and tutorials for the general public.
Feature of multiple Backend
Keras allows choosing backend as per the project requirement. TensorFlow is the default backend, but you can also use CNTK and Theano. You must know the pros and cons of the backend and use it as per your requirement.
Keras has a variety of supported platforms and devices. You can deploy Keras on
- Android using TensorFlow Android
- Raspberry Pi
- iOS using CoreML
- Cloud Engine
- Web browsers using .js support
You can use Keras with a single GPU or multiple GPU as per the project demands. Keras can process large volumes of data and speed up the training process.
What are the Disadvantages of Keras?
Unable to handle low-level API
Keras can handle only the high-level API. All the low-level computations are performed by the backend as discussed above. So it is not very useful if you want to make your own abstract layer.
What is TensorFlow?
Google uses machine learning in almost its entire product may it be a search engine, image captioning, translation or recommendations. So they have developed their own library known as TensorFlow.
TensorFlow was developed by the Google Brain Team to facilitate machine learning and neural network research.
There are three parts to TensorFlow architecture:
- Pre-processing the data
- Building the model
- Training the model
The name TensorFlow comes from the fact that it takes input as a multidimensional array called “tensors”. The input enters from one end, flows through the entire system with multiple operations and finally comes out from the other end.
So “tensor” is the input and it flows through the system, so the name TensorFlow.
Where can TensorFlow run?
The hardware and software requirement for TensorFlow can be classified into two parts:
- Development Phase: when the model is trained. Training can be done on a desktop or laptop.
- Run Phase: Once training is completed, TensorFlow can be implemented in many different platforms like
- Desktop: Windows, Linux or macOS
- Mobile: Android and iOS
The interesting fact is that the model can be trained and implemented using a GPU or CPU. GPU is very good in matrix multiplication, and deep learning needs a lot of matrix multiplication. So we can also use GPU. TensorFlow is written using C++ and so it is fairly fast in matrix multiplication.
An important feature of TensorFlow is TensorBoard. TensorBoard allows you to monitor visually and graphically what TensorFlow is doing.
How to install TensorFlow?
Installing TensorFlow can take some time. So have some patience.
- Open your terminal and type this command:
conda create –n tensorflow_CPU pip python = 3.6
- This will lead to the creation of a new virtual environment named tensorflow_CPU.
- Next step is to activate this environment. So type the following command
- You should get this output:
- This proves that the environment has been created and ready to use.
- Now the installation process begins. Type this command:
pip install –ignore-installed –upgrade tensorflow == 1.9
- This will start the installation. Wait for it to finish.
Open a new terminal and activate the tensorflow_CPU environment as you have done before.
Start a new python session by typing
Once the interpreter starts to type the following command:
>>> import tensorflow as TF
If the above code executes successfully that means TensorFlow is properly installed in your system.
Components of TensorFlow
The name TensorFlow is directly derived from the core component called tensors. All computations in TensorFlow will involve tensors. A tensor can be viewed as a matrix or vector of n-dimensions that can be used to represent all kinds of data. The shape of the data refers to the dimensionality of the vector or matrix.
All the computations will be performed inside graphs. Graphs are a successive set of computations. Each operation in a graph is called op node and are connected to one another. Graphs outline the connections or ops between nodes. but, it does not reveal the value. At each edge of the node, we have tensors.
Advantages of graphs
- It helps in implementing TensorFlow in multiple CPU or GPU and even smartphones.
- It can store computations for later use. You can also save the graph for any future use.
- A graph is a medium to connect tensors together.
Prominent Algorithms Supported by TensorFlow
TensorFlow 1.10 supports the following algorithms:
- Classification: tf.estimator.LinearClassification
- Linear Regression: tf.estimator.LinearRegressor
- Deep learning wipe and deep: tf.estimator.DNNLinearCombinedClassification
- Deep Learning Classification: tf.estimator.DNNClassifier
- Boosted Tree Classification: tf.estimator.BoosstedTreesClassifier
- Boosted Tree Regression: tf.estimator.BoosterTreesRegressor
What are the advantages of TensorFlow?
TensorFlow can help you in visualizing your data with the help of graphs. TensorFlow is much better in this case when compared to its competitors like Theano and Torch.
TensorFlow is managed by one of the prominent names in the AI industry – Google. So it has the advantage of frequent updates, quick support and seamless performance.
With TensorFlow you can execute sub-parts of a graph this offers a good debugging method.
TensorFlow is supported by a lot of devices starting from your smartphone to the desktop. Again in a smartphone, it is supported by Android as well as iOS. Similarly, in the case of Desktop, it is supported by Windows, Linux and macOS.
TensorFlow is very parallel and can be used in various backend software (ASIC, GPU, etc.).
What are the Disadvantages of TensorFlow?
Missing Symbolic Loops
In variable-length sequences, symbolic loops are very important. Unfortunately, TensorFlow lacks it. But you can get through this by using bucketing.
No support for Windows
There are a lot of users who prefer using Windows rather than Linux for its easy to use interface. However, TensorFlow does not provide any support for Windows.
TensorFlow lacks both usage and speed when compared to its competitors.
Lack of GPU support
Currently, only NVIDIA provides GPU support for TensorFlow
click here to learn about artificial intelligence course
Lack of language support
Python is the only language that supports TensorFlow. But with the rise of the machine learning community, more languages like Lau are coming forward in TensorFlow support.
I am Bharani Kumar Depuru, eminent Digital Transformation Specialist with over 15+ years of professional experience in Emerging Technologies consulting. I am an alumnus of IIT & ISB and serve on the board of multiple companies in devising their strategies.
Alumnus of ISB and IIT with 15+ years of experience working in various capacities with companies including HSBC, ITC Infotech, Infosys, Deloitte. Performing consulting for various companies on Industrial Revolution 4.0 implementation, Data Analytics practice setup, Artificial Intelligence, Big Data Analytics, Industrial IoT, Business Intelligence, Business Management Consulting, etc., are a few of the prime activities performed. Worked across various lines of business including IT, Quality Management, Project Management, IT Service Management, etc.
Notable Clients for whom Data Science, Machine Learning and AI implementations are performed includes: Coca Cola, Tata Trusts, Trujet, Yatra, Korean Airlines, etc.
Director of 360DigiTMG
Headquartered in India, 360DigiTMG provides professional management and emerging technologies training across the globe. With international accreditations from world renowned certification bodies, 360DigiTMG is at the forefront of delivering quality education, thereby bridging the gap between academia and industry. For details please refer to our website.