自学内容网 自学内容网

无人机视角下火灾检测数据集 共12736张 标注文件为YOLO适用的txt格式。已划分为训练集、验证集、测试集。类别:Fire yolov5-v10通用

无人机视角下火灾检测数据集 共12736张 标注文件为YOLO适用的txt格式。已划分为训练集、验证集、测试集。类别:Fire yolov5-v10通用

 

无人机视角下火灾检测数据集 共12736张 标注文件为YOLO适用的txt格式。已划分为训练集、验证集、测试集。类别:Fire yolov5-v10通用

无人机视角下的火灾检测数据集

数据集概述

名称:无人机视角下的火灾检测数据集
图片数量:12736张
标注格式:YOLO (TXT)
类别

  • 0: 火灾 (Fire)

用途:用于从无人机视角检测火灾,适用于森林防火、城市消防监控、灾害响应等任务。该数据集特别适合基于YOLO的目标检测模型。

数据集特点

  • 规模:包含12736张高分辨率图像,每张图像都带有详细的标注信息。
  • 多样性:图像涵盖了不同的光照条件(白天、夜晚)、天气状况(晴天、阴天、雨天)、背景环境(森林、城市、农田)以及火灾的不同阶段和规模,以确保模型能够适应多样的实际场景。
  • 划分:数据集已经划分为训练集、验证集和测试集,方便进行模型的训练、验证和测试。
  • 标注质量:每张图像都有精确的手动标注,确保了高质量的训练数据。
  • 标注格式
    • YOLO格式 (TXT):每个目标用一个文本行表示,格式为 class_id x_center y_center width height,所有坐标值都是归一化的。
标注信息
  • YOLO格式
    0 0.25 0.3333 0.1 0.2
    0 0.75 0.6667 0.08 0.15
    解释:0 表示火灾。x_center 和 y_center 是边界框中心点的归一化坐标,width 和 height 是边界框的宽度和高度的归一化值。
应用领域
  • 森林防火:自动检测并报告森林中的火灾,提高防火效率。
  • 城市消防监控:在城市区域实时监测火灾情况,及时响应火灾事件。
  • 灾害响应:快速识别灾区的火源位置,辅助救援行动。
  • 环境监测:持续监测特定区域的火灾风险,预防大规模火灾的发生。
  • 智能交通系统:结合无人机视频监控,提高道路安全,特别是在山区或偏远地区。
获取方式

通常情况下,研究人员可以通过官方提供的链接或相关机构网站下载该数据集。请注意,使用时应遵循相应的许可协议和引用要求。

关键代码示例
1. 下载数据集

假设我们已经有了数据集的下载链接,可以使用 Python 的 requests 库来下载数据集:

import requests
import os

# 定义下载链接和保存路径
url = 'http://example.com/path/to/fire_dataset.zip'  # 替换为实际的下载链接
save_path = './fire_dataset.zip'

# 检查是否已经下载过
if not os.path.exists(save_path):
    print("Downloading dataset...")
    response = requests.get(url, stream=True)
    with open(save_path, 'wb') as f:
        for chunk in response.iter_content(chunk_size=8192):
            if chunk:
                f.write(chunk)
    print("Download complete.")
else:
    print("Dataset already exists.")

# 解压数据集
import zipfile
with zipfile.ZipFile(save_path, 'r') as zip_ref:
    zip_ref.extractall('./fire_dataset')
2. 解析 YOLO 格式的标注文件

以下是一个解析 YOLO 格式标注文件的函数:

def parse_yolo_annotation(anno_file, image_width, image_height):
    annotations = []
    with open(anno_file, 'r') as f:
        lines = f.readlines()
        for line in lines:
            parts = line.strip().split(' ')
            class_id = int(parts[0])
            x_center = float(parts[1]) * image_width
            y_center = float(parts[2]) * image_height
            width = float(parts[3]) * image_width
            height = float(parts[4]) * image_height
            
            xmin = x_center - width / 2
            ymin = y_center - height / 2
            xmax = x_center + width / 2
            ymax = y_center + height / 2
            
            annotations.append({
                'class_name': 'fire',
                'class_id': class_id,
                'bbox': [xmin, ymin, xmax, ymax]
            })
    
    return annotations
3. 加载图像并显示标注框

我们可以使用 OpenCV 来加载图像,并使用 Matplotlib 来显示图像及其标注框:

import cv2
import matplotlib.pyplot as plt

def load_image(image_path):
    return cv2.imread(image_path)

def display_image_with_annotations(image, annotations):
    fig, ax = plt.subplots()
    ax.imshow(cv2.cvtColor(image, cv2.COLOR_BGR2RGB))
    for anno in annotations:
        bbox = anno['bbox']
        rect = plt.Rectangle((bbox[0], bbox[1]), bbox[2] - bbox[0], bbox[3] - bbox[1],
                             fill=False, edgecolor='red', linewidth=2)
        ax.add_patch(rect)
        ax.text(bbox[0], bbox[1], f"{anno['class_name']} ({anno['class_id']})", fontsize=12, color='white', backgroundcolor='red')
    plt.show()

# 示例用法
image_path = './fire_dataset/train/images/image_0001.jpg'
anno_path = './fire_dataset/train/annotations/image_0001.txt'

image = load_image(image_path)
image_height, image_width, _ = image.shape
annotations = parse_yolo_annotation(anno_path, image_width, image_height)
display_image_with_annotations(image, annotations)
4. 使用数据集进行训练

如果您打算使用这个数据集进行深度学习模型的训练,可以使用 PyTorch 或 TensorFlow 等框架。以下是一个简单的 PyTorch DataLoader 示例:

import torch
from torch.utils.data import Dataset, DataLoader
from PIL import Image
import numpy as np

class FireDataset(Dataset):
    def __init__(self, image_dir, anno_dir, transform=None):
        self.image_dir = image_dir
        self.anno_dir = anno_dir
        self.transform = transform
        self.images = os.listdir(image_dir)

    def __len__(self):
        return len(self.images)

    def __getitem__(self, idx):
        img_name = self.images[idx]
        image = Image.open(os.path.join(self.image_dir, img_name)).convert("RGB")
        anno_name = img_name.replace('.jpg', '.txt')
        anno_path = os.path.join(self.anno_dir, anno_name)
        
        image_np = np.array(image)
        image_height, image_width, _ = image_np.shape
        annotations = parse_yolo_annotation(anno_path, image_width, image_height)
        
        if self.transform:
            image = self.transform(image)
        
        return image, annotations

# 创建 DataLoader
dataset = FireDataset(image_dir='./fire_dataset/train/images',
                      anno_dir='./fire_dataset/train/annotations')
dataloader = DataLoader(dataset, batch_size=4, shuffle=True, num_workers=2)

# 遍历数据
for images, annotations in dataloader:
    # 在这里进行模型训练
    pass
YOLO模型训练

为了使用YOLO进行火灾检测,您可以使用预训练的YOLO模型,并对其进行微调。以下是一个简单的YOLOv5训练示例:

  1. git clone https://github.com/ultralytics/yolov5
    cd yolov5
    pip install -r requirements.txt
  2. 准备数据集: 将数据集转换为YOLO所需的格式,并创建配置文件(例如 data.yaml):

     yaml 

    深色版本

    train: ./fire_dataset/train/images
    val: ./fire_dataset/val/images
    test: ./fire_dataset/test/images
    nc: 1  # 类别数
    names: ['fire']  # 类别名称
  3. 训练模型: 使用YOLOv5进行训练:

    python train.py --img 640 --batch 16 --epochs 50 --data data.yaml --weights yolov5s.pt
  4. 评估模型: 训练完成后,可以使用验证集进行评估:

    python val.py --data data.yaml --weights runs/train/exp/weights/best.pt
  5. 推理测试: 使用训练好的模型进行推理测试:

    python detect.py --source ./fire_dataset/test/images --weights runs/train/exp/weights/best.pt --conf 0.4

通过上述步骤,您将拥有一个完整的YOLO火灾检测系统,包括数据集、预训练模型和相关的训练流程。希望这些代码能帮助您更好地利用该数据集!


原文地址:https://blog.csdn.net/ALiLiLiYa/article/details/142907769

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!