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

得到xml所有label 名字和数量 get_xml_lab.py,get_json_lab.py

import os
import xml.etree.ElementTree as ETrootdir2 = r"F:\images3\xmls"
file_list = os.listdir(rootdir2)  # 列出文件夹下所有的目录与文件# 初始化字典
classes_dict = {}for file_name in file_list:path = os.path.join(rootdir2, file_name)if os.path.isfile(path):# 解析XML文件tree = ET.parse(path)root = tree.getroot()# 获取所有object标签中的name子标签for obj in root.findall('object'):name = obj.find('name').textif name not in classes_dict:classes_dict[name] = 1else:classes_dict[name] += 1# 打印统计结果
for k, v in classes_dict.items():print(k, v)
print(classes_dict.keys())print("图片总数:", len(file_list))
import os
import jsonrootdir2 = r"F:\images3\jsons"
file_list = os.listdir(rootdir2)  # 列出文件夹下所有的目录与文件# 初始化字典
label_count = {}for file_name in file_list:path = os.path.join(rootdir2, file_name)if os.path.isfile(path) and path.endswith('.json'):# 打开并读取JSON文件with open(path, 'r', encoding='utf-8') as f:data = json.load(f)# 遍历shapes列表中的所有对象并统计labelif 'shapes' in data:for shape in data['shapes']:label = shape.get('label')if label:if label not in label_count:label_count[label] = 1else:label_count[label] += 1# 打印统计结果
for k, v in label_count.items():print(k, v)
print(label_count.keys())print("文件总数:", len(file_list))
http://www.lryc.cn/news/409972.html

相关文章:

  • 数据结构算法-排序(二)
  • Linux安装与配置
  • AI赋能交通治理:非机动车监测识别技术在城市街道安全管理中的应用
  • 水电站泄洪放水预警广播系统解决方案
  • 【Django】ajax和django接口交互(获取新密码)
  • Logback 日志打印导致程序崩溃的实战分析
  • 新加坡 Numen Cyber 与香港光环云数据有限公司达成战略合作
  • Laravel魔术方法:框架的隐秘力量
  • 系统复习Java日志体系
  • 网络管理linux命令
  • PowerDNS架构解析与安装部署指南
  • Ubuntu 20.04.6 安装 Elasticsearch
  • Python for循环迭代原理(迭代器 Iterator)
  • 通信原理-思科实验四:静态路由项配置实验
  • ngzero使用外部的svg图标
  • 逆矩阵、秩
  • pc端小程序抓包修改数据相关记录
  • 用Python打造精彩动画与视频.2.1 Python基础语法概述
  • Golang高效合并(拼接)多个gzip压缩文件
  • MySQL数据库-基本概念
  • 【无标题】web+http协议+nginx搭建+nginx反向代理(环境准备)
  • c-periphery RS485串口库文档serial.md(serial.h)(非阻塞读)(VMIN、VTIME)
  • Matlab arrayfun 与 bsxfun——提高编程效率的利器!
  • 【Unity编辑器拓展】GraphView自定义可视化节点
  • 教程系列4 | 趋动云『社区项目』极速体验 LivePortrait 人脸表情“移花接木”大法
  • WGS84、GCJ-02、BD09三大坐标系详解
  • css上下动画 和淡化
  • 深入解析C#中的URI和URL编码:理解EscapeDataString、EscapeUriString和UrlEncode的区别及字符编码错误处理
  • 【CSS】给图片设置 max-width
  • 区块链——代码格式检查(prettier、solhint)