当前位置:网站首页>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)
边栏推荐
- 运行时端的执行流程
- 【C】 Frog jumping steps and Hanoi Tower problem (recursion)
- Self learning neural network sequence -- 2 perceptron
- 教程1:Hello Behaviac
- Mongodb分片环境搭建和验证(redis期末大作业)
- 拦截器与过滤器的实现代码
- Applet realizes picture preloading (picture delayed loading)
- Introduction to common classes on the runtime side
- Phpcms V9 adds the reading amount field in the background, and the reading amount can be modified at will
- Which software is safer to open an account on
猜你喜欢

设置QCheckbox 样式的注意事项

XSS cross site scripting attack

phpcms v9后台文章列表增加一键推送到百度功能

PD快充磁吸移動電源方案

ThreadLocal

Vipshop work practice: Jason's deserialization application

【300+精选大厂面试题持续分享】大数据运维尖刀面试题专栏(一)

In depth study paper reading target detection (VII) Chinese version: yolov4 optimal speed and accuracy of object detection

【MATLAB GUI】 键盘回调中按键识别符查找表

【C】青蛙跳台阶和汉诺塔问题(递归)
随机推荐
Principle and application of single chip microcomputer -- Overview
Adding confidence threshold for demo visualization in detectron2
Vipshop work practice: Jason's deserialization application
Pytorch build progression
Data warehouse (3) star model and dimension modeling of data warehouse modeling
Differences between commonjs and ES6 modularity
Analysis of ROS calculation diagram level
【微积分】拉格朗日乘子法
Programming training 7- date conversion problem
Unity webgl publishing cannot run problem
Fast construction of neural network
《单片机原理及应用》——概述
Sublime Text3 common plug-ins
phpcms小程序插件api接口升级到4.3(新增批量获取接口、搜索接口等)
20220213 Cointegration
Self taught neural network series - 4 learning of neural network
关于小程序tabbar不支持传参的处理办法
HDU - 6225 little boxes (\u int128)
行為樹XML文件 熱加載
Unity WebGL发布无法运行问题