9/1/25, 2:41 PM dl_lab_ex1 (1).
py
# -*- coding: utf-8 -*-
"""DL Lab Ex1.ipynb
Automatically generated by Colab.
Original file is located at
https://colab.research.google.com/drive/1h8MgpaSViO_ra7h9ZGmn86f1UsaUOliy
"""
import torch
from pathlib import Path
import cv2
import matplotlib.pyplot as plt
import numpy as np
!pip install ultralytics
model = torch.hub.load('ultralytics/yolov5', 'yolov5s', pretrained=True)
# Load image
img_path = '/content/image2.jpg'
img = cv2.imread(img_path)
# Convert BGR to RGB
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
# Display the image
plt.imshow(img)
plt.show()
# Perform inference
results = model(img)
# Print results
results.print() # Print results to console
results.show() # Display results
# Get the results
detections = results.pandas().xyxy[0] # Results as pandas dataframe
# Print detections
print(detections)
file:///C:/Users/Senthil/Downloads/dl_lab_ex1 (1).py 1/1