当前位置:网站首页>Mmdetection trains its own data set -- export coco format of cvat annotation file and related operations
Mmdetection trains its own data set -- export coco format of cvat annotation file and related operations
2022-07-02 07:41:00 【chenf0】
See the previous configuration and the messy problems encountered :https://blog.csdn.net/chenfang0529/article/details/115094036
One 、 export
Use mmdetection Train your own dataset , Dataset use VCAT Annotate , The marked file is a video file , Export image frames and annotation files as COCO Format . There are also PASCAL VOC
Include two files after Export
images and annotations
images Contains image frames
annotations Include dimension files , We only need to modify the third file .
Two 、 Related codes
1. Batch modify the picture name
import os
class BatchRename():
def rename(self):
path="D:\\achenf\data\\taxi\\test\\task_2_9_car_test-2021_04_13_13_25_24-coco\images"
filelist=os.listdir(path)
total_num = len(filelist)
i=595
for item in filelist:
if item.endswith('.jpg'):
src=os.path.join(os.path.abspath(path),item)
dst=os.path.join(os.path.abspath(path),''+str(i)+'.jpg') # You can choose the format according to your needs
# dst=os.path.join(os.path.abspath(path),'00000'+format(str(i))+'.jpg') # You can choose the format according to your needs , Custom picture name
try:
os.rename(src,dst) #src: old name dst New name d
i+=1
except:
continue
print ('total %d to rename & converted %d png'%(total_num,i))
if __name__=='__main__':
demo = BatchRename()
demo.rename()
2. Bulk changes json The contents of the document
json in id Etc. need to correspond with the picture .
Needed json It contains five parts ,info,categories,licenses,annotations,images
We just need to modify it annotations and images Two parts .
import json
import os
path = 'D:\\achenf\data\\taxi\\train\\task_2_8_car_test-2021_04_13_13_25_07-coco\\annotations\\test'
dirs = os.listdir(path)
num_flag = 0
for file in dirs: # Loop to read the file under the path and filter the output
if os.path.splitext(file)[1] == ".json": # Screening csv file
num_flag = num_flag +1
print("path ===== ",file)
print(os.path.join(path,file))
with open(os.path.join(path,file),'r') as load_f:
load_dict = json.load(load_f)
# print(load_dict)
# n=len(load_dict["image_id"])
# print(type(load_dict))
# for i in load_dict:
# print(i)
for i in load_dict['annotations']:
i['image_id'] = i['image_id'] + 595
i['id']=i['id']+2032
# if i['image_id']>=595:
# i['id']=i['id']+3015
for i in load_dict['images']:
i['id'] = i['id'] + 595
i['file_name'] = ""+str(i['id'])+".jpg"
with open(os.path.join(path,file),'w') as dump_f:
json.dump(load_dict, dump_f)
if(num_flag == 0):
print(' The selected folder does not exist json file , Please re confirm the folder you want to select ')
else:
print(' common {} individual json file '.format(num_flag))
Finally, merge the corresponding parts
3、 ... and 、 other
1. analysis xml file , Check the number of annotations in the file
import os
import xml.dom.minidom
res=0
AnnoPath = r'./file_xml/0512/'
Annolist = os.listdir(AnnoPath)
for annotation in Annolist:
filename =AnnoPath + annotation
dom = xml.dom.minidom.parse(filename) # open XML file
collection = dom.documentElement # Get element object
objectlist = collection.getElementsByTagName('box') # s
count = objectlist.length
res =res+count
print(" file name :", filename," Number of dimensions :", count)
print(" Total labels :", res)
result :
边栏推荐
- 【Ranking】Pre-trained Language Model based Ranking in Baidu Search
- [introduction to information retrieval] Chapter 6 term weight and vector space model
- Interpretation of ernie1.0 and ernie2.0 papers
- Proof and understanding of pointnet principle
- 【Cutout】《Improved Regularization of Convolutional Neural Networks with Cutout》
- Get the uppercase initials of Chinese Pinyin in PHP
- Implement interface Iterable & lt; T>
- Cognitive science popularization of middle-aged people
- Comparison of chat Chinese corpus (attach links to various resources)
- 【Torch】解决tensor参数有梯度,weight不更新的若干思路
猜你喜欢
Pointnet understanding (step 4 of pointnet Implementation)
Alpha Beta Pruning in Adversarial Search
ABM thesis translation
【Mixup】《Mixup:Beyond Empirical Risk Minimization》
Win10+vs2017+denseflow compilation
【多模态】CLIP模型
[medical] participants to medical ontologies: Content Selection for Clinical Abstract Summarization
Practice and thinking of offline data warehouse and Bi development
The difference and understanding between generative model and discriminant model
【Hide-and-Seek】《Hide-and-Seek: A Data Augmentation Technique for Weakly-Supervised Localization xxx》
随机推荐
[mixup] mixup: Beyond Imperial Risk Minimization
PPT的技巧
[introduction to information retrieval] Chapter 7 scoring calculation in search system
Ppt skills
【Paper Reading】
Point cloud data understanding (step 3 of pointnet Implementation)
Cognitive science popularization of middle-aged people
《Handwritten Mathematical Expression Recognition with Bidirectionally Trained Transformer》论文翻译
Traditional target detection notes 1__ Viola Jones
Transform the tree structure into array in PHP (flatten the tree structure and keep the sorting of upper and lower levels)
【信息检索导论】第二章 词项词典与倒排记录表
allennlp 中的TypeError: Object of type Tensor is not JSON serializable错误
【Torch】最简洁logging使用指南
win10解决IE浏览器安装不上的问题
【MEDICAL】Attend to Medical Ontologies: Content Selection for Clinical Abstractive Summarization
Delete the contents under the specified folder in PHP
传统目标检测笔记1__ Viola Jones
【TCDCN】《Facial landmark detection by deep multi-task learning》
TimeCLR: A self-supervised contrastive learning framework for univariate time series representation
Deep learning classification Optimization Practice