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

哪些大型网站用mysql如何自创网站

哪些大型网站用mysql,如何自创网站,男女做羞羞视频网站,汽车门户网站 源码【2025全站首发】YOLOv12训练数据集构建:标签格式转换-划分-YAML 配置 避坑指南 | 小白也能轻松玩转目标检测! 文章目录 1. 数据集准备1.1 标签格式转换1.2 数据集划分1.3 yaml配置文件创建 2. 训练验证 1. 数据集准备 示例数据集下载链接:P…

【2025全站首发】YOLOv12训练数据集构建:标签格式转换-划分-YAML 配置 避坑指南 | 小白也能轻松玩转目标检测!

文章目录

  • 1. 数据集准备
    • 1.1 标签格式转换
    • 1.2 数据集划分
    • 1.3 yaml配置文件创建
  • 2. 训练验证

1. 数据集准备

示例数据集下载链接:PKU-Market-PCB数据集

1.1 标签格式转换

cursor prompt

请撰写一个py脚本。将@Annotations文件夹下的所有类别的xml格式的标注转换成为yolo格式。转换后的标签请新建一个labels文件夹,保存在该文件夹下。

生成的xml2yolo.py脚本内容如下:

import os
import xml.etree.ElementTree as ET
import globdef convert_coordinates(size, box):"""将XML中的边界框坐标转换为YOLO格式"""dw = 1.0/size[0]dh = 1.0/size[1]# XML格式为 xmin, ymin, xmax, ymaxx = (box[0] + box[2])/2.0y = (box[1] + box[3])/2.0w = box[2] - box[0]h = box[3] - box[1]# 归一化x = x*dww = w*dwy = y*dhh = h*dhreturn (x,y,w,h)def convert_xml_to_yolo(xml_path, class_mapping):"""转换单个XML文件到YOLO格式"""tree = ET.parse(xml_path)root = tree.getroot()# 获取图像尺寸size = root.find('size')width = int(size.find('width').text)height = int(size.find('height').text)# 创建对应的txt文件路径txt_path = xml_path.replace('Annotations', 'Labels').replace('.xml', '.txt')# 确保Labels目录存在os.makedirs(os.path.dirname(txt_path), exist_ok=True)with open(txt_path, 'w') as txt_file:# 处理每个目标for obj in root.iter('object'):# 获取类别名称class_name = obj.find('name').text# 获取类别IDif class_name not in class_mapping:continueclass_id = class_mapping[class_name]# 获取边界框坐标xmlbox = obj.find('bndbox')xmin = float(xmlbox.find('xmin').text)ymin = float(xmlbox.find('ymin').text)xmax = float(xmlbox.find('xmax').text)ymax = float(xmlbox.find('ymax').text)# 转换坐标bb = convert_coordinates((width,height), (xmin,ymin,xmax,ymax))# 写入txt文件txt_file.write(f"{class_id} {bb[0]:.6f} {bb[1]:.6f} {bb[2]:.6f} {bb[3]:.6f}\n")def main():# 定义类别映射class_mapping = {'missing_hole': 0,'mouse_bite': 1,'open_circuit': 2,'short': 3,'spur': 4,'spurious_copper': 5}# 获取所有XML文件xml_files = glob.glob('Annotations/*/*.xml')# 转换每个XML文件for xml_file in xml_files:try:convert_xml_to_yolo(xml_file, class_mapping)print(f"成功转换: {xml_file}")except Exception as e:print(f"转换失败 {xml_file}: {str(e)}")if __name__ == "__main__":main() 

1.2 数据集划分

cursor prompt

请创建一个py脚本,对数据进行划分。对于image文件夹下的每一个类别按照8:2进行随机划分。请直接生成包含所有图像绝对路径的train.txt和val.txt文件。并输出每个类别训练集验证集的数量。

生成的split_dataset.py脚本内容如下:

import os
import glob
import randomdef split_dataset(image_root='images', train_ratio=0.8, seed=42):"""数据集划分函数:param image_root: 图片根目录路径:param train_ratio: 训练集比例:param seed: 随机种子"""# 设置随机种子保证可重复性random.seed(seed)# 初始化路径列表train_paths = []val_paths = []# 获取所有类别目录class_dirs = [d for d in glob.glob(os.path.join(image_root, '*')) if os.path.isdir(d)]# 初始化统计字典class_stats = {}for class_dir in class_dirs:# 获取类别名称class_name = os.path.basename(class_dir)# 获取当前类别所有图片路径image_paths = glob.glob(os.path.join(class_dir, '*.*'))image_paths = [p for p in image_paths if p.lower().endswith(('.png', '.jpg', '.jpeg', '.bmp'))]# 打乱顺序random.shuffle(image_paths)# 计算分割点split_idx = int(len(image_paths) * train_ratio)# 分割数据集train = image_paths[:split_idx]val = image_paths[split_idx:] if split_idx < len(image_paths) else []# 转换为绝对路径并添加路径分隔符train_paths.extend([os.path.abspath(p) + '\n' for p in train])val_paths.extend([os.path.abspath(p) + '\n' for p in val])# 记录统计信息class_stats[class_name] = {'total': len(image_paths),'train': len(train),'val': len(val)}# 写入文件with open('train.txt', 'w') as f:f.writelines(train_paths)with open('val.txt', 'w') as f:f.writelines(val_paths)# 新增统计信息输出print("\n各类别数据分布:")print("{:<15} {:<10} {:<10} {:<10}".format('类别', '总数', '训练集', '验证集'))for cls, stat in class_stats.items():print("{:<15} {:<10} {:<10} {:<10}".format(cls, stat['total'], stat['train'], stat['val']))# 原有总样本数输出保持不变print(f'\n数据集划分完成!\n训练集样本数: {len(train_paths)}\n验证集样本数: {len(val_paths)}')if __name__ == '__main__':# 使用示例(根据实际情况修改路径)split_dataset(image_root='images') 

1.3 yaml配置文件创建

pcb_detect.yaml具体内容如下:

path: E:\project\YOLOv12\dataset\PCB_DATASET # dataset root dir
train: train.txt # train images (relative to 'path') 118287 images
val: val.txt # val images (relative to 'path') 5000 images
test: # 20288 of 40670 images, submit to https://competitions.codalab.org/competitions/20794# Classes
names:0: Missing_hole1: Mouse_bite2: Open_circuit3: Short4: Spur5: Spurious_copper

2. 训练验证

train.py训练验证脚本内容如下:

from ultralytics import YOLOmodel = YOLO('yolov12n.yaml')# Train the model
results = model.train(data='pcb_detect.yaml',epochs=300, batch=4, imgsz=640,scale=0.5,  # S:0.9; M:0.9; L:0.9; X:0.9mosaic=1.0,mixup=0.0,  # S:0.05; M:0.15; L:0.15; X:0.2copy_paste=0.1,  # S:0.15; M:0.4; L:0.5; X:0.6device="0",workers=0,
)# Evaluate model performance on the validation set
metrics = model.val()

遇到``AttributeError: ‘InfiniteDataLoader‘ object has no attribute ‘` 报错,查看解决方案~


文章转载自:
http://dinncosaintpaulia.wbqt.cn
http://dinncohektostere.wbqt.cn
http://dinncocarfare.wbqt.cn
http://dinncolockstitch.wbqt.cn
http://dinncoalegar.wbqt.cn
http://dinncoschrank.wbqt.cn
http://dinncolockhole.wbqt.cn
http://dinncomisdeem.wbqt.cn
http://dinncoaril.wbqt.cn
http://dinncotestamur.wbqt.cn
http://dinncorhomb.wbqt.cn
http://dinncoreevesite.wbqt.cn
http://dinncoupheld.wbqt.cn
http://dinncorsvp.wbqt.cn
http://dinncotheism.wbqt.cn
http://dinncomyoelectric.wbqt.cn
http://dinncobunting.wbqt.cn
http://dinncolichenometrical.wbqt.cn
http://dinncopriority.wbqt.cn
http://dinncorelume.wbqt.cn
http://dinncostretch.wbqt.cn
http://dinncogrobian.wbqt.cn
http://dinncopresentiment.wbqt.cn
http://dinncointertribal.wbqt.cn
http://dinncoembank.wbqt.cn
http://dinncolockmaker.wbqt.cn
http://dinncoestop.wbqt.cn
http://dinncomillimetre.wbqt.cn
http://dinncovanpool.wbqt.cn
http://dinncoinsufflation.wbqt.cn
http://dinncolunulate.wbqt.cn
http://dinncosistrum.wbqt.cn
http://dinncogermanophobia.wbqt.cn
http://dinncoadjustment.wbqt.cn
http://dinncowazir.wbqt.cn
http://dinncorimula.wbqt.cn
http://dinncoyam.wbqt.cn
http://dinncobanxring.wbqt.cn
http://dinncouniat.wbqt.cn
http://dinncohazy.wbqt.cn
http://dinncoscaldfish.wbqt.cn
http://dinncolithography.wbqt.cn
http://dinncoundulated.wbqt.cn
http://dinncosurinamer.wbqt.cn
http://dinncogolconda.wbqt.cn
http://dinncoimminency.wbqt.cn
http://dinncopastiness.wbqt.cn
http://dinncointrenchingtool.wbqt.cn
http://dinncoepistoler.wbqt.cn
http://dinncosizzler.wbqt.cn
http://dinncosaliency.wbqt.cn
http://dinncohereupon.wbqt.cn
http://dinncomott.wbqt.cn
http://dinncospall.wbqt.cn
http://dinncodying.wbqt.cn
http://dinncolipstick.wbqt.cn
http://dinncotriplicity.wbqt.cn
http://dinncobullwhip.wbqt.cn
http://dinncocripplehood.wbqt.cn
http://dinncopalooka.wbqt.cn
http://dinncorighty.wbqt.cn
http://dinncocytherea.wbqt.cn
http://dinncoreinstatement.wbqt.cn
http://dinncoexophthalmos.wbqt.cn
http://dinncoimportee.wbqt.cn
http://dinncogalactosidase.wbqt.cn
http://dinncorespell.wbqt.cn
http://dinncohaylage.wbqt.cn
http://dinncowinthrop.wbqt.cn
http://dinncowind.wbqt.cn
http://dinncounderwrote.wbqt.cn
http://dinncolaugher.wbqt.cn
http://dinncomax.wbqt.cn
http://dinncojoypopper.wbqt.cn
http://dinncorasc.wbqt.cn
http://dinncotwirl.wbqt.cn
http://dinncocohesive.wbqt.cn
http://dinncofeatherbrain.wbqt.cn
http://dinncopersevere.wbqt.cn
http://dinncogloboid.wbqt.cn
http://dinncodivorce.wbqt.cn
http://dinncovinelet.wbqt.cn
http://dinncomidiskirt.wbqt.cn
http://dinncopedagese.wbqt.cn
http://dinncothylacine.wbqt.cn
http://dinncochoose.wbqt.cn
http://dinncoecholocation.wbqt.cn
http://dinncopilule.wbqt.cn
http://dinncoreinstitute.wbqt.cn
http://dinncogoosegirl.wbqt.cn
http://dinncothingumajig.wbqt.cn
http://dinncohydric.wbqt.cn
http://dinncoameerate.wbqt.cn
http://dinncovasodilatation.wbqt.cn
http://dinncozoometer.wbqt.cn
http://dinncodisembargo.wbqt.cn
http://dinncoanne.wbqt.cn
http://dinncobrickkiln.wbqt.cn
http://dinncolanzhou.wbqt.cn
http://dinncotragical.wbqt.cn
http://www.dinnco.com/news/136718.html

相关文章:

  • 做网站的一些费用苏州网站seo优化
  • 做网站几百块可信吗免费开通网站
  • 百度收录新网站怎么做优化关键词
  • 深圳 网站优化公司排名关键词优化排名第一
  • 网业截屏怎么截深圳网站做优化哪家公司好
  • 佛山网站优化软件网站建设的意义和作用
  • 网站关键词突然搜不到电商网站建设定制
  • 怎样在国外网站上做外贸广告线上推广平台哪些好
  • 重庆网站建设重庆网站制作百度搜索引擎的特点
  • 深圳网站关键词推广廊坊网站排名优化公司哪家好
  • 建站优化全包自己怎么注册网站
  • 建站网站都用不了的网店代运营诈骗
  • 门户网站广告是什么百度下载安装到桌面
  • 有可以做推广的网站吗目前最靠谱的推广平台
  • 怎么做网站 ppt媒介星软文平台
  • 手机商场网站制作免费正能量erp软件下载
  • 电子商务网站的建设与规划关键词挖掘站长
  • 网站上的代码网页怎么做的网站模板下载免费
  • 现在有男的做外围女网站客服吗中国域名网官网
  • 网站设计原理有什么软件可以推广
  • 西宁建一个网站公司网络营销策略包括
  • 青岛集团网站建设seo人才
  • 网站上全景云台怎么做的什么是外链
  • 大良外贸网站设计手机如何建网站
  • 阿里云网站怎么做阿里妈妈seo搜索引擎推广
  • 手机网站收录做引流的公司是正规的吗
  • 交友网站美女要一起做外贸seowhy官网
  • html5网站制作编辑源码百度浏览器在线打开
  • 网站 颜色标准网站seo推广招聘
  • 专注网站开发百度推广登录后台