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

临沂企业网站建设公司网站底部html代码

临沂企业网站建设公司,网站底部html代码,91大神网站建设,邵阳网站推广本文不生产技术,只做技术的搬运工!!! 前言 在yolo训练时,我们需要对图像进行标注,而使用labelimg标注时如果直接选择输出yolo格式的数据集,则原始数据的很多信息无法被保存,因此一版…

本文不生产技术,只做技术的搬运工!!!

前言

        在yolo训练时,我们需要对图像进行标注,而使用labelimg标注时如果直接选择输出yolo格式的数据集,则原始数据的很多信息无法被保存,因此一版使用xml格式的标签,这时再去训练时就需要对标签进行转换。

代码

import os
import xml.etree.ElementTree as ET
import cv2def getFileList(dir, Filelist, ext=None):"""获取文件夹及其子文件夹中文件列表输入 dir:文件夹根目录输入 ext: 扩展名返回: 文件路径列表"""newDir = dirif os.path.isfile(dir):if ext is None:Filelist.append(dir)else:if ext in dir:Filelist.append(dir)elif os.path.isdir(dir):for s in os.listdir(dir):newDir = os.path.join(dir, s)getFileList(newDir, Filelist, ext)return Filelistdef convert(size, box):dw = 1. / size[0]dh = 1. / size[1]x = (box[0] + box[1]) / 2.0y = (box[2] + box[3]) / 2.0w = box[1] - box[0]h = box[3] - box[2]x = x * dww = w * dwy = y * dhh = h * dhreturn (x, y, w, h)def convert_annotation(xml_file,xml_name, image_file,dst, class_names):tree = ET.parse(xml_file)root = tree.getroot()# 读取图像以获取准确的尺寸image = cv2.imread(image_file)if image is None:raise FileNotFoundError(f"Image file not found: {image_file}")image_size = [image.shape[1], image.shape[0]]  # [width, height]output_path = os.path.join(dst, xml_name.replace(".xml", '.txt'))with open(output_path, 'w') as out_file:for obj in root.iter('object'):difficult = obj.find('difficult').textclass_name = obj.find('name').textif class_name not in class_names or int(difficult) == 1:continueclass_id = class_names.index(class_name)xmlbox = obj.find('bndbox')b = (float(xmlbox.find('xmin').text), float(xmlbox.find('xmax').text), float(xmlbox.find('ymin').text), float(xmlbox.find('ymax').text))bb = convert(image_size, b)out_file.write(f"{class_id} {bb[0]} {bb[1]} {bb[2]} {bb[3]}\n")if __name__ == '__main__':xml_dir = "/data2/dataset/abcd/20250305/xml" #xml标签路径image_dir = "/data2/dataset/abcd/20250305/images" #图像路径output_dir = "/data2/dataset/abcd/20250305/labels" #输出的txt路径class_names = ['aaa', 'bbb', 'ccc', 'ddd']  # 类别名称列表xml_file_list = []xml_file_list = getFileList(xml_dir, xml_file_list, '.xml')lenth = len(xml_file_list)i = 1for xml_file in xml_file_list:xml_name = os.path.basename(xml_file)image_name = xml_name.replace(".xml", ".jpg")image_file = os.path.join(image_dir, image_name)if not os.path.exists(image_file):print(f"image file not found: {image_file}")continueconvert_annotation(xml_file, xml_name, image_file, output_dir, class_names)print('{}/{}'.format(i, lenth))i += 1

http://www.yayakq.cn/news/978499/

相关文章:

  • mvc 5 做网站的教程移动网站开发百科
  • 深圳龙华观澜网站建设公司wordpress主题支持分页
  • 公司英文网站建设html点餐网页简单代码
  • 吉林省建设厅安全证查询网站网页加速器插件
  • 免费网站建设制作怎么写网站文案
  • 拼多多网店seo优化培训公司
  • 淘宝装修可以做代码的网站有哪些嵌入式培训班一般多少钱
  • 了解当前各类网站建设价格姑苏网站建设
  • 怎样做网站平台赚钱吗济南城乡建设网站
  • 食品营销型网站seo体系百科
  • 上海网站制作培训网站空间网站虚拟空间
  • 网站开发算法面试wordpress中文二次元
  • 青之峰做网站响应式网页开发
  • 20m带宽做网站够用吗网站群建设调研报告
  • 产品网站怎样做外部链接宣传册设计与制作模板
  • wordpress二级目录百度快照如何优化
  • 报告总结网站建设实验网上购物平台有哪些
  • 宁远网站建设佛山网站设计哪家便宜
  • wordpress创建分站点网站培训培训班
  • 自助建站系统搭建网站源码php
  • 中小型企业网站优化案例周口哪家做网站好
  • 做一手房用什么网站好上海网站建设 润
  • 遵义花果园网站建设营销型网站效果不好
  • 长沙网站制作公司推荐企业网站营销实现方式解读
  • 国外网站推广公司信息展示网站系统
  • 西安专业网站建设报价辽宁省建设工程信息网网址
  • 怎么分析一个网站网站建设的意义
  • 深圳网站建设深圳网站首页图片轮转代码 很好用
  • 中天建设集团山西分公司网站三站合一网站
  • 温州建设集团网站佛山网站制作网站