Reader small image

You're reading from  Deep Learning for Beginners

Product typeBook
Published inSep 2020
Reading LevelBeginner
PublisherPackt
ISBN-139781838640859
Edition1st Edition
Languages
Tools
Right arrow
Author (1)
Dr. Pablo Rivas
Dr. Pablo Rivas
author image
Dr. Pablo Rivas

Dr. Pablo Rivas is an assistant professor of computer science at Baylor University in Texas. He worked in industry for a decade as a software engineer before becoming an academic. He is a senior member of the IEEE, ACM, and SIAM. He was formerly at NASA Goddard Space Flight Center performing research. He is an ally of women in technology, a deep learning evangelist, machine learning ethicist, and a proponent of the democratization of machine learning and artificial intelligence in general. He teaches machine learning and deep learning. Dr. Rivas is a published author and all his papers are related to machine learning, computer vision, and machine learning ethics. Dr. Rivas prefers Vim to Emacs and spaces to tabs.
Read more about Dr. Pablo Rivas

Right arrow
Setup and Introduction to Deep Learning Frameworks

At this point, you are now familiar with machine learning (ML) and deep learning (DL) - this is great! You should feel ready to begin making the preparations for writing and running your own programs. This chapter helps you in the process of setting up TensorFlow and Keras, and introduces their usefulness and purpose in deep learning. Dopamine is presented as the new reinforcement learning framework that we will use later on. This chapter also briefly introduces other deep learning libraries that are important to know.

The topics that will be covered in this chapter are as follows:

  • Introduction to Colaboratory
  • Introduction and setup of TensorFlow
  • Introduction and setup of Keras
  • Introduction to PyTorch
  • Introduction to Dopamine
  • Other deep learning libraries

Introduction to Colaboratory

What is Colaboratory? Colaboratory is a web-based research tool for doing machine learning and deep learning. It is essentially like Jupyter Notebook. Colaboratory is becoming very popular these days as it requires no setup.

Throughout this book, we will be using Python 3 running on Colaboratory which will have installed all the libraries we may need.

Colaboratory is free to use and is compatible with most major browsers. The company in charge of the development of the Colaboratory tool is Google. As opposed to Jupyter notebooks, in Colaboratory you are running everything on the cloud and not on your own computer. Here is the catch: you need a Google account since all the Colaboratory notebooks are saved into your personal Google Drive space. However, if you do not have a Google account, you can still continue reading to see how you can install every piece of Python library you will need to run things on your own. Still, I highly recommend you create...

Introduction and setup of TensorFlow

TensorFlow (TF) has in its name the word Tensor, which is a synonym of vector. TF, thus, is a Python framework that is designed to excel at vectorial operations pertaining to the modeling of neural networks. It is the most popular library for machine learning.

As data scientists, we have a preference towards TF because it is free, opensource with a strong user base, and it uses state-of-the-art research on the graph-based execution of tensor operations.

Setup

Let us now begin with instructions to set up or verify that you have the proper setup:

  1. To begin the installation of TF, run the following command in your Colaboratory:
%tensorflow_version 2.x
!pip install tensorflow

This will install about 20 libraries that are required to run TF, including numpy, for example.

Notice the exclamation mark (!) at the beginning of the command? This is how you will run shell commands on Colaboratory. For example, say that you want to remove a file named model.h5...

Introduction and setup of Keras

If you search on the internet for sample TensorFlow code, you will find that it may not be super easy to understand or follow. You can find tutorials for beginners but, in reality, things can get complicated very easily and editing someone else's code can be very difficult. Keras comes as an API solution to develop deep learning Tensorflow model prototypes with relative ease. In fact, Keras supports running not only on top of TensorFlow, but also over CNTK and Theano.

We can think of Keras as an abstraction to actual TensorFlow models and methods. This symbiotic relationship has become so popular that TensorFlow now unofficially encourages its use for those who are beginning to use TensorFlow. Keras is very user friendly, it is easy to follow in Python, and it is easy to learn in a general sense.

Setup

To set up Keras on your Colab, do the following:

  1. Run the following command:
!pip install keras
  1. The system will proceed to install the necessary libraries...

Introduction to PyTorch

At the time of writing this book, PyTorch is the third most popular overall deep learning framework. Its popularity has been increasing in spite of being relatively new in the world compared to TensorFlow. One of the interesting things about PyTorch is that it allows some customizations that TensorFlow does not. Furthermore, PyTorch has the support of Facebook™.

Although this book covers TensorFlow and Keras, I think it is important for all of us to remember that PyTorch is a good alternative and it looks very similar to Keras. As a mere reference, here is how the exact same shallow neural network we showed earlier would look if coded in PyTorch:

import torch

device = torch.device('cpu')

model = torch.nn.Sequential(
torch.nn.Linear(10, 10),
torch.nn.ReLU(),
torch.nn.Linear(10, 8),
torch.nn.ReLU(),
torch.nn.Linear(8, 2),
torch.nn.Softmax(2)
).to(device)

The similarities are many. Also,...

Introduction to Dopamine

An interesting recent development in the world of deep reinforcement learning is Dopamine. Dopamine is a framework for the fast prototyping of deep reinforcement learning algorithms. This book will deal very briefly with reinforcement learning, but you need to know how to install it.

Dopamine is known for being easy to use for new users in the world of reinforcement learning. Also, although it is not an official product of Google, most of its developers are Googlers. In its current state, at the time of writing this book, the framework is very compact and provides ready-to-use algorithms.

To install Dopamine, you can run the following command:

!pip install dopamine-rl

You can test the correct installation of Dopamine by simply executing the following command:

import dopamine

This provides no output, unless there are errors. Usually, Dopamine will make use of a lot of libraries outside of it to allow doing many more interesting things. Right now, some of the most...

Other deep learning libraries

Besides the big two, TensorFlow and Keras, there are other competitors that are making their way in the world of deep learning. We already discussed PyTorch, but there are more. Here we talk about them briefly.

Caffe

Caffe is also a popular framework developed at UC Berkeley (Jia, Y., et.al. 2014). It became very popular in 2015-2016. A few employers still demand this skillset and scholarly articles still mention its usage. However, its usage is in decay in part due to the major success of TF and the accessibility of Keras.

For more information about Caffe, visit: https://caffe.berkeleyvision.org.

Note also the existence of Caffe2, which is developed by Facebook and is open source. It was built based on Caffe, but now Facebook has its new champion, PyTorch.

Theano

Theano was developed by Yoshua Bengio's group at the University of Montreal in 2007 (Al-Rfou, R., et.al. 2016). Theano has a relatively old user base that probably saw the rise of TF. The...

Summary

This introductory chapter showed how to set up the necessary libraries to run TensorFlow, Keras, and Dopamine. Hopefully, you will use Colabs to make things easier for you to learn. You also learned the basic mindset and design concept behind these frameworks. Although such frameworks are the most popular at the time of writing this book, there are other competitors out there, which we also introduced briefly.

At this point, you are all set to begin the journey to mastering deep learning. Our first milestone is to know how to prepare data for deep learning applications. This item is crucial for the success of the model. No matter how good the models are and how deep they are, if the data is not properly formatted or treated, it can lead to catastrophic performance results. For that reason, we will now go to Chapter 3, Preparing Data. In that chapter, you will learn how to take a dataset and prepare it for the specific task you are trying to solve with a specific type of deep...

Questions and answers

  1. Does Colab run on my personal computer?

No, it runs in the cloud, but with some skill and setup, you could connect it to your own personal cloud.

  1. Does Keras use GPUs?

Yes. Since Keras runs on TensorFlow (in the setup of this book) and TensorFlow uses GPUs, then Keras also does.

  1. What are the two main coding paradigms in Keras?

(A) Sequential model; (B) Functional API.

  1. Why do we care about Dopamine?

Because there are only a few reinforcement learning frameworks you can trust out there, and Dopamine is one of them.

References

  • Abadi, M., Barham, P., Chen, J., Chen, Z., Davis, A., Dean, J., Devin, M., Ghemawat, S., Irving, G., Isard, M., and Kudlur, M. (2016). Tensorflow: A system for large-scale machine learning. In 12th {USENIX} Symposium on Operating Systems Design and Implementation ({OSDI} 16) (pp. 265-283).
  • Paszke, A., Gross, S., Chintala, S., Chanan, G., Yang, E., DeVito, Z., Lin, Z., Desmaison, A., Antiga, L. and Lerer, A. (2017). Automatic differentiation in pytorch.
  • Castro, P. S., Moitra, S., Gelada, C., Kumar, S., and Bellemare, M. G. (2018). Dopamine: A research framework for deep reinforcement learning. arXiv preprint arXiv:1812.06110.
  • Jia, Y., Shelhamer, E., Donahue, J., Karayev, S., Long, J., Girshick, R., Guadarrama, S., and Darrell, T. (2014, November). Caffe: Convolutional architecture for fast feature embedding. In Proceedings of the 22nd ACM international conference on Multimedia (pp. 675-678). ACM.
  • Al-Rfou, R., Alain, G., Almahairi, A., Angermueller, C., Bahdanau, D., Ballas...
lock icon
The rest of the chapter is locked
You have been reading a chapter from
Deep Learning for Beginners
Published in: Sep 2020Publisher: PacktISBN-13: 9781838640859
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
Dr. Pablo Rivas

Dr. Pablo Rivas is an assistant professor of computer science at Baylor University in Texas. He worked in industry for a decade as a software engineer before becoming an academic. He is a senior member of the IEEE, ACM, and SIAM. He was formerly at NASA Goddard Space Flight Center performing research. He is an ally of women in technology, a deep learning evangelist, machine learning ethicist, and a proponent of the democratization of machine learning and artificial intelligence in general. He teaches machine learning and deep learning. Dr. Rivas is a published author and all his papers are related to machine learning, computer vision, and machine learning ethics. Dr. Rivas prefers Vim to Emacs and spaces to tabs.
Read more about Dr. Pablo Rivas