It is working great for yolov5 but i want to upgrade to yolov8
How can I do that?
import cv2
import torch
import os
from PIL import Image
# Load the pre-trained YOLOv5 model
model = torch.hub.load('ultralytics/yolov5', 'yolov5x')
# Aspect ratios to consider
aspect_ratios = [(1024, 1280)]
def auto_zoom(input_dir, output_base_dir):
# Loop over all files in the input directory
for filename in os.listdir(input_dir):
# Create the full input path and read the file
input_path = os.path.join(input_dir, filename)
img = cv2.imread(input_path)
if img is None:
continue
# Run the image through the model
results = model(img)
# Find the first human detected in the image
human = next((x for x in results.xyxy[0] if int(x[5]) == 0), None)
if human is None:
print(f"No human detected in the image {input_path}.")
os.remove(input_path)
continue
# Crop the image to the bounding box of the human
x1, y1, x2, y2 = map(int, human[:4])