舌象舌头舌苔检测数据集 1400张 舌象 带标注 voc yolo

舌象舌头舌苔检测数据集 1400张 舌象 带标注 voc yolo

舌象舌头舌苔检测数据集介绍

数据集概览

这是一个针对舌象舌头舌苔检测的数据集,包含1400张图片,每张图片都使用VOC或YOLO格式进行了标注。该数据集可用于训练和评估目标检测模型,特别是YOLO系列模型。

数据集特点
  • 规模较小: 包含1400张图片,适合小型项目或者初步探索。
  • 多类别标注: 标注了五种不同的舌苔类型。
  • VOC/YOLO格式: 标注信息采用VOC或YOLO格式,适合用于目标检测模型。
数据集结构

假设数据集文件夹结构如下:

 
tongue_dataset/
├── images/
│   ├── train/
│   ├── val/
│   └── test/
├── annotations/
│   ├── train/
│   ├── val/
│   └── test/
└── data.yaml
  • images/ 目录下存放图片文件。
  • annotations/ 目录下存放对应的VOC或YOLO格式的标注文件。
  • data.yaml 文件定义了数据集的配置信息。
data.yaml 文件示例(YOLO格式)
# data.yaml
train: ./images/train
val: ./images/val
test: ./images/test

nc: 5  # 类别数量
names: ['Mirror-Approximated', 'White-Greasy', 'Thin-White', 'Yellow-Greasy', 'Grey-Black']
关键代码示例

以下是一段Python代码示例,展示如何加载和查看数据集中的部分图片及其标注:

import os
import cv2
import matplotlib.pyplot as plt
from matplotlib.patches import Rectangle

def load_image_and_label(image_path, label_path):
    """
    加载图片和其对应的标注信息。
    
    Parameters:
        image_path (str): 图片路径。
        label_path (str): 标注文件路径。
        
    Returns:
        img (numpy.ndarray): 加载的图片。
        labels (list of dict): 标注信息列表。
    """
    img = cv2.imread(image_path)
    img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)  # 转换颜色空间
    
    if label_path.endswith('.xml'):  # VOC格式
        from xml.etree.ElementTree import ElementTree
        
        tree = ElementTree(file=label_path)
        root = tree.getroot()
        bboxes = []

        for obj in root.findall('object'):
            bbox = obj.find('bndbox')
            xmin = float(bbox.find('xmin').text)
            ymin = float(bbox.find('ymin').text)
            xmax = float(bbox.find('xmax').text)
            ymax = float(bbox.find('ymax').text)

            bboxes.append({
                'class_id': int(obj.find('name').text.split('-')[0]),  # 根据类别名称获取类别ID
                'x_center': (xmin + xmax) / 2 / img.shape[1],
                'y_center': (ymin + ymax) / 2 / img.shape[0],
                'width': (xmax - xmin) / img.shape[1],
                'height': (ymax - ymin) / img.shape[0]
            })

        labels = [dict(b) for b in bboxes]

    elif label_path.endswith('.txt'):  # YOLO格式
        with open(label_path, 'r') as f:
            lines = f.readlines()
            labels = []
            for line in lines:
                class_id, x_center, y_center, width, height = map(float, line.strip().split())
                labels.append({
                    'class_id': int(class_id),
                    'x_center': x_center,
                    'y_center': y_center,
                    'width': width,
                    'height': height
                })

    return img, labels

def draw_bounding_boxes(img, labels, class_names):
    """
    在图片上绘制边界框。
    
    Parameters:
        img (numpy.ndarray): 图片。
        labels (list of dict): 标注信息列表。
        class_names (list of str): 类别名称列表。
    """
    fig, ax = plt.subplots(1, figsize=(12, 12))
    ax.imshow(img)
    
    for label in labels:
        x_center, y_center, width, height = label['x_center'], label['y_center'], label['width'], label['height']
        h, w, _ = img.shape
        x_min = int((x_center - width / 2) * w)
        y_min = int((y_center - height / 2) * h)
        x_max = int((x_center + width / 2) * w)
        y_max = int((y_center + height / 2) * h)
        
        rect = Rectangle((x_min, y_min), x_max - x_min, y_max - y_min, linewidth=2, edgecolor='r', facecolor='none')
        ax.add_patch(rect)
        
        class_name = class_names[label['class_id']]
        ax.text(x_min, y_min, class_name, fontsize=12, color='red', backgroundcolor='white')
    
    plt.axis('off')
    plt.show()

if __name__ == "__main__":
    data_dir = "/path/to/your/dataset"
    train_images_dir = os.path.join(data_dir, "images/train")
    train_labels_dir = os.path.join(data_dir, "annotations/train")

    # 选择任何一张训练集中的图片及其对应的标注信息
    image_name = os.listdir(train_images_dir)[0]  # 选择第一张图片
    label_name = image_name.replace(".jpg", ".txt")  # 假设图片是.jpg格式,标签文件名相同但扩展名为.txt
    
    image_path = os.path.join(train_images_dir, image_name)
    label_path = os.path.join(train_labels_dir, label_name)
    
    img, labels = load_image_and_label(image_path, label_path)
    
    print(f"Loaded image shape: {img.shape}")
    print(f"Number of objects: {len(labels)}")
    print(f"First object's label: {labels[0]}")
    
    # 绘制边界框
    class_names = ['Mirror-Approximated', 'White-Greasy', 'Thin-White', 'Yellow-Greasy', 'Grey-Black']
    draw_bounding_boxes(img, labels, class_names)

请确保替换"/path/to/your/dataset"为你本地数据集的实际路径。这段代码会加载训练集中的一张图片及其对应的标注信息,并显示带有边界框和类别的图片。

注意:上述代码仅支持YOLO和VOC两种标注格式之一。如果你的数据集同时存在这两种格式,你需要根据实际情况修改代码来处理不同格式的标注文件。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值