TensorFlow Object Detection

Last updated on Oct 24 2021
Ashutosh Wakiroo

Table of Contents

TensorFlow Object Detection

Object detection is a process of discovering real-world object detail in images or videos such as cars or bikes, TVs, flowers, and humans. It allows identification, localization, and identification of multiple objects within an image, giving us a better understanding of an image. It is used in applications such as image retrieval, security, surveillance, and the Advanced Driver Assistance System (ADAS).

Applications of Object Detection

tensorFlow 40
TensorFlow

Facial Recognition:
A deep learning facial recognition system called “Deep Face” has been developed by a group of researchers on Facebook, which very effectively identifies the human face in a digital image. Google Photos, which automatically separates all pictures based on the person in the picture. Many components are involved in facial recognition, such as face, nose, mouth, and eyebrow.

TensorFlow
TensorFlow

Industrial Quality Check:
Object detection is also used in the industrial process to identify products. Finding a specific object by visual inspection is an essential task that is involved in multiple industrial processes like inventory management, machining, quality management, packaging, sorting, etc.
Inventory management is very tricky as items are hard to track in real-time. Automatic localization and object counting allows for improving inventory accuracy.

TensorFlow 1 1
TensorFlow

Self-Driving Cars:
Self-driving cars are the future cars. But the working backside is very tricky like it combines a variety of techniques to perceive its atmosphere, including radar, laser light, GPS, odometry, and computer vision.
There are advanced control systems that interpret sensory information to identify appropriate navigation paths, as well as obstacles. Once ever the image sensor detects any sign of living thing in its way, it automatically stops. This happens at a rapid rate and is a big step towards Driverless cars.

TensorFlow 1 2
TensorFlow

People Counting:
Object detection can be used for people counting, and it is used for analyzing store performance or crowd figures during festivals. It tends to be more difficult as people move out of the frame quickly.
It is a critical application during crowd gathering; this feature can be used for multiple purposes.

TensorFlow 1 3
TensorFlow

Object Detection Workflow

Every object Detection algorithm is working in different teaching, but they all work on the same principle.
Feature Extraction: They extract the features from the input images at hand and use these features to determining the class of the picture. Be it through Mat Lab, Open CV, Viola-Jones, or Deep learning.

TensorFlow 1 4
TensorFlow

Prerequisites
• Python
• TensorFlow
• Tensorboard
• Protobuf v3.4 or above

Environment set-up

Now to download TensorFlow and TensorFlow GPU, we can use pip or conda commands which we have at the start.
Complete command

1. import numpy as np 
2. import os 
3. import zipfile 
4. import six.moves.urllib as urllib 
5. import sys 
6. import tarfile 
7. import tensorflow as tf 
8. from collections import defaultdict 
9. from matplotlib import pyplot as plt 
10. from PIL import Image 
11. from io import StringIO 
12. 
13. 
14. import cv2 
15. cap = cv2.VideoCapture(0) 
16. 
17. sys.path.append("..") 
18. from utils import visualization_utils as vis_util 
19. from utils import label_map_util 
20. 
21. MODEL_NAME = 'ssd_mobilenet_v1_coco_11_06_2017' 
22. MODEL_FILE = MODEL_NAME + '.tar.gz' 
23. DOWNLOAD_BASE = '<a href="http://download.tensorflow.org/models/object_detection/">http://download.tensorflow.org/models/object_detection/</a>' 
24. 
25. # Here, the path to frozen detection graph. 
26. PATH_TO_CKPT = MODEL_NAME + '/frozen_inference_graph.pb' 
27. 
28. # Here, list of the strings that are used to add a correct label for every box. 
29. PATH_TO_LABELS = os.path.join('data', 'mscoco_label_map.pbtxt') 
30. 
31. NUM_CLASSES = 90 
32. 
33. opener = urllib.request.URLopener() 
34. opener.retrieve(DOWNLOAD_BASE + MODEL_FILE, MODEL_FILE) 
35. tar_file = tarfile.open(MODEL_FILE) 
36. for file in tar_file.getmembers(): 
37. file_name = os.path.basename(file.name) 
38. if 'frozen_inference_graph.pb' in file_name: 
39. tar_file.extract(file, os.getcwd()) 
40. 
41. detection_graph = tf.Graph() 
42. with detection_graph.as_default(): 
43. od_graph_def = tf.GraphDef() 
44. with tf.gfile.GFile(PATH_TO_CKPT, 'rb') as fid: 
45. serialized_graph = fid.read() 
46. od_graph_def.ParseFromString(serialized_graph) 
47. tf.import_graph_def(od_graph_def, name='') 
48. 
49. label_map = label_map_util.load_labelmap(PATH_TO_LABELS) 
50. categories =label_map_util.convert_label_map_to_categories(label_map, max_num_classes=NUM_CLASSES, use_display_name=True) 
51. category_index = label_map_util.create_category_index (categories) 
52. 
53. with detection_graph.as_default(): 
54. with tf.Session(graph=detection_graph) as sess: 
55. while True: 
56. ret, image_np = cap.read() 
57. # Expanding the dimensions since the model expects images into the shape: [1, None, None, 3] 
58. image_np_expanded = np.expand_dims(image_np, axis=0) 
59. image_tensor = detection_graph.get_tensor_by_name('image_tensor:0') 
60. # Every box representing a part of the image where a particular object was detected. 
61. boxes = detection_graph.get_tensor_by_name('detection_boxes:0') 
62. scores = detection_graph.get_tensor_by_name('detection_scores:0') 
63. classes = detection_graph.get_tensor_by_name('detection_classes:0') 
64. num_detections = detection_graph.get_tensor_by_name('num_detections:0') 
65. #. 
66. (boxes, scores, classes, num_detections) = sess.run( 
67. [boxes, scores, classes, num_detections], 
68. feed_dict={image_tensor: image_np_expanded}) 
69. # Visualization of the results through detection. 
70. vis_util.visualize_boxes_and_labels_on_image_array( 
71. image_np, 
72. np.squeeze(boxes), 
73. np.squeeze(classes).astype(np.int32), 
74. np.squeeze(scores), 
75. category_index, 
76. use_normalized_coordinates=True, 
77. line_thickness=8) 
78. 
79. cv2.imshow('object detection', cv2.resize(image_np, (800,500))) 
80. if cv2.waitKey(0) & 0xFF == ord('q'): 
81. cv2.destroyAllWindows() 
82. break

Output-

TensorFlow 1 5
TensorFlow

So, this brings us to the end of blog. This Tecklearn ‘TensorFlow Object Detection’ blog helps you with commonly asked questions if you are looking out for a job in Artificial Intelligence. If you wish to learn Artificial Intelligence and build a career in AI or Machine Learning domain, then check out our interactive, Artificial Intelligence and Deep Learning with TensorFlow Training, that comes with 24*7 support to guide you throughout your learning period. Please find the link for course details:

https://www.tecklearn.com/course/artificial-intelligence-and-deep-learning-with-tensorflow/

Artificial Intelligence and Deep Learning with TensorFlow Training

About the Course

Tecklearn’s Artificial Intelligence and Deep Learning with Tensor Flow course is curated by industry professionals as per the industry requirements & demands and aligned with the latest best practices. You’ll master convolutional neural networks (CNN), TensorFlow, TensorFlow code, transfer learning, graph visualization, recurrent neural networks (RNN), Deep Learning libraries, GPU in Deep Learning, Keras and TFLearn APIs, backpropagation, and hyperparameters via hands-on projects. The trainee will learn AI by mastering natural language processing, deep neural networks, predictive analytics, reinforcement learning, and more programming languages needed to shine in this field.

Why Should you take Artificial Intelligence and Deep Learning with Tensor Flow Training?

• According to Paysa.com, an Artificial Intelligence Engineer earns an average of $171,715, ranging from $124,542 at the 25th percentile to $201,853 at the 75th percentile, with top earners earning more than $257,530.
• Worldwide Spending on Artificial Intelligence Systems Will Be Nearly $98 Billion in 2023, According to New IDC Spending Guide at a GACR of 28.5%.
• IBM, Amazon, Apple, Google, Facebook, Microsoft, Oracle and almost all the leading companies are working on Artificial Intelligence to innovate future technologies.

What you will Learn in this Course?

Introduction to Deep Learning and AI
• What is Deep Learning?
• Advantage of Deep Learning over Machine learning
• Real-Life use cases of Deep Learning
• Review of Machine Learning: Regression, Classification, Clustering, Reinforcement Learning, Underfitting and Overfitting, Optimization
• Pre-requisites for AI & DL
• Python Programming Language
• Installation & IDE
Environment Set Up and Essentials
• Installation
• Python – NumPy
• Python for Data Science and AI
• Python Language Essentials
• Python Libraries – Numpy and Pandas
• Numpy for Mathematical Computing
More Prerequisites for Deep Learning and AI
• Pandas for Data Analysis
• Machine Learning Basic Concepts
• Normalization
• Data Set
• Machine Learning Concepts
• Regression
• Logistic Regression
• SVM – Support Vector Machines
• Decision Trees
• Python Libraries for Data Science and AI
Introduction to Neural Networks
• Creating Module
• Neural Network Equation
• Sigmoid Function
• Multi-layered perception
• Weights, Biases
• Activation Functions
• Gradient Decent or Error function
• Epoch, Forward & backword propagation
• What is TensorFlow?
• TensorFlow code-basics
• Graph Visualization
• Constants, Placeholders, Variables
Multi-layered Neural Networks
• Error Back propagation issues
• Drop outs
Regularization techniques in Deep Learning
Deep Learning Libraries
• Tensorflow
• Keras
• OpenCV
• SkImage
• PIL
Building of Simple Neural Network from Scratch from Simple Equation
• Training the model
Dual Equation Neural Network
• TensorFlow
• Predicting Algorithm
Introduction to Keras API
• Define Keras
• How to compose Models in Keras
• Sequential Composition
• Functional Composition
• Predefined Neural Network Layers
• What is Batch Normalization
• Saving and Loading a model with Keras
• Customizing the Training Process
• Using TensorBoard with Keras
• Use-Case Implementation with Keras
GPU in Deep Learning
• Introduction to GPUs and how they differ from CPUs
• Importance of GPUs in training Deep Learning Networks
• The GPU constituent with simpler core and concurrent hardware
• Keras Model Saving and Reusing
• Deploying Keras with TensorBoard
Keras Cat Vs Dog Modelling
• Activation Functions in Neural Network
Optimization Techniques
• Some Examples for Neural Network
Convolutional Neural Networks (CNN)
• Introduction to CNNs
• CNNs Application
• Architecture of a CNN
• Convolution and Pooling layers in a CNN
• Understanding and Visualizing a CNN
RNN: Recurrent Neural Networks
• Introduction to RNN Model
• Application use cases of RNN
• Modelling sequences
• Training RNNs with Backpropagation
• Long Short-Term memory (LSTM)
• Recursive Neural Tensor Network Theory
• Recurrent Neural Network Model
Application of Deep Learning in image recognition, NLP and more
Real world projects in recommender systems and others
Got a question for us? Please mention it in the comments section and we will get back to you.

 

0 responses on "TensorFlow Object Detection"

Leave a Message

Your email address will not be published. Required fields are marked *