0% found this document useful (0 votes)
4 views3 pages

Temp

Programming experiment

Uploaded by

Randomizer 225
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)
4 views3 pages

Temp

Programming experiment

Uploaded by

Randomizer 225
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/ 3

MINI PROJECT

EX.NO. : 13
DATE :

AIM :
To write a python code to perform object detection using YOLOv5 model and display the
confidence score distribution.

ALGORITHM :
Import necessary libraries
Load the pre-trained YOLOv5 model

Read the input image


Perform object detection using the model

Save the detection results


Extract confidence scores from the detection results

Display the input image


Plot the confidence score distribution

Display the detected objects with their confidence scores

PROGRAM:
import torch

import matplotlib.pyplot as plt


import numpy as np
import cv2

import os
from google.colab.patches import cv2_imshow
model = torch.hub.load('yolov5.pt')

image_path = 'kipz.jpg'
img = cv2.imread(image_path)

results = model(img)

save_dir = 'output'

if not os.path.exists(save_dir):
os.makedirs(save_dir)

results.save(save_dir)

detections = results.pandas().xyxy[0]

print(detections)

confidence_scores = detections['confidence'].to_numpy()

plt.figure(figsize=(10, 10))

plt.imshow(cv2.cvtColor(img, cv2.COLOR_BGR2RGB))
plt.axis('off')

plt.show()

plt.figure(figsize=(10, 6))

plt.hist(confidence_scores, bins=10, alpha=0.75, color='blue', edgecolor='black')


plt.title('Object Detection Confidence Score Distribution')

plt.xlabel('Confidence Score')
plt.ylabel('Frequency')
plt.grid(True)
plt.show()

cv2_imshow(img)

for index, row in detections.iterrows():


print(f"Objects Detected: {row['name']} with confidence: {row['confidence']:.2f}")

OUTPUT:

RESULT:
Thus the program was executed successfully and the output is verified.

You might also like