AutoDL云服务器上使用yolov8训练数据集

1.准备数据集

(1)下载数据集

这里以CUB-200-2011数据集为例。CUB-200-2011(Caltech-UCSD Birds 200-2011)是一个包含200种鸟类的数据集,每种鸟类大约有60张图片,总共有11788张图片。数据集中包含了图片和标注信息(包括边界框)。下载链接CUB-200-2011

(2)解压 
(3)转换成yolov8所需格式

        生成标签文件(labels):打开你克隆下来的ultralytics项目,在项目中新建一个python文件convert_to_yolov8_format.py,粘贴下面的python代码。并打开终端输入以下bash命令运行它。

python convert_to_yolov8_format.py
#1.处理标签文件
import os
import pandas as pd
from PIL import Image

# 数据集路径
dataset_dir = '/path/to/CUB_200_201'  #这里切换为自己的路径,解压后的数据集位置
images_dir = os.path.join(dataset_dir, 'images')
annotations_dir = dataset_dir

# 加载数据
bounding_boxes = pd.read_csv(os.path.join(annotations_dir, 'bounding_boxes.txt'), sep='\s+', header=None, names=['image_id', 'x', 'y', 'width', 'height'])
class_labels = pd.read_csv(os.path.join(annotations_dir, 'image_class_labels.txt'), sep='\s+', header=None, names=['image_id', 'class_id'])
image_paths = pd.read_csv(os.path.join(annotations_dir, 'images.txt'), sep='\s+', header=None, names=['image_id', 'image_path'])

# 合并数据帧
data = pd.merge(bounding_boxes, class_labels, on='image_id')
data = pd.merge(data, image_paths, on='image_id')

# 创建YOLO格式的标注文件
for _, row in data.iterrows():
    image_path = os.path.join(images_dir, row['image_path'])
    image = Image.open(image_path)
    dw = 1. / image.width
    dh = 1. / image.height

    # 计算归一化坐标
    x = (row['x'] + row['width'] / 2.0) * dw
    y = (row['y'] + row['height'] / 2.0) * dh
    w = row['width'] * dw
    h = row['height'] * dh

    # 类别ID调整为从0开始(如果需要)
    class_id = row['class_id'] - 1

    # 生成标注文件
    txt_path = image_path.replace
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值