ARTICLE DETAIL

资讯详情

深耕网站建设与运营推广的一线实战洞察。

yolov26遥感影像各类油罐检测数据集 油罐数据集,共分为外浮顶油罐,封闭顶油罐,球形压力罐,水塔,沉淀罐五种类型,超过26000张影像,采用voc格式标注,512×215尺寸,2GB

yolov26遥感影像各类油罐检测数据集 油罐数据集,共分为外浮顶油罐,封闭顶油罐,球形压力罐,水塔,沉淀罐五种类型,超过26000张影像,采用voc格式标注,512×215尺寸,2GB 遥感影像各类油罐检测共分为外浮顶油罐封闭顶油罐球形压力罐水塔沉淀罐五种类型超过26000张影像采用voc格式标注512×215尺寸2GB使用YOLOv8来训练一个包含超过26000张遥感影像的油罐检测数据集。这个数据集包含5个类别已标注为VOC格式可以直接用于模型训练。数据集描述数据量超过26000张影像类别0: 外浮顶油罐External Floating Roof Tank1: 封闭顶油罐Fixed Roof Tank2: 球形压力罐Spherical Pressure Tank3: 水塔Water Tower4: 沉淀罐Settling Tank标注格式VOC格式图像尺寸512×215数据大小约2GB应用场景遥感影像油罐检测数据集组织假设你的数据集目录结构如下深色版本oil_tank_dataset/├── images/│ ├── 000001.jpg│ ├── 000002.jpg│ └── …├── annotations/│ ├── 000001.xml│ ├── 000002.xml│ └── …└── data.yaml # 数据配置文件数据配置文件创建或确认data.yaml文件是否正确配置了数据集路径和类别信息yaml深色版本train: ./images/train/ # 训练集图像路径val: ./images/val/ # 验证集图像路径test: ./images/test/ # 测试集图像路径Classesnc: 5 # 类别数量names:External Floating Roof TankFixed Roof TankSpherical Pressure TankWater TowerSettling Tank # 类别名称列表数据集划分将数据集划分为训练集、验证集和测试集。可以使用以下脚本python深色版本import osimport randomfrom shutil import copyfile定义源目录和目标目录source_images_dir ‘./oil_tank_dataset/images’source_annotations_dir ‘./oil_tank_dataset/annotations’target_train_dir ‘./oil_tank_dataset/images/train’target_val_dir ‘./oil_tank_dataset/images/val’target_test_dir ‘./oil_tank_dataset/images/test’target_train_annotations_dir ‘./oil_tank_dataset/annotations/train’target_val_annotations_dir ‘./oil_tank_dataset/annotations/val’target_test_annotations_dir ‘./oil_tank_dataset/annotations/test’创建目标目录os.makedirs(target_train_dir, exist_okTrue)os.makedirs(target_val_dir, exist_okTrue)os.makedirs(target_test_dir, exist_okTrue)os.makedirs(target_train_annotations_dir, exist_okTrue)os.makedirs(target_val_annotations_dir, exist_okTrue)os.makedirs(target_test_annotations_dir, exist_okTrue)获取所有图像文件all_images [f for f in os.listdir(source_images_dir) if f.endswith(‘.jpg’)]random.shuffle(all_images)划分数据集train_ratio 0.8val_ratio 0.1test_ratio 0.1train_split int(train_ratio * len(all_images))val_split train_split int(val_ratio * len(all_images))train_images all_images[:train_split]val_images all_images[train_split:val_split]test_images all_images[val_split:]复制图像文件和对应的标注文件def copy_files(image_list, target_image_dir, target_annotation_dir):for img in image_list:copyfile(os.path.join(source_images_dir, img), os.path.join(target_image_dir, img))annotation img.replace(‘.jpg’, ‘.xml’)copyfile(os.path.join(source_annotations_dir, annotation), os.path.join(target_annotation_dir, annotation))copy_files(train_images, target_train_dir, target_train_annotations_dir)copy_files(val_images, target_val_dir, target_val_annotations_dir)copy_files(test_images, target_test_dir, target_test_annotations_dir)转换VOC标注为YOLO格式首先我们需要将VOC格式的标注文件转换为YOLO格式。可以使用Python脚本来完成这个任务。python深色版本import osimport xml.etree.ElementTree as ETimport shutil定义类别映射class_map {‘External Floating Roof Tank’: 0,‘Fixed Roof Tank’: 1,‘Spherical Pressure Tank’: 2,‘Water Tower’: 3,‘Settling Tank’: 4}定义转换函数def convert_voc_to_yolo(voc_file, yolo_file, image_size, class_map):tree ET.parse(voc_file)root tree.getroot()with open(yolo_file, w) as f: for obj in root.findall(object): class_name obj.find(name).text if class_name not in class_map: continue class_id class_map[class_name] bbox obj.find(bndbox) x_min int(bbox.find(xmin).text) y_min int(bbox.find(ymin).text) x_max int(bbox.find(xmax).text) y_max int(bbox.find(ymax).text) x_center (x_min x_max) / 2.0 / image_size[0] y_center (y_min y_max) / 2.0 / image_size[1] width (x_max - x_min) / image_size[0] height (y_max - y_min) / image_size[1] f.write(f{class_id} {x_center} {y_center} {width} {height}\n)读取图像尺寸def get_image_size(image_path):from PIL import Imagewith Image.open(image_path) as img:return img.width, img.height转换所有标注文件def convert_all_annotations(image_dir, annotation_dir, output_dir):if not os.path.exists(output_dir):os.makedirs(output_dir)for filename in os.listdir(annotation_dir): if filename.endswith(.xml): image_filename filename.replace(.xml, .jpg) image_path os.path.join(image_dir, image_filename) voc_file os.path.join(annotation_dir, filename) yolo_file os.path.join(output_dir, filename.replace(.xml, .txt)) image_size get_image_size(image_path) convert_voc_to_yolo(voc_file, yolo_file, image_size, class_map)调用转换函数image_dir ‘./oil_tank_dataset/images’annotation_dir ‘./oil_tank_dataset/annotations’output_dir ‘./oil_tank_dataset/labels’convert_all_annotations(image_dir, annotation_dir, output_dir)安装YOLOv8如果你还没有安装YOLOv8可以使用以下命令安装pip install ultralytics训练模型使用YOLOv8训练模型的命令非常简单你可以直接使用以下命令开始训练cd path/to/oil_tank_dataset/克隆YOLOv8仓库git clone https://github.com/ultralytics/ultralytics.gitcd ultralytics开始训练python yolo.py detect train data…/data.yaml modelyolov8n.pt epochs100 imgsz512 batch16在这个命令中data…/data.yaml指定数据配置文件。modelyolov8n.pt指定预训练权重这里使用的是YOLOv8的小模型。epochs100训练轮数。imgsz512输入图像的宽度高度为215但YOLOv8通常需要正方形输入可以考虑调整图像大小或使用其他方法处理。batch16批量大小。模型评估训练完成后可以使用以下命令评估模型在验证集上的表现python yolo.py detect val data…/data.yaml modelruns/detect/train/weights/best.pt imgsz512这里的runs/detect/train/weights/best.pt是训练过程中产生的最佳模型权重文件。模型预测你可以使用训练好的模型对新图像进行预测python yolo.py detect predict sourcepath/to/your/image.jpg modelruns/detect/train/weights/best.pt imgsz512 conf0.4 iou0.5查看训练结果训练过程中的日志和结果会保存在runs/detect/目录下你可以查看训练过程中的损失、精度等信息。数据增强为了进一步提高模型性能可以使用数据增强技术。以下是一个简单的数据增强示例安装albumentations库pip install -U albumentations在yolo.py中添加数据增强pimport albumentations as Afrom albumentations.pytorch import ToTensorV2import cv2定义数据增强transform A.Compose([A.RandomSizedCrop(min_max_height(400, 512), height512, width512, p0.5),A.HorizontalFlip(p0.5),A.VerticalFlip(p0.5),A.Rotate(limit10, p0.5, border_modecv2.BORDER_CONSTANT),A.ColorJitter(brightness0.2, contrast0.2, saturation0.2, hue0.2, p0.5),A.GaussNoise(var_limit(10.0, 50.0), p0.5),A.Normalize(mean[0.485, 0.456, 0.406], std[0.229, 0.224, 0.225]),ToTensorV2()], bbox_paramsA.BboxParams(format‘yolo’, label_fields[‘class_labels’]))在数据加载器中应用数据增强def collate_fn(batch):images, targets zip(*batch)transformed_images []transformed_targets []for img, target in zip(images, targets): bboxes target[bboxes] class_labels target[labels] augmented transform(imageimg, bboxesbboxes, class_labelsclass_labels) transformed_images.append(augmented[image]) transformed_targets.append({ bboxes: augmented[bboxes], labels: augmented[class_labels] }) return torch.stack(transformed_images), transformed_targets注意事项数据集质量确保数据集的质量包括清晰度、标注准确性等。模型选择可以选择更强大的模型版本如YOLOv8m、YOLOv8l等以提高性能。超参数调整根据实际情况调整超参数如批量大小batch、图像大小imgsz等。监控性能训练过程中监控损失函数和mAP指标确保模型收敛。通过上述步骤你可以使用YOLOv8来训练一个遥感影像油罐检测数据集并使用训练好的模型进行预测。
返回列表