Professional Documents
Culture Documents
Source
https://towardsdatascience.com/object-detection-using-google-ai-open-images-4c908cad4a54 1/22
10/01/2019 Object Detection using Google AI Open Images – Towards Data Science
When was the last time you logged into your phone using nothing but
your face? Or clicked a sel e with some friends and used a Snapchat
lter that put some fancy dog ears on your face? Did you know that
these cool features are enabled by a fancy neural network that not only
recognizes that there is a face in the photo but also detects where the
ears should go. Your phone, in a sense, can ‘see’ you and it even knows
what you look like!
https://towardsdatascience.com/object-detection-using-google-ai-open-images-4c908cad4a54 2/22
10/01/2019 Object Detection using Google AI Open Images – Towards Data Science
For more details on the di erence in such tasks, please reference the following article.
https://towardsdatascience.com/object-detection-using-google-ai-open-images-4c908cad4a54 3/22
10/01/2019 Object Detection using Google AI Open Images – Towards Data Science
https://towardsdatascience.com/object-detection-using-google-ai-open-images-4c908cad4a54 4/22
10/01/2019 Object Detection using Google AI Open Images – Towards Data Science
A quick look at the training images revealed that certain objects had
more of a presence than others in terms of how many times they
appeared. The chart above shows the distribution of the top 43 classes.
It is clear that there is a huge disparity and it would need to be resolved
somehow. In the interest of time and money (GPU costs are high :( ) we
chose the aforementioned 43 object classes and a subset of ~ 300K
images with these objects. We had about 400 images for each object
class in the training data.
https://towardsdatascience.com/object-detection-using-google-ai-open-images-4c908cad4a54 5/22
10/01/2019 Object Detection using Google AI Open Images – Towards Data Science
608.
https://towardsdatascience.com/object-detection-using-google-ai-open-images-4c908cad4a54 6/22
10/01/2019 Object Detection using Google AI Open Images – Towards Data Science
YOLO v2 Architecture
The architecture is as shown below — it has 23 convolution layers each
with its own batch normalization, Leaky RELU activation and max
https://towardsdatascience.com/object-detection-using-google-ai-open-images-4c908cad4a54 7/22
10/01/2019 Object Detection using Google AI Open Images – Towards Data Science
pooling.
The YOLO algorithm outputs a matrix (shown below) for each of the
de ned anchor boxes-
https://towardsdatascience.com/object-detection-using-google-ai-open-images-4c908cad4a54 8/22
10/01/2019 Object Detection using Google AI Open Images – Towards Data Science
Given that we had to train the algorithm for 43 classes, we got output
dimensions of:
https://towardsdatascience.com/object-detection-using-google-ai-open-images-4c908cad4a54 9/22
10/01/2019 Object Detection using Google AI Open Images – Towards Data Science
Below is the illustration of the last few layers of the YOLO v2 architecture:
1 # Layer 20
2 x = Conv2D(1024, (3,3), strides=(1,1), padding='same', name
3 x = BatchNormalization(name='norm_20')(x)
4 x = LeakyReLU(alpha=0.1)(x)
5
6 # Layer 21
7 skip_connection = Conv2D(64, (1,1), strides=(1,1), padding=
8 skip_connection = BatchNormalization(name='norm_21')(skip_c
9 skip_connection = LeakyReLU(alpha=0.1)(skip_connection)
10 skip_connection = Lambda(space_to_depth_x2)(skip_connection
11
12 x = concatenate([skip_connection, x])
13
14 # Layer 22
15 x = Conv2D(1024, (3,3), strides=(1,1), padding='same', name
16 x = BatchNormalization(name='norm_22')(x)
17 x = LeakyReLU(alpha=0.1)(x)
18
https://towardsdatascience.com/object-detection-using-google-ai-open-images-4c908cad4a54 10/22
10/01/2019 Object Detection using Google AI Open Images – Towards Data Science
Transfer Learning
Transfer learning is the idea of obtaining a neural network that has
already been trained to classify images and using it for our speci c
purpose. This saves us computation time since we don’t need to train a
lot of weights — for instance, the YOLO v2 model we used has about 50
million weights — training which would have taken 4–5 days easily on
the Google cloud instance we were using.
https://towardsdatascience.com/object-detection-using-google-ai-open-images-4c908cad4a54 11/22
10/01/2019 Object Detection using Google AI Open Images – Towards Data Science
Cost Function
In any object detection problem, we want to identify the right object at
the right place with a high con dence in an image. There are 3 major
components to the cost function:
https://towardsdatascience.com/object-detection-using-google-ai-open-images-4c908cad4a54 12/22
10/01/2019 Object Detection using Google AI Open Images – Towards Data Science
Please feel free to refer to the original YOlO paper for a detailed look at
the cost function.
The beauty of YOLO is that it uses errors that are easy to optimize using
optimization functions such as Stochastic Gradient Descent (SGD),
SGD with momentum, or Adam etc. Below code snippet shows the
parameters we used for optimizing the cost function.
1
2 # Optimization Functions
3 optimizer = Adam(lr=0.5e-4, beta_1=0.9, beta_2=0.999, epsil
4 #optimizer = SGD(lr=1e-4, decay=0.0005, momentum=0.9)
5 #optimizer = RMSprop(lr=1e-4, rho=0.9, epsilon=1e-08, decay
6
7 model.compile(loss=custom_loss, optimizer=optimizer)
8
9 model.fit_generator(generator = train_batch,
10 steps_per_epoch = int(len(train_batch)
11 epochs = 100,
12 verbose = 1
Training algorithm for YOLO (Adam optimizer)
https://towardsdatascience.com/object-detection-using-google-ai-open-images-4c908cad4a54 13/22
10/01/2019 Object Detection using Google AI Open Images – Towards Data Science
Source
https://towardsdatascience.com/object-detection-using-google-ai-open-images-4c908cad4a54 14/22
10/01/2019 Object Detection using Google AI Open Images – Towards Data Science
Results
https://towardsdatascience.com/object-detection-using-google-ai-open-images-4c908cad4a54 15/22
10/01/2019 Object Detection using Google AI Open Images – Towards Data Science
https://towardsdatascience.com/object-detection-using-google-ai-open-images-4c908cad4a54 16/22
10/01/2019 Object Detection using Google AI Open Images – Towards Data Science
https://towardsdatascience.com/object-detection-using-google-ai-open-images-4c908cad4a54 17/22
10/01/2019 Object Detection using Google AI Open Images – Towards Data Science
Conclusion
https://towardsdatascience.com/object-detection-using-google-ai-open-images-4c908cad4a54 18/22
10/01/2019 Object Detection using Google AI Open Images – Towards Data Science
Object detection is di erent from other computer vision tasks. You can
use a pre-trained model and edit as needed to meet your needs. You’ll
prob need GCP or another platform that allows for higher computing
power. Math is hard, read others’ articles and fail fast.
Lessons Learned
In the beginning, we found that the model was not able to predict
many of the classes because many of them only had a few training
images, which caused an imbalance training dataset. Therefore, we
decided to just use the most popular 43 classes, which is not a perfect
approach, but each class had at least 500 images. However, our
predictions’ con dence scores were still pretty low. To solve this
problem, we selected images that contained our target classes.
Object detection is a very challenging topic, but don’t be scared and try
to learn as much as possible from the various open sources online, like
Coursera, YouTube instructional videos, GitHub, and Medium. All
these free wisdom can help you succeed in this amazing eld!
https://towardsdatascience.com/object-detection-using-google-ai-open-images-4c908cad4a54 19/22
10/01/2019 Object Detection using Google AI Open Images – Towards Data Science
If you’d like to take a detailed look into our team’s code, here’s the GitHub
link. Please feel free to provide any feedback or comments!
bandiatindra/Object-Detection-
Project
Contribute to bandiatindra/Object-
Detection-Project development by
creating an account on GitHub.
github.com
https://towardsdatascience.com/object-detection-using-google-ai-open-images-4c908cad4a54 20/22
10/01/2019 Object Detection using Google AI Open Images – Towards Data Science
https://towardsdatascience.com/object-detection-using-google-ai-open-images-4c908cad4a54 21/22
10/01/2019 Object Detection using Google AI Open Images – Towards Data Science
https://towardsdatascience.com/object-detection-using-google-ai-open-images-4c908cad4a54 22/22