Reader small image

You're reading from  Mastering OpenCV 4 with Python

Product typeBook
Published inMar 2019
Reading LevelExpert
PublisherPackt
ISBN-139781789344912
Edition1st Edition
Languages
Tools
Right arrow
Author (1)
Alberto Fernández Villán
Alberto Fernández Villán
author image
Alberto Fernández Villán

Alberto Fernndez Villn is a software engineer with more than 12 years of experience in developing innovative solutions. In the last couple of years, he has been working in various projects related to monitoring systems for industrial plants, applying both Internet of Things (IoT) and big data technologies. He has a Ph.D. in computer vision (2017), a deep learning certification (2018), and several publications in connection with computer vision and machine learning in journals such as Machine Vision and Applications, IEEE Transactions on Industrial Informatics, Sensors, IEEE Transactions on Industry Applications, IEEE Latin America Transactions, and more. As of 2013, he is a registered and active user (albertofernandez) on the Q&A OpenCV forum.
Read more about Alberto Fernández Villán

Right arrow

Introduction to Deep Learning

Nowadays, deep learning is the most popular and fastest growing area in machine learning. Deep learning has been surpassing traditional approaches for machine learning applications since 2012. This is the reason why a lot of deep learning architectures have been applied to a great number of fields, including computer vision. Common applications of deep learning include automatic speech recognition, image recognition, visual art processing, natural language processing, recommendation systems, bioinformatics, and image restoration. Most modern deep learning architectures are based on an artificial neural network, and the deep in deep learning refers to the number of layers of the architecture.

In this chapter, you will be introduced to deep learning by looking at the differences with traditional machine learning approaches, which were covered in the...

Technical requirements

The technical requirements are listed here:

  • Python and OpenCV
  • Python-specific IDE
  • NumPy and Matplotlib packages
  • Git client
  • TensorFlow library (see the following section on how to install TensorFlow)
  • Keras library (see the following section on how to install Keras)

Further details about how to install these requirements are covered in Chapter 1, Setting Up OpenCV. The GitHub repository for Mastering OpenCV 4 with Python, which contains all the supporting project files necessary to work through the book from the first chapter to the last, can be accessed in https://github.com/PacktPublishing/Mastering-OpenCV-4-with-Python.

Installing TensorFlow

Deep learning overview for computer vision tasks

Deep learning added an impressive boost to the field of computer vision. In this section of the chapter, some key concepts are tackled in order to introduce you to the world of deep learning.

Deep learning characteristics

Deep learning has some key differences when compared with traditional machine learning approaches. Additionally, deep learning techniques surpass machine learning in many computer vision tasks, but some key considerations should be taken into account in order to know when to apply each technique to accomplish a certain computation task. All of these considerations are briefly summarized as follows:

  • Deep learning algorithms need to have a high-end infrastructure...

Deep learning in OpenCV

Since OpenCV 3.1, there has been a deep neural networks (DNN) module in the library, implementing forward pass (inferencing) with deep networks, pre-trained using some popular deep learning frameworks, such as Caffe (http://caffe.berkeleyvision.org/), TensorFlow (https://www.tensorflow.org/), Torch/Pytorch (http://torch.ch/), Darknet (https://pjreddie.com/darknet/), and models in ONNX (https://onnx.ai/) format. In OpenCV 3.3, the module has been promoted from an opencv_contrib repository to the main repository (https://github.com/opencv/opencv/tree/master/modules/dnn) and has been accelerated significantly. Therefore, since OpenCV 3.3, pre-trained networks can be used to make a prediction within our application, and many of the popular network architectures, which were introduced in the previous section, are compatible with OpenCV 3.3.

In this section...

The TensorFlow library

TensorFlow is an open source software platform for machine learning and deep learning that was developed by the Google Brain team for internal use. Later on, TensorFlow was released under the Apache license in 2015. In this section, we will see some examples in order to introduce you to the TensorFlow library.

Introduction example to TensorFlow

The TensorFlow library represents the computation to perform by linking operations into a computation graph. Once this computation graph is created, you can open a TensorFlow session and execute the computation graph to get the results. This procedure can be seen in the tensorflow_basic_op.py script, which performs a multiplication operation defined inside a computation...

The Keras library

Keras (https://keras.io/) is an open source, high-level neural network API written in Python (compatible with Python 2.7-3.6). It is capable of running on top of TensorFlow, Microsoft Cognitive Toolkit, Theano, or PlaidML, and was developed with a focus on enabling fast experimentation. In this section, we are going to see two examples. In the first example, we are going to see how to solve a linear regression problem using the same input data as the TensorFlow example in the previous section. In the second example, we will classify some handwritten digits using the MNIST dataset in the same way we also performed in the previous section with TensorFlow. This way, you can clearly see the differences between the two libraries when solving the same kind of problems.

...

Summary

In this chapter, we have performed an introduction to deep learning using some popular libraries, including OpenCV, TensorFlow, and Keras. In the first part of the chapter, we looked at an overview of the state-of-the-art deep learning architectures for both image classification and object detection. In the second part, we looked at deep learning modules in OpenCV that provide a DNN library implementing forward pass (inferencing) with deep networks that have been pre-trained by using some popular deep learning frameworks. Therefore, since OpenCV 3.3, pre-trained networks can be used to make a prediction within our application. Later on in this chapter, we had an introduction to TensorFlow, and, finally, we had an introduction to Keras.

In the next chapter, we will have an introduction to both mobile and web computer vision. More specifically, we will see how to create...

Questions

  1. What are the three main differences between machine learning and deep learning stated at the beginning of this chapter?
  2. What year is considered the explosion of deep learning?
  3. What does the following function perform?
    blob = cv2.dnn.blobFromImage(image, 1.0, (300, 300), [104., 117., 123.], False, False)
  4. What do the following lines perform?
net.setInput(blob)
preds = net.forward()
  1. What is a placeholder in TensorFlow?
  2. When saving a model using saver.save() in TensorFlow, what four files are created?
  3. What is the meaning of one-hot encoding?
  4. What is a sequential model in Keras?
  5. What is the purpose of model.fit() in Keras?

Further reading

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Mastering OpenCV 4 with Python
Published in: Mar 2019Publisher: PacktISBN-13: 9781789344912
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
Alberto Fernández Villán

Alberto Fernndez Villn is a software engineer with more than 12 years of experience in developing innovative solutions. In the last couple of years, he has been working in various projects related to monitoring systems for industrial plants, applying both Internet of Things (IoT) and big data technologies. He has a Ph.D. in computer vision (2017), a deep learning certification (2018), and several publications in connection with computer vision and machine learning in journals such as Machine Vision and Applications, IEEE Transactions on Industrial Informatics, Sensors, IEEE Transactions on Industry Applications, IEEE Latin America Transactions, and more. As of 2013, he is a registered and active user (albertofernandez) on the Q&A OpenCV forum.
Read more about Alberto Fernández Villán