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

南通网站推广公司哪家好360优化大师app

南通网站推广公司哪家好,360优化大师app,wordpress用什么系统,网站设计导航栏怎么做本文不生产技术,只做技术的搬运工!!! 前言 在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.dinnco.com/news/31594.html

相关文章:

  • 辅助购卡网站怎么做电商详情页模板免费下载
  • soe标题打开直接显示网站怎么做怎么推广自己的公司
  • 厦门首屈一指网站建设百度 官网
  • iis7 伪静态 wordpress搜索引擎优化的实验结果分析
  • 南宁网站制作企业引擎搜索优化
  • 大型企业网站建设论坛推广
  • 包头市做网站哪个百度识图识别
  • 公司网站制作可以使用开源系统吗南昌网站建设
  • 网站建设 江苏长沙市最新疫情
  • 做网站的公司有哪些岗位晋江怎么交换友情链接
  • 微小店网站建设哪家好站长工具四叶草
  • php网站的数据库怎么做备份电商培训机构排名前十
  • 邛崃网站建设网络促销方案
  • web怎样插入自己做的网站三只松鼠网络营销策略
  • 银川网站设计建设东方网络律师团队
  • 个人网站模板下载搜索关键词排名一般按照什么收费
  • wordpress google字体本地qq群排名优化
  • 医院网站改版建设招标公告sem优化软件哪家好
  • 网站平台建设重点难点分析上海网络推广公司网站
  • 做衣服的网站推荐网络品牌推广
  • 可以做司考真题的网站seo服务优化
  • 网站建设q-9外贸网络营销
  • 做网站的应该怎么发广告百度平台联系方式
  • 怎么自己做网站表白教育培训机构
  • 韩路做的网站是什么名字今日头条官网登录入口
  • 做直播 网站的上市公司搜索引擎推广有哪些
  • 做网站需要什么步骤下载优化大师并安装
  • 山西省吕梁市简介网站优化seo是什么意思
  • 招标网站免费新乡seo顾问
  • wordpress fonts.googleapi二十条优化措施