当前位置:网站首页>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 :
边栏推荐
- Get the uppercase initials of Chinese Pinyin in PHP
- Regular expressions in MySQL
- [introduction to information retrieval] Chapter II vocabulary dictionary and inverted record table
- Traditional target detection notes 1__ Viola Jones
- MoCO ——Momentum Contrast for Unsupervised Visual Representation Learning
- Using MATLAB to realize: Jacobi, Gauss Seidel iteration
- A summary of a middle-aged programmer's study of modern Chinese history
- Using compose to realize visible scrollbar
- parser.parse_args 布尔值类型将False解析为True
- Delete the contents under the specified folder in PHP
猜你喜欢

Implementation of purchase, sales and inventory system with ssm+mysql

机器学习理论学习:感知机

Memory model of program

点云数据理解(PointNet实现第3步)

SSM second hand trading website

A slide with two tables will help you quickly understand the target detection

Ding Dong, here comes the redis om object mapping framework

SSM garbage classification management system

Faster-ILOD、maskrcnn_ Benchmark installation process and problems encountered

论文写作tip2
随机推荐
[in depth learning series (8)]: principles of transform and actual combat
[introduction to information retrieval] Chapter 3 fault tolerant retrieval
Using MATLAB to realize: power method, inverse power method (origin displacement)
[mixup] mixup: Beyond Imperial Risk Minimization
yolov3训练自己的数据集(MMDetection)
Using compose to realize visible scrollbar
parser. parse_ Args boolean type resolves false to true
论文tips
Get the uppercase initials of Chinese Pinyin in PHP
Transform the tree structure into array in PHP (flatten the tree structure and keep the sorting of upper and lower levels)
Regular expressions in MySQL
Find in laravel8_ in_ Usage of set and upsert
【信息检索导论】第七章搜索系统中的评分计算
Using MATLAB to realize: Jacobi, Gauss Seidel iteration
latex公式正体和斜体
【TCDCN】《Facial landmark detection by deep multi-task learning》
How do vision transformer work? [interpretation of the paper]
Faster-ILOD、maskrcnn_benchmark训练coco数据集及问题汇总
【信息检索导论】第一章 布尔检索
One field in thinkphp5 corresponds to multiple fuzzy queries