Merry Christmas
TECHNOLOGICAL INNOVATION FOR HUMANITY

Convolutional Neural Network for Object Recognition and Detection

written by Antonius - roboticist, hardware hacker & low level hacker based in Indonesia
robohax.com - technological innovation for humanity
date : July 12 2019
https://medium.com/@ringlayer/convolutional-neural-network-for-object-recognition-and-detection-126a22af8975

Basically computer vision has 4 main tasks :

1. Object Recognition/Classification

Classify the object in the image.

2.Object Detection

Are there any object that we want to detect in the image? If yes, draw the bounding box around the image

3. Object Localization

Are there any object that we want to detect in the image? If yes, draw the bounding box around the image and show the coordinates of the bounding box.

The (x1, y1) would be the top left corner and the (x2, y2) the bottom right.

And finally … the latest one :

4. Object Segmentation

By accommodating mask rcnn, we can get the exact pixel position for each object. This kind of development is very important for robotic vision.

Suppose you have a small robot

Press enter or click to view image in full size

And we need to instruct the robot to get passes through this woman between her tiny legs. By using mask rcnn, the robot knows the exact position of her legs.

This kind of trick can not be accomplished by object localization which uses bounding box since we need to know exact position of her leg.

Currently, The most suitable type of neural network to perform those 4 tasks is “convolutional neural network”.

Previously on my post, I wrote about “Cardboard Box Detection using Retinanet (Keras)”, it’s about train a custom model on keras retinanet for cardboard localization in the image. RetinaNet is a convolutional neural network architecture.

Convolutional neural network is commonly used in computer vision for object detections, object localizations, object recognitions, analyzing depth of image regions, etc…

This post will cover about convolutional neural network in general, including some maths of convnet, convnet architecture and then continue with RetinaNet architecture.

Convolutional Neural Network

“A convolutional neural network is a class of deep neural networks, most commonly applied to analyzing visual imagery. CNN is an improved version of multilayer perceptron”. It’s a class of deep neural network inspired by human’s visual cortex.

Basically CNN works by collecting matrix of features then predicting whether this image contains a class or another class based on these features using softmax probabilities.

Convolutional Neural Network Architecture

Commonly, a convolutional neural network architecture consists of these layers :

1.Convolution Layer

The core idea between convolutional operation is for feature extractions or we can say filtering. Later, the network will be trying every possible matching features from the input image compared to the class’s image (class is an object name that we want to recognize, e.g : a car).

In order to get enlightenment of how convolutional layer operate, have a look at above image. Based from the above picture we have an input image of 6×6 px, and we have a 3×3 px 2d convolution kernel. The kernel will do 1 stride from top left pixel of the image until the bottom of the image. The kernel is a 3×3 matrix of weight (each component of the matrix is a weight). This convolutional operation is used to extract features from image. The most frequently used kernel for convolutional is 2d convolution kernel.

Suppose we have a 6×6 pixel image with RGB color channel.

Suppose we are going to do a convolutional operation using 3×3 matrix as kernel and stride = 1 (the number of strides defines how many pixels the kernel will step).

Here’s the RGB channel in 6×6 matrix extracted from numpy array :

#!/usr/bin/env python3
from PIL import Image
import numpy as np
im = Image.open(“6px.png”)
imgarr = np.array(im)
print(“R channel”)
print(imgarr[:,:,0])
print(“_” * 30)
print(“G channel”)
print(imgarr[:,:,1])
print(“_” * 30)
print(“B channel”)
print(imgarr[:,:,2])
print(“_” * 30)

For this example, we are going to do a 1 stride convolutional operation on red channel using this 3×3 matrix of weight (sobel) :

As an example of convolutional operation, we are going to use “The Red Channel” matrix :

Here’s the mathematical operation using convolutional operation :

#!/usr/bin/env python3
res = (46 * -1) + (67 * 0) + (161 * 1)+ (48 * -2) + (41 * 0) + (114 * 2) + (101 * -1 ) + (165 * 0 ) + (216 * 1)

print(res)

The next 1 pixel stride :

and so on, the stride will continue until the last pixel.

The result is called convolved feature map matrix.

Since the matrix is only 4×4 pixel, There will be 2 pixel padding for bottom, right, top and left.

The Linearity

Algebraically, a convolutional operation is a linear combination. We need to introduce non linearity hence an activation function is needed. Right after the convolutional operation, in order to introduce non linearity, the “ReLU” activation function is used. If we keep it linear, we do not need to use deep learning since it’s just a simple linear functions.

Mathematically, ReLU can be defined as

After ReLU, all negative pixel value from the previous convolved feature map matrix with negative pixel value will be replaced by 0.

Why Non Linearity is Needed ?

In Math and statistic, a non linearity is commonly used to solve complex problem, meanwhile a linear equation is simple, if we define the input of a linear equation, the output can be found by simple algebra. Before we use activation function such as ReLU, basically the convolutional operation is only a linear function.

Consider an example of a simple this linear equation :

Y = a.x

No matter how many layers, the final activation function will always yield the exact same predicted output. In this condition we do not need to use deep learning with many layers, a simple one layer neural network is enough.

By using ReLU activation function right after a convolutional operation, we can introduce the non linearity hence the system can learn how to solve more complex problem.

Real-life image recognition is a complex problem which can’t be solved literally by computer.

For example we have trained our single layer neural network using dataset of cars and dataset of bat logos:

class 1 is honda civic

class 2 is bat logo

Then if we give an input image with something like this (the same image resolution with dataset)

The computer will be able to answer the correct prediction since it’s just answering a literally just the same image with the same pixels arrangement.

Unfortunately when we give this input image :

The computer will not be able to vote correctly whether this one is a bat logo or a honda civic class.

In order to solve this kind of complex problem (since the object in image might be rotated slightly or having a different pose or a bit different form) the ideal neural network to solve this one need a non linearity.

By having a different pose or a slightly different form, this means that the prediction can not by simply solved by a linear regression, since

Y is no longer a.X hence we need to solve this using a non linear equation.

In convolutional neural network, we would update the weights and biases of the neurons on the basis of the error at the output. This process is known as back-propagation. Activation functions will introduce non linearity to the system thus making the back-propagation possible since the gradients are supplied along with the error / loss to update the weights and biases.

2. Pooling Layer

Right after the ReLU, the next layer is a pooling layer. The pooling layer basically is used to reduce the spatial size of the input hence reducing the number of parameters and computational complexity.

Commonly used pooling method is max pooling.

3. Fully Connected Layer

The Fully Connected layer holds composite and aggregate information from previous layers. Before given as input of fully connected layers, those previous multi dimensional inputs will be flatten into a single dimensional inputs.

And finally, the prediction (voting) will be accomplished using the activation function, e.g : softmax.

Some Examples of CNN Architectures

 

Lenet

The input image of lenet 5 is 32×32 px image. Here’s the summary of lenet 5 architecture :

Other than using tanh activation function, we can use ReLU as activation function.

Here’s example of lenet implementation in keras :

import keras
from keras.models import Sequential
from keras import models, layers
model = keras.Sequential()
model.add(layers.Conv2D(filters=6, kernel_size=(3, 3), activation='tanh', input_shape=(32,32,1)))
model.add(layers.AveragePooling2D())
model.add(layers.Conv2D(filters=16, kernel_size=(3, 3), activation='tanh'))
model.add(layers.AveragePooling2D())
model.add(layers.Flatten())
model.add(layers.Dense(units=120, activation='tanh'))
model.add(layers.Dense(units=84, activation='tanh'))
model.add(layers.Dense(units=10, activation = 'softmax'))
model.summary()

VGG16

The input image of vgg16 is 224×224 px. Here’s the summary of vgg16 architecture :

Example of implementation of vgg16 in keras :

#!/usr/bin/env python3
import keras
from keras.models import Sequential
from keras.layers import Dense, Activation, Dropout, Flatten
from keras.layers import Conv2D
from keras.layers import MaxPooling2D
from keras import models, layers
model = keras.Sequential()
model.add(layers.Conv2D(filters=64, kernel_size=(3, 3), activation='relu', input_shape=(224,224,3)))
model.add(layers.Conv2D(64, (3, 3), activation='relu', padding='same'))
model.add(layers.MaxPooling2D(pool_size=(2, 2), strides=(2, 2)))
model.add(layers.Conv2D(128, (3, 3),activation='relu',padding='same'))
model.add(layers.Conv2D(128, (3, 3), activation='relu', padding='same'))
model.add(layers.MaxPooling2D((2, 2), strides=(2, 2)))
model.add(layers.Conv2D(256, (3, 3), activation='relu', padding='same'))
model.add(layers.Conv2D(256, (3, 3), activation='relu', padding='same'))
model.add(layers.Conv2D(256, (3, 3), activation='relu',padding='same'))
model.add(layers.MaxPooling2D((2, 2), strides=(2, 2)))
model.add(layers.Conv2D(512, (3, 3),activation='relu',padding='same'))
model.add(layers.Conv2D(512, (3, 3),activation='relu', padding='same'))
model.add(layers.Conv2D(512, (3, 3),activation='relu',padding='same'))
model.add(layers.MaxPooling2D((2, 2), strides=(2, 2)))
model.add(layers.Conv2D(512, (3, 3), activation='relu', padding='same'))
model.add(layers.Conv2D(512, (3, 3), activation='relu', padding='same'))
model.add(layers.Conv2D(512, (3, 3), activation='relu', padding='same'))
model.add(layers.MaxPooling2D((2, 2), strides=(2, 2)))
model.add(layers.Flatten())
model.add(layers.Dense(4096, activation='relu'))
model.add(layers.Dense(4096, activation='relu'))
model.add(layers.Dense(1000, activation='softmax'))
model.summary()

Resnet

The main purpose of resnet architecture is to make a convolutional neural network with many layers to train effectively.

The problem of a deep convolutional neural network is that when we increase the network depth, there’s a vanishing gradient problem. As the network goes deeper, its performance gets saturated or even starts degrading in accuracy.

Resnet splits a deeper network into three layer chunks and passing the input into each chunk straight through to the next chunk, along with the residual output of the chunk minus the input to the chunk that is reintroduced.

An implementation of resnet from keras :

https://github.com/raghakot/keras-resnet/blob/master/resnet.py

RetinaNet

The problem with a single shot detection model such as yolo is : “there is extreme foreground-background class imbalance problem in one-stage detector.”

RetinaNet introduce “The Focal Loss” to cover for extreme foreground-background class imbalance problem in one-stage detector.

Press enter or click to view image in full size

Retinanet is a single shot detection model just like Yolo. On RetinaNet, a commonly used backbone is resnet50, we add a FPN (Feature Pyramid Network) for feature extraction and later the network will use Focal lost to handle extreme foreground-background class imbalance problem.

Example implementation of RetinaNet using keras can be cloned from https://github.com/fizyr/keras-retinanet

Example of custom object detection using Retinanet :

Press enter or click to view image in full size

 

Reference : https://arxiv.org/html/1708.02002v2

Productions (Total : 5)

Inventions Robots Electronics Gadgets Circuit Design AI IOT Electrical
RoboMall - A Teleoperated Mall Robot by Robotsoft
inventions
RoboMall - A Teleoperated Mall Robot by Robotsoft

RoboMall was developed by Antonius (w1sdom) in 2023, The robot was designed to be operated in a mall. The purpose is that mall visitors doesn't need to visit mall directly, instead, they can use this robot to stroll in a mall and if they deposit in RoboMall wallet system they can buy things on mall, then the goods will be delivered by couriers.

iot
Robotsoft LightBox - IOT Lightning

Robotsoft LightBox is a solar powered outdoor lighting. Features : water proof, controlled by voice & android application. This product was created by Antonius (w1sdom). This product was created for his startup Robotsoft in 2020.

iot
Robotsoft FloorLight - IOT Lightning

Robotsoft FloorLight is a solar powered outdoor lighting. Features : water proof, controlled by voice & android application. This product was created by Antonius (w1sdom). This product was created for his startup Robotsoft in 2020.

iot
Robotsoft Torch - IOT Lightning

Robotsoft Torch is a solar powered outdoor lighting. Features : water proof, controlled by voice & android application. This product was created by Antonius (w1sdom). This product was created for his startup Robotsoft in 2020.

electrical
Robotsoft Solar - Solar Powered Electrical Generator

Solar Powered Electrical Generator. This generator created by Antonius (w1sdom). This product created for his startup Robotsoft in 2020.

Show All

Prototypes (Total : 6)

Inventions Robots Electronics Gadgets Circuit Design AI IOT Electrical
INVENTIONS PROTOTYPE
Haxtronic - My First Generation Hacker Robot - Developed in 2014

The first hacker robot that I created. This robot was developed in 2014. Some demo videos were posted in Youtube around 2016. This robot can explains about low level exploitation techniques. Robot skills : can hack wifi (wpa cracking using aircrack), evil twin, wifi deauth, arp cache poisoning. My old video channel --> https://www.youtube.com/@antoniusringlayer/videos

ROBOTS PROTOTYPE
Inem Robot

I planned to develop a spy robot, but this robot was too big. The chassis was created using metals. Developed in 2017, posted in youtube around 2019. Developed by Antonius (w1sdom)

Airhax Wireless Network Auditor Device
HACKER GADGET PROTOTYPE
Airhax Wireless Network Auditor Device

Airhax is a wireless network auditor gadget. This device was created in 2015. This gadget functions : wifi cracking, evil twin, wifi deauth, arp poisoning. Developed by Antonius (w1sdom / sw0rdm4n / ev1lut10n / robotsoft)

ROBOTS PROTOTYPE
Ultrasonic Robot

I built this robot in 2014. It is a shy robot that is afraid of humans. I used 3 ultrasonic sensors.

ROBOTS PROTOTYPE
Giant Robot

A large-scale prototype robot powered by a mini PC and an Arduino, built as a personal project rather than a commercial product. At first, I planned to equip it with high-torque servos and an airsoft gun, but I realized that could be dangerous, so I scrapped the idea. Real hacking should be harmless. Build 2017 - by Prof. Antonius Robotsoft

Various Robots (finished and unfinished)
ROBOTS PROTOTYPE
Various Robots (finished and unfinished)

Various Robots (finished and unfinished) - build by Antonius Robotsoft (w1sdom).

Show All

Videos (Total : 0)

Show All

Blog (Total : 25)

Inventions Robotics Electronics Math & Physics Artificial Intelligence Electrical Computer >> more
ELECTRONICS
Identifying Resistor Value

A short guide on identifying resistor value. This post was taken from my old blog post : https://sw0rdm4n.wordpress.com/2014/12/06/identifying-resistor-value/

ELECTRONICS
Controlling Many Servo(s) Using IC TLC5940

Tlc5940 is a 16 channel led driver. Since this IC has pwm control ability we can use this IC for controlling up to 16 servo(s).

MATHEMATICS-PHYSICS
Forward Kinematics Calculation for Robotic Arm

Kinematics is a branch of mathematics, physics and classic mechanical engineering. There are 2 mostly used kinematics in robotic field, they are : forward kinematics and inverse kinematics. Forward kinematics is frequently used to calculate the position of end effector when we know the degree value of each joint, meanwhile inverse kinematics is used to compute the degree of each joint when we know the position of the end effector.

ROBOTICS
Haxtronic Robot Development in 2013-2015

This post was taken from my old blog post in 2015. Haxtronic was my first generation hacker robot that I built from 2013-2015

MATHEMATICS-PHYSICS
Matrix Determinant - Laplace and Sarrus Method

An introduction to matrix determinants in linear algebra, explaining how to calculate determinants using Sarrus' rule and Laplace expansion through step-by-step mathematical examples.

MATHEMATICS-PHYSICS
Regular Matrix Inverse and Pseudoinverse Using Singular Value Decomposition (SVD)

A step-by-step guide to calculating matrix inverses and Moore-Penrose pseudoinverses using the adjugate method and Singular Value Decomposition (SVD), with manual calculations, Python NumPy implementations, and applications in robotic inverse kinematics.

MATHEMATICS-PHYSICS
Calculus 3 - First Order Partial Derivatives

An introduction to first-order partial derivatives in multivariable calculus, featuring step-by-step calculations for functions of two and three variables and their relevance to Jacobian matrices and robotic inverse kinematics.

ARTIFICIAL INTELLIGENCE
Convolutional Neural Network for Object Recognition and Detection

An exploration of Convolutional Neural Networks (CNNs) for object recognition and detection, covering mathematical foundations, feature extraction, activation functions, and popular deep learning architectures such as LeNet, VGG16, ResNet, and RetinaNet, with practical Python and Keras examples.

ARTIFICIAL INTELLIGENCE
Cardboard Box Detection and Localization using RetinaNet (Keras)

In this guide, we are going to train a model using keras retinanet to detect and localize a custom object : “cardboard box” from the image.

ARTIFICIAL INTELLIGENCE
Convolutional Operation in Convolutional Neural Network

Technical guide on convolutional operations behind convolutional neural network.

ELECTRONICS
Switch Based on Contact (SPST, SPDT, DPST, DPDT)

An introduction to four common types of electrical switches (SPST, SPDT, DPST, and DPDT), explaining their contact configurations, operating principles, and practical applications through simple diagrams and real-world examples.

ELECTRONICS
Motor DC Control (1 direction only) Using ULN2803 (Darlington Array Transistor)

This tutorial is about motor dc control using uln2803 ic. Taken from my old blog post.

Show All
ABOUT
Technological Innovation for Humanity

Robohax is dedicated to provide creative, innovative technological innovations that benefits humanity.

Our projects range from autonomous robots, electronic devices and IoT devices for commercial / business to custom robots & hacking gadgets for physical penetration testing.

DISCIPLINES
What We Do
  • Robotics for Business
  • Technology inventions
  • IoT Devices
  • Electronics Prototyping
  • Robotics for Penetration Testing
  • Robotics for Exploitation
  • Custom Hacking Gadgets
  • Hardware Reverse Engineering
THE FOUNDER

Robohax was founded by Antonius. Antonius (w1sdom) is a roboticist, technology inventor, hardware hacker, low level hacker & electronic engineer based in Indonesia.

INVENTIONS

Robomall (2023)
RoboHax is a teleoperated robot that allows shoppers to visit shopping malls without having to be there in person. Users can remotely navigate the mall, browse storefronts, explore products, and shop as if they were physically there. To make purchases, users can add funds to their RoboWallet, and their purchases will be delivered to their doorstep through an on-demand courier service.

Haxtronic (2014)
The concept behind the world's first hacking robot, designed to perform WPA cracking, Evil Twin Wi-Fi attacks, and Wi-Fi deauthentication. The robot is also equipped with Artificial Narrow Intelligence (ANI) specialized in cybersecurity, enabling it to explain low-level exploitation concepts and techniques. Natural language processing is powered by the Natural Language Toolkit (NLTK).

NOTABLE RECORDS

The first hacker from Indonesia who confirmed to have written a paper for Phrack.
Paper : UAF Exploitation in The Sheaves Era

This paper presents a novel heap-based use-after-free exploitation technique for the Linux 7.0 kernel, developed by Antonius (w1sdom).

Sitemap

PRODUCTIONS
Finished Projects

Completed robots, electronics, hacking gadgets and other hardware projects.

PROTOTYPES
Work in Progress

Prototypes and experimental builds currently in development.

VIDEOS
Video Content

Demos, tutorials and project walkthroughs.

BLOG
Articles & Write-ups

Technical write-ups on robotics, electronics, hacking gadgets and more.

ABOUT
About RoboHax

Profile, disciplines and links.

Contact

Pm me on
My Linkedin

Order

You want a custom robot or gadget ?
Pm me on
My Linkedin

Home Productions Prototypes Videos Blog Order About Contact
RoboHax ScorpioGuard BlueDragonSec