当前位置:网站首页>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)
边栏推荐
- Router bridging settings
- Live review | smardaten lihongfei interprets the Research Report on China's low / no code industry: the wind direction has changed
- 板端电源硬件调试BUG
- 运行时端常用类的介绍
- [program compilation and pretreatment]
- 关于小程序tabbar不支持传参的处理办法
- Runtimeerror: object has no attribute NMS error record when using detectron2
- 上下架和橱窗推荐如何设置,优化过程需要注意的地方
- Practice is the fastest way to become a network engineer
- Load other related resources or configurations (promise application of the applet) before loading the homepage of the applet
猜你喜欢

Phpcms applet plug-in version 4.0 was officially launched

51 single chip microcomputer ROM and ram

phpcms小程序插件教程网站正式上线

PD快充磁吸移动电源方案

Slider verification - personal test (JD)

【开源】使用PhenoCV-WeedCam进行更智能、更精确的杂草管理

《一周搞定数电》——组合逻辑电路

20220623 getting started with Adobe Illustrator

直播回顾 | smardaten李鸿飞解读中国低/无代码行业研究报告:风向变了

phpcms v9商城模块(修复自带支付宝接口bug)
随机推荐
[qnx hypervisor 2.2 user manual]12.1 terminology (I)
Lagrange multiplier method
攔截器與過濾器的實現代碼
51 single chip microcomputer ROM and ram
Yolov5 advanced level 2 installation of labelimg
20220213 Cointegration
20220623 Adobe Illustrator入门
【MATLAB GUI】 键盘回调中按键识别符查找表
[open source] use phenocv weedcam for more intelligent and accurate weed management
Some commands for remote work
Phpcms V9 background article list adds one click push to Baidu function
教程1:Hello Behaviac
【程序的编译和预处理】
Runtimeerror: object has no attribute NMS error record when using detectron2
Self taught programming series - 1 regular expression
[Matlab GUI] key ID lookup table in keyboard callback
Mongodb分片环境搭建和验证(redis期末大作业)
行為樹XML文件 熱加載
Live review | smardaten lihongfei interprets the Research Report on China's low / no code industry: the wind direction has changed
Chargement à chaud du fichier XML de l'arbre de comportement