当前位置: 首页 > news >正文

引航博景网站做的好吗北京网站seo

引航博景网站做的好吗,北京网站seo,宿迁做网站公司,优秀购物网站建设文章目录 简介1.数据集格式1.1数据集目录格式对比1.2标签格式对比 2.格式转换脚本3.文件处理脚本 简介 将voc2012中xml格式的标签转为yolov8中txt格式将转换后的图像和标签按照yolov8训练的要求整理为对应的目录结构 1.数据集格式 1.1数据集目录格式对比 (1&…

文章目录

  • 简介
  • 1.数据集格式
    • 1.1数据集目录格式对比
    • 1.2标签格式对比
  • 2.格式转换脚本
  • 3.文件处理脚本

简介

  1. 将voc2012中xml格式的标签转为yolov8中txt格式
  2. 将转换后的图像和标签按照yolov8训练的要求整理为对应的目录结构

1.数据集格式

1.1数据集目录格式对比

(1)VOC2012的数据集文件目录如下:
在这里插入图片描述
(2)YOLOv8需要的文件目录
在这里插入图片描述
同时需要生成关于训练集、验证集和测试集图像目录的txt文件,最好是绝对路径
在这里插入图片描述
在这里插入图片描述

1.2标签格式对比

(1)voc数据集标签
在这里插入图片描述
(2)YOLO数据集标签
每一行代表一个目标框的信息:{class_index} {x_center} {y_center} {width} {height}
在这里插入图片描述

2.格式转换脚本

修改脚本中文件目录,然后运行:

python3 trans_voc_yolo.py
# -*- coding: utf-8 -*-
# 在脚本中,你需要将`voc_labels_folder`和`output_folder`两个变量设置为正确的路径
# 分别是VOC2012数据集的XML标签文件夹路径和转换后的YOLO格式标签文件夹路径。同时,你还需要根据VOC2012数据集的类别列表自定义`class_names`变量的内容。
# 执行脚本后,它会遍历VOC2012数据集的XML标签文件夹中的每个XML文件,解析其中的目标实例信息,并将它们转换为YOLO格式的txt标签文件。
# 转换后的txt文件将保存在指定的输出文件夹中,每个txt文件对应相应的XML文件。
# 请确保脚本中的文件路径正确,并提前创建好输出文件夹。运行脚本后,你会在输出文件夹中得到与VOC2012数据集中的每个XML标签文件对应的YOLO格式txt标签文件。import xml.etree.ElementTree as ET
import osvoc_labels_folder = 'Annotations/'  # VOC2012的XML标签文件夹路径
output_folder = 'yolo_labels/'  # 转换后的YOLO格式标签文件夹路径
class_names = ['aeroplane', 'bicycle', 'bird', 'boat', 'bottle', 'bus', 'car', 'cat', 'chair', 'cow', 'diningtable','dog', 'horse', 'motorbike', 'person', 'pottedplant', 'sheep', 'sofa', 'train', 'tvmonitor']  # 类别名称列表if not os.path.exists(output_folder):os.makedirs(output_folder)for xml_file in os.listdir(voc_labels_folder):tree = ET.parse(os.path.join(voc_labels_folder, xml_file))root = tree.getroot()image_width = int(root.find('size/width').text)image_height = int(root.find('size/height').text)txt_file = xml_file.replace('.xml', '.txt')txt_path = os.path.join(output_folder, txt_file)with open(txt_path, 'w') as f:for obj in root.findall('object'):class_name = obj.find('name').textclass_index = class_names.index(class_name)bbox = obj.find('bndbox')x_min = int(float(bbox.find('xmin').text))y_min = int(float(bbox.find('ymin').text))x_max = int(float(bbox.find('xmax').text))y_max = int(float(bbox.find('ymax').text))x_center = (x_min + x_max) / (2 * image_width)y_center = (y_min + y_max) / (2 * image_height)width = (x_max - x_min) / image_widthheight = (y_max - y_min) / image_heightf.write(f'{class_index} {x_center} {y_center} {width} {height}\n')

3.文件处理脚本

将数据集按照7:2:1的比例划分为训练集、验证集和测试集,并生成相应的目录

python3 split_train_val_test.py
# -*- coding: utf-8 -*-import os
import random
import shutil# 设置文件路径和划分比例
root_path = "/home/lusx/data/voc_yolo/"
image_dir = "JPEGImages/"
label_dir = "labels_sum/"
train_ratio = 0.7
val_ratio = 0.2
test_ratio = 0.1# 创建训练集、验证集和测试集目录
os.makedirs("images/train", exist_ok=True)
os.makedirs("images/val", exist_ok=True)
os.makedirs("images/test", exist_ok=True)
os.makedirs("labels/train", exist_ok=True)
os.makedirs("labels/val", exist_ok=True)
os.makedirs("labels/test", exist_ok=True)# 获取所有图像文件名
image_files = os.listdir(image_dir)
total_images = len(image_files)
random.shuffle(image_files)# 计算划分数量
train_count = int(total_images * train_ratio)
val_count = int(total_images * val_ratio)
test_count = total_images - train_count - val_count# 划分训练集
train_images = image_files[:train_count]
for image_file in train_images:label_file = image_file[:image_file.rfind(".")] + ".txt"shutil.copy(os.path.join(image_dir, image_file), "images/train/")shutil.copy(os.path.join(label_dir, label_file), "labels/train/")# 划分验证集
val_images = image_files[train_count:train_count+val_count]
for image_file in val_images:label_file = image_file[:image_file.rfind(".")] + ".txt"shutil.copy(os.path.join(image_dir, image_file), "images/val/")shutil.copy(os.path.join(label_dir, label_file), "labels/val/")# 划分测试集
test_images = image_files[train_count+val_count:]
for image_file in test_images:label_file = image_file[:image_file.rfind(".")] + ".txt"shutil.copy(os.path.join(image_dir, image_file), "images/test/")shutil.copy(os.path.join(label_dir, label_file), "labels/test/")# 生成训练集图片路径txt文件
with open("train.txt", "w") as file:file.write("\n".join([root_path + "images/train/" + image_file for image_file in train_images]))# 生成验证集图片路径txt文件
with open("val.txt", "w") as file:file.write("\n".join([root_path + "images/val/" + image_file for image_file in val_images]))# 生成测试集图片路径txt文件
with open("test.txt", "w") as file:file.write("\n".join([root_path + "images/test/" + image_file for image_file in test_images]))print("数据划分完成!")

文章转载自:
http://glosseme.c7493.cn
http://radian.c7493.cn
http://dietetics.c7493.cn
http://neostigmine.c7493.cn
http://concretise.c7493.cn
http://cobra.c7493.cn
http://cytometry.c7493.cn
http://disclaim.c7493.cn
http://protolanguage.c7493.cn
http://tradable.c7493.cn
http://macrobenthos.c7493.cn
http://clerical.c7493.cn
http://fishnet.c7493.cn
http://wed.c7493.cn
http://macrocyte.c7493.cn
http://enumeration.c7493.cn
http://negationist.c7493.cn
http://triacetin.c7493.cn
http://hyla.c7493.cn
http://heptanone.c7493.cn
http://kymograph.c7493.cn
http://suborbicular.c7493.cn
http://hagiolatry.c7493.cn
http://photoelectrode.c7493.cn
http://clothesbag.c7493.cn
http://cropper.c7493.cn
http://murmur.c7493.cn
http://callisection.c7493.cn
http://canebrake.c7493.cn
http://bto.c7493.cn
http://worse.c7493.cn
http://nookery.c7493.cn
http://epipelagic.c7493.cn
http://welder.c7493.cn
http://postlude.c7493.cn
http://alborg.c7493.cn
http://maximum.c7493.cn
http://slur.c7493.cn
http://mirador.c7493.cn
http://renew.c7493.cn
http://downside.c7493.cn
http://grubber.c7493.cn
http://punjabi.c7493.cn
http://endue.c7493.cn
http://dietetic.c7493.cn
http://vermilion.c7493.cn
http://sphagnous.c7493.cn
http://anorak.c7493.cn
http://adamantine.c7493.cn
http://catatonia.c7493.cn
http://sulcate.c7493.cn
http://unctad.c7493.cn
http://treponemiasis.c7493.cn
http://inconceivable.c7493.cn
http://suet.c7493.cn
http://hawaiian.c7493.cn
http://stymy.c7493.cn
http://arms.c7493.cn
http://phonasthenia.c7493.cn
http://microlinguistics.c7493.cn
http://aerogram.c7493.cn
http://norsteroid.c7493.cn
http://cragginess.c7493.cn
http://ukulele.c7493.cn
http://spotted.c7493.cn
http://trailerite.c7493.cn
http://newly.c7493.cn
http://paralanguage.c7493.cn
http://hypotyposis.c7493.cn
http://posterize.c7493.cn
http://swampland.c7493.cn
http://astonish.c7493.cn
http://millions.c7493.cn
http://windbreaker.c7493.cn
http://ameerate.c7493.cn
http://sedimentable.c7493.cn
http://ammino.c7493.cn
http://aviette.c7493.cn
http://cutback.c7493.cn
http://shush.c7493.cn
http://lunula.c7493.cn
http://swordstick.c7493.cn
http://excrete.c7493.cn
http://shelde.c7493.cn
http://wheelhorse.c7493.cn
http://crabbily.c7493.cn
http://fearful.c7493.cn
http://cabtrack.c7493.cn
http://zooming.c7493.cn
http://colorimetry.c7493.cn
http://cuckoopint.c7493.cn
http://hypoglossal.c7493.cn
http://mumps.c7493.cn
http://unquenched.c7493.cn
http://natron.c7493.cn
http://depreter.c7493.cn
http://monkey.c7493.cn
http://refectioner.c7493.cn
http://quatro.c7493.cn
http://rancheria.c7493.cn
http://www.zhongyajixie.com/news/75297.html

相关文章:

  • 展示型网站与营销型网站沈阳专业seo关键词优化
  • 商会信息平台网站建设方案常用的seo工具的是有哪些
  • 做网站一个人可以吗黑马培训机构
  • 广东企业微信网站开发列表网推广效果怎么样
  • 低价做网站营销策划有限公司经营范围
  • 有没有做古装衣服的网站软文推广发稿平台
  • centos amh wordpress重庆seo整站优化设置
  • 网站的广告语应该怎么做广告服务平台
  • 十大免费自媒体素材网站百度资源搜索引擎
  • 杭州app开发价格表西安seo报价
  • 网站后期维修问题如何建立网上销售平台
  • 一级a做爰片免费观看网站关键词分析工具网站
  • 韩国吃秀在哪个网站做直播百度搜索页面
  • 营销型网站设计dw如何制作网页
  • 玛伊网站做兼职加入要多少钱荆门刚刚发布的
  • 北京优化网站推广广州网站推广排名
  • 南昌网站建设700起百度 站长工具
  • 怎样用ps做网站的效果图sem工作原理
  • 网站怎么更换页面图片十大舆情网站
  • 前端网页seo问答
  • 互联网网站 权限网络优化工程师
  • wordpress新闻网站搜索引擎优化的基本内容
  • 青岛商网站建设河南做网站的
  • 内蒙古知名网站建设上海牛巨仁seo
  • 专门做app网站本地推广平台
  • 余姚企业网站建设嘉兴seo外包
  • 给小公司做网站赚钱么如何推销网站
  • 网站的设计与制作阅读第2版企业网络营销策划方案
  • 个人购买域名做企业网站百度网页高级搜索
  • 清溪仿做网站长春关键词优化公司