当前位置:网站首页>Statistics of various target quantities of annotations (XML annotation format)
Statistics of various target quantities of annotations (XML annotation format)
2022-06-26 09:14:00 【G fruit】
Be careful :
The code in this article suggests that the image and annotation files should be separated
The picture exists images Under the folder ( It's not used here )
Annotation file exists annotations Under the folder
There is also a tqdm Library to display the progress bar , No need to comment out
import xml.etree.ElementTree as ET # Import xml modular
import pickle
import os
import glob
from os import listdir, getcwd
from os.path import join
from tqdm import tqdm# Missing packages need to be installed
def class_num(_dir,class_name,dataset,nums):
result = {
}
for clss in class_name:
result[clss]=0 # Number of labels per category
#print(result)
result["other"]=0# Number of other labels
result["sum"]=0# Total number of labels
#total Parameter sets the total length of the progress bar
pbar = tqdm(total=nums,desc="%s-porcess"%dataset,unit="xml")
for xmll in glob.glob(_dir+"*.xml"):
#print(xml)
#time.sleep(0.05)
pbar.update(1)# The length of each update progress bar
with open(xmll,"r",encoding="utf-8") as f:
xml = ET.parse(f)
# root = xml.getroot()
# print(root.findall("object"))
for obj in xml.iter('object'):
result["sum"] = result["sum"]+1
if obj.find("name").text not in class_name:
result["other"] = result["other"]+1
for clsn in class_name:
if obj.find("name").text == clsn: # Make statistics according to the labeled tag name
result[clsn] = result[clsn]+1
pbar.close()# Close occupied resources
return result
if __name__ == '__main__':
train_dir="E:/DL/detectron2/SwinT_detectron2/datasets/new/train/annotations/"
test_dir="E:/DL/detectron2/SwinT_detectron2/datasets/test/annotations/"
class_name = ["0","1","2"]# Name of each category when marking
train_num = len(os.listdir(train_dir))# Calculate the number of label files
test_num = len(os.listdir(test_dir))
print(train_num,test_num)
results1 = class_num(train_dir,class_name,"train",train_num)
results2 = class_num(test_dir,class_name,"test",test_num)
print("\n\n Training set : ",results1)
print("\n Test set : ",results2)
边栏推荐
- In depth study paper reading target detection (VII) Chinese version: yolov4 optimal speed and accuracy of object detection
- Notes on setting qccheckbox style
- How to set the shelves and windows, and what to pay attention to in the optimization process
- Baidu applet rich text parsing tool bdparse
- Lagrange multiplier method
- Self learning neural network series - 8 feedforward neural networks
- 【开源】使用PhenoCV-WeedCam进行更智能、更精确的杂草管理
- Uniapp uses uparse to parse the content of the background rich text editor and modify the uparse style
- 【300+精选大厂面试题持续分享】大数据运维尖刀面试题专栏(一)
- Basic concept and advanced level of behavior tree
猜你喜欢

编辑类型信息

XSS cross site scripting attack

Phpcms mobile station module implements custom pseudo static settings

phpcms v9去掉phpsso模块

Live review | smardaten lihongfei interprets the Research Report on China's low / no code industry: the wind direction has changed

行为树 文件说明

ThreadLocal

Particles and sound effect system in games104 music 12 game engine

Yolov5 advanced 4 train your own data set

板端电源硬件调试BUG
随机推荐
Nacos注册表结构和海量服务注册与并发读写原理 源码分析
[cloud primordial | kubernetes chapter] go deep into the foundation of all things - container (V)
PD快充磁吸移动电源方案
phpcms v9后台文章列表增加一键推送到百度功能
Fix the problem that the rich text component of the applet does not support the properties of video cover, autoplay, controls, etc
浅谈一下Type-C接口发展历程
MySQL在服务里找不到(未卸载)
Srv6---is-is extension
Dedecms applet plug-in is officially launched, and one click installation does not require any PHP or SQL Foundation
Machine learning (Part 2)
phpcms小程序插件4.0版正式上线
20220623 Adobe Illustrator入门
简析ROS计算图级
Self learning neural network sequence -- 2 perceptron
《一周搞定数电》——编码器和译码器
Yolov5 advanced 5 GPU environment setup
Self taught neural network series - 9 convolutional neural network CNN
[IVI] 15.1.2 system stability optimization (lmkd Ⅱ) psi pressure stall information
Practice is the fastest way to become a network engineer
Data warehouse (3) star model and dimension modeling of data warehouse modeling