当前位置:网站首页>Mmclassification annotation file generation
Mmclassification annotation file generation
2022-07-04 09:40:00 【Coding leaves】
1 Data set composition
mmclassification The dataset mainly contains four folders meta、train、val、test, among meta Stored annotation information , contain train.txt、val.txt and test.txt Three files .train、val、test Images of different categories are stored . Its composition is shown in the figure below :

train.txt、val.txt and test.txt The file stores the image path and category id, As shown in the figure below :

train、val、test Images of different categories are stored , Images of the same category are located in the same subfolder , The name of the subfolder is the corresponding category name , As shown in the figure below :

The data in the above example image comes from minist Handwritten font visualization dataset , According to train、test Folder for storage , Download at :minist Handwritten digital visualization data set - Deep learning document resources -CSDN download .
2 Annotation file generation
Annotation file generation refers to the generation without meta In the case of folders , according to train、val、test The folder is automatically generated meta Folder , And its folder train.txt、val.txt and test.txt.
3 Reference procedure
# -*- coding: utf-8 -*-
"""
The official account of Lele perception school
@author: https://blog.csdn.net/suiyingy
"""
import os
from glob import glob
from pathlib import Path
def generate_mmcls_ann(data_dir, img_type='.png'):
data_dir = str(Path(data_dir)) + '/'
classes = ['0', '1', '2', '3', '4','5', '6', '7', '8', '9']
class2id = dict(zip(classes, range(len(classes))))
data_dir = str(Path(data_dir)) + '/'
dir_types = ['train', 'val', 'test']
sub_dirs = os.listdir(data_dir)
ann_dir = data_dir + 'meta/'
if not os.path.exists(ann_dir):
os.makedirs(ann_dir)
for sd in sub_dirs:
if sd not in dir_types:
continue
annotations = []
target_dir = data_dir + sd + '/'
for d in os.listdir(target_dir):
class_id = str(class2id[d])
images = glob(target_dir+d+'/*'+img_type)
for img in images:
img = d + '/' + os.path.basename(img)
annotations.append(img+' '+ class_id+'\n')
annotations[-1] = annotations[-1].strip()
with open(ann_dir+sd+'.txt', 'w') as f:
f.writelines(annotations)
if __name__ == '__main__':
data_dir = 'data/Minist Handwritten digital visualization data set /'
generate_mmcls_ann(data_dir) 4 Running results
After running the above reference program ,data_dir The folder will automatically generate meta Folder and corresponding txt file ,txt The content of the document is shown in the figure below .

5 【python Three dimensional deep learning 】python 3D point cloud from basic to deep learning _Coding Leaves blog -CSDN Blog _python Three dimensional point cloud
More 3D 、 Please pay attention to two-dimensional perception algorithm and financial quantitative analysis algorithm “ Lele perception school ” WeChat official account , And will continue to update .
边栏推荐
- Hands on deep learning (35) -- text preprocessing (NLP)
- How does idea withdraw code from remote push
- How should PMP learning ideas be realized?
- Reading notes on how to connect the network - tcp/ip connection (II)
- Simulate EF dbcontext with MOQ - mocking EF dbcontext with MOQ
- Go context 基本介绍
- Multilingual Wikipedia website source code development part II
- C # use smtpclient The sendasync method fails to send mail, and always returns canceled
- H5 audio tag custom style modification and adding playback control events
- Hands on deep learning (33) -- style transfer
猜你喜欢

品牌连锁店5G/4G无线组网方案

2022-2028 global special starch industry research and trend analysis report

Logstack configuration details -- elasticstack (elk) work notes 020

C # use gdi+ to add text to the picture and make the text adaptive to the rectangular area

ArrayBuffer

PHP student achievement management system, the database uses mysql, including source code and database SQL files, with the login management function of students and teachers

libmysqlclient. so. 20: cannot open shared object file: No such file or directory

Matlab tips (25) competitive neural network and SOM neural network

Function comparison between cs5261 and ag9310 demoboard test board | cost advantage of cs5261 replacing ange ag9310

2022-2028 global gasket metal plate heat exchanger industry research and trend analysis report
随机推荐
DR6018-CP01-wifi6-Qualcomm-IPQ6010-IPQ6018-FAMILY-2T2R-2.5G-ETH-port-CP01-802-11AX-MU-MIMO-OFDMA
PHP student achievement management system, the database uses mysql, including source code and database SQL files, with the login management function of students and teachers
Summary of the most comprehensive CTF web question ideas (updating)
2022-2028 global special starch industry research and trend analysis report
MySQL foundation 02 - installing MySQL in non docker version
lolcat
Launpad | Basics
Report on investment analysis and prospect trend prediction of China's MOCVD industry Ⓤ 2022 ~ 2028
How do microservices aggregate API documents? This wave of show~
MATLAB小技巧(25)竞争神经网络与SOM神经网络
[on February 11, 2022, the latest and most fully available script library collection of the whole network, a total of 23]
Implementing expired localstorage cache with lazy deletion and scheduled deletion
Write a jison parser from scratch (5/10): a brief introduction to the working principle of jison parser syntax
Some points needing attention in PMP learning
Global and Chinese markets of thrombography hemostasis analyzer (TEG) 2022-2028: Research Report on technology, participants, trends, market size and share
Golang Modules
Upgrading Xcode 12 caused Carthage to build cartfile containing only rxswift to fail
el-table单选并隐藏全选框
How web pages interact with applets
2022-2028 global intelligent interactive tablet industry research and trend analysis report