0% found this document useful (0 votes)
18 views4 pages

Ex No 06

Uploaded by

Jeevan Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views4 pages

Ex No 06

Uploaded by

Jeevan Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Object Detection Using YOLO

Object Detection Using YOLO


Exp. No.:
Date:
AIM: Implement Object Detection Using YOLO.
PROBLEM DESCRIPTION:

Object detection is a computer vision task that involves identifying and locating objects in
images or videos. It is an important part of many applications, such as surveillance, self-driving
cars, or robotics. Object detection algorithms can be divided into two main categories: single-shot
detectors and two-stage detectors.
You Only Look Once (YOLO) proposes using an end-to-end neural network that makes
predictions of bounding boxes and class probabilities all at once. It differs from the approach taken
by previous object detection algorithms, which repurposed classifiers to perform detection.
Following a fundamentally different approach to object detection, YOLO achieved state-of-the-art
results, beating other real-time object detection algorithms by a large margin.While algorithms like
Faster RCNN work by detecting possible regions of interest using the Region Proposal Network
and then performing recognition on those regions separately, YOLO performs all of its predictions
with the help of a single fully connected layer.

How does YOLO work? YOLO Architecture


The YOLO algorithm takes an image as input and then uses a simple deep convolutional neural
network to detect objects in the image. The architecture of the CNN model that forms the
backbone of YOLO is shown below

The first 20 convolution layers of the model are pre-trained using ImageNet by plugging in
a temporary average pooling and fully connected layer. Then, this pre-trained model is converted

Dept of IT GIET Engineering College, Rajahmundry


21
Object Detection Using YOLO

to perform detection since previous research showcased that adding convolution and connected
layers to a pre-trained network improves performance. YOLO’s final fully connected layer
predicts both class probabilities and bounding box coordinates.
YOLO divides an input image into an S × S grid. If the center of an object falls into a grid
cell, that grid cell is responsible for detecting that object. Each grid cell predicts B bounding boxes
and confidence scores for those boxes. These confidence scores reflect how confident the model is
that the box contains an object and how accurate it thinks the predicted box is.
YOLO predicts multiple bounding boxes per grid cell. At training time, we only want one
bounding box predictor to be responsible for each object. YOLO assigns one predictor to be
“responsible” for predicting an object based on which prediction has the highest current IOU with
the ground truth. This leads to specialization between the bounding box predictors. Each predictor
gets better at forecasting certain sizes, aspect ratios, or classes of objects, improving the overall
recall score.

SOFTWARE REQUIRED:
 Ubuntu 14.04, 64 bit
 Tensorflow deep learning framework and Python language
 GPU: Nvidia GTX 750, 4GB

PROGRAM:
import cv2
import numpy as np

# Load YOLOv3 model


net = cv2.dnn.readNet("yolov3.weights", "yolov3.cfg")

# Load classes (COCO dataset)


classes = []
with open("coco.names", "r") as f:
classes = f.read().strip().split("\n")

# Load image
image = cv2.imread("image.jpg")

Dept of IT GIET Engineering College, Rajahmundry


22
Object Detection Using YOLO

height, width = image.shape[:2]

# Preprocess image for YOLO


blob = cv2.dnn.blobFromImage(image, 1/255.0, (416, 416), swapRB=True, crop=False)
net.setInput(blob)

# Perform object detection


outs = net.forward(net.getUnconnectedOutLayersNames())

# Process and display detected objects


conf_threshold = 0.5 # Confidence threshold for detections
nms_threshold = 0.4 # Non-maximum suppression threshold

for out in outs:


for detection in out:
scores = detection[5:]
class_id = np.argmax(scores)
confidence = scores[class_id]

if confidence >conf_threshold:
center_x = int(detection[0] * width)
center_y = int(detection[1] * height)
w = int(detection[2] * width)
h = int(detection[3] * height)

# Calculate coordinates of the bounding box


x = center_x - w // 2
y = center_y - h // 2

# Draw bounding box and label

Dept of IT GIET Engineering College, Rajahmundry


23
Object Detection Using YOLO

cv2.rectangle(image, (x, y), (x + w, y + h), (0, 255, 0), 2)


label = f"{classes[class_id]}: {confidence:.2f}"
cv2.putText(image, label, (x, y - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255,
0), 2)

# Display the result


cv2.imshow("Object Detection", image)
cv2.waitKey(0)
cv2.destroyAllWindows()

SAMPLE INPUT AND OUTPUT:


[INFO] loading YOLOv3 model...
[INFO] loading classes...
[INFO] loading image...
[INFO] processing image...
[INFO] displaying results...
[INFO] Object Detection
[INFO] Cat: 0.90

RESULT: Thus the given aim of the program is Succefully Completed and the Outs puts are
Verified.

RERERENCE BOOKS:
1. Bishop, C., M., Pattern Recognition and Machine Learning, Springer, 2006.
2. Navin Kumar Manaswi, “Deep Learning with Applications Using Python”, Apress, 2018.

Dept of IT GIET Engineering College, Rajahmundry


24

You might also like