Skip to content

Commit

Permalink
Merge pull request #272 from ramana2074/main
Browse files Browse the repository at this point in the history
Object Detection
  • Loading branch information
UTSAVS26 authored Oct 8, 2024
2 parents 84adf4c + 165e55b commit beb2ab9
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 0 deletions.
38 changes: 38 additions & 0 deletions Deep_Learning/Object detection/Dataset/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Object Detection using YOLOv3

## 🎯 Goal
The main goal of this project is to demonstrate the use of the YOLOv3 (You Only Look Once) object detection algorithm with OpenCV in Python to detect objects in images. The purpose of this project is to showcase the effectiveness of YOLOv3 in real-time object detection.

## 🧵 Dataset
The dataset used in this project is the COCO (Common Objects in Context) dataset, which is a large-scale object detection dataset. The dataset can be downloaded from the official COCO website: https://cocodataset.org/#home.

## 🧾 Description
This project uses the YOLOv3 algorithm to detect objects in images. The YOLOv3 model is pre-trained on the COCO dataset and is used to detect objects in real-time. The project uses OpenCV to load the YOLOv3 model and detect objects in images.

## 🧮 What I had done! Here are the step-by-step procedures of how the project works:

Loaded the YOLOv3 model using OpenCV.
Loaded the image to be detected.
Detected objects in the image using the YOLOv3 model.
Displayed the image with bounding boxes and labels using matplotlib.
🚀 Models Implemented The YOLOv3 algorithm is used in this project. YOLOv3 is a state-of-the-art, real-time object detection algorithm that is widely used in computer vision tasks. It is chosen for its high accuracy and speed.

## 📚 Libraries Needed The following libraries are needed for this project:

OpenCV
NumPy
Matplotlib

## 📊 Exploratory Data Analysis Results
The output of the project is an image with detected objects highlighted by bounding boxes and class labels.

![Output](./Images/Output.png)
## 📈 Performance of the Models based on the Accuracy Scores
The accuracy of the YOLOv3 model is not explicitly calculated in this project. However, the model is known to have high accuracy in object detection tasks.

## 📢 Conclusion
The YOLOv3 algorithm is effective in detecting objects in images. The project demonstrates the use of YOLOv3 with OpenCV in Python to detect objects in real-time.

## ✒️ Your Signature
Name - Venkata Ramana Billana
Github - https://github.com/ramana2074
Binary file added Deep_Learning/Object detection/Images/Input.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Deep_Learning/Object detection/Images/Output.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
77 changes: 77 additions & 0 deletions Deep_Learning/Object detection/Model/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import cv2
import numpy as np
import matplotlib.pyplot as plt

# Load YOLO model
# download YOLO models from offical webiste of yolo algorithm

yolo = cv2.dnn.readNet("C:\\Users\\billa\\OneDrive\\Documents\\ABC\\Computer-Vision-Projects\\Object detection\\Dataset\\yolov3.weights",
"C:\\Users\\billa\\OneDrive\\Documents\\ABC\\Computer-Vision-Projects\\Object detection\\Dataset\\yolov3.cfg")

# Load class names
classes = []
with open("C:\\Users\\billa\\OneDrive\\Documents\\ABC\\Computer-Vision-Projects\\Object detection\\Dataset\\coco.names", 'r') as f:
classes = f.read().splitlines()

# Load image
img = cv2.imread("C:\\Users\\billa\\OneDrive\\Desktop\\Programs\\ML_DL\\gg.png")
if img is None:
print("Error loading image.")
height, width = img.shape[:2] # Get image height and width

# Prepare the image for YOLO
blob = cv2.dnn.blobFromImage(img, 1/255, (416, 416), (0, 0, 0), swapRB=True, crop=False)
yolo.setInput(blob)

# Get output layer names and run forward pass
output_layers_names = yolo.getUnconnectedOutLayersNames()
layer_output = yolo.forward(output_layers_names)

# Initialize lists
boxes = []
confidences = []
class_ids = []

for output in layer_output:
for detection in output:
scores = detection[5:]
class_id = np.argmax(scores)
confidence = scores[class_id]
if confidence > 0.7:
center_x = int(detection[0] * width)
center_y = int(detection[1] * height)
w = int(detection[2] * width)
h = int(detection[3] * height)

x = int(center_x - w / 2)
y = int(center_y - h / 2)

# Append detection information
boxes.append([x, y, w, h])
confidences.append(float(confidence))
class_ids.append(class_id)

# Perform Non-Maximum Suppression
indexes = cv2.dnn.NMSBoxes(boxes, confidences, 0.5, 0.4)

# Font for displaying labels
font = cv2.FONT_HERSHEY_PLAIN
# Random colors for each box
colors = np.random.randint(0, 255, size=(len(boxes), 3), dtype='uint8')

# Check if any boxes are returned
if len(indexes) > 0:
indexes = indexes.flatten() # Flatten the list of indexes

# Draw bounding boxes and labels
for i in indexes:
x, y, w, h = boxes[i]
label = str(classes[class_ids[i]])
color = [int(c) for c in colors[i]]
cv2.rectangle(img, (x, y), (x + w, y + h), color, 2)
cv2.putText(img, label, (x, y - 10), font, 2, (255, 255, 255), 2)

# Display the image with matplotlib
plt.imshow(cv2.cvtColor(img, cv2.COLOR_BGR2RGB))
plt.axis('off') # Hide axis
plt.show()
3 changes: 3 additions & 0 deletions Deep_Learning/Object detection/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
opencv-python==4.5.5.64
numpy==1.21.4
matplotlib==3.5.0

0 comments on commit beb2ab9

Please sign in to comment.