本文主要是介绍SAHI_Yolov8:小目标检测,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
懒得推gitee,记录一下
import os import time import shutil os.getcwd()# arrange an instance segmentation model for test from sahi.utils.yolov8 import (download_yolov8s_model, ) import cv2 from sahi import AutoDetectionModel from sahi.utils.cv import read_image from sahi.utils.file import download_from_url from sahi.predict import get_prediction, get_sliced_prediction, predict from IPython.display import Imagedetection_model = AutoDetectionModel.from_pretrained(model_type='yolov8',# YOLOv8模型的路径model_path="/home/hxzh/PycharmProjects/SAHI_YOLOv8/best.pt",# YOLOv8模型的路径confidence_threshold=0.3,# 设备类型。# 如果您的计算机配备 NVIDIA GPU,则可以通过将 'device' 标志更改为'cuda:0'来启用 CUDA 加速;否则,将其保留为'cpu'device="cuda:0", # or 'cuda:0' ) start_time=time.time() images_path="/media/hxzh/D/Dataset/plean_test/0926" for i in os.listdir(images_path):image=cv2.imread(f"{images_path}/{i}")[:,:,::-1] # image=cv2.resize(image,(1000,700))[:,:,::-1]result = get_sliced_prediction(# "/media/hxzh/D/Dataset/plean_test/0926/DJI_20230919085432_0018_W.JPG",image,detection_model,slice_height = 1000,slice_width = 750,overlap_height_ratio = 0.2,overlap_width_ratio = 0.2)result.export_visuals(export_dir="demo_data/",hide_labels=True,hide_conf=True)os.rename("demo_data/prediction_visual.png",f"demo_data/{i}")print(time.time()-start_time)Image(f"demo_data/{i}")
这篇关于SAHI_Yolov8:小目标检测的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!