Temp
Temp
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
PROGRAM:
import torch
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.xlabel('Confidence Score')
plt.ylabel('Frequency')
plt.grid(True)
plt.show()
cv2_imshow(img)
OUTPUT:
RESULT:
Thus the program was executed successfully and the output is verified.