当前位置:网站首页>mmdetection训练自己的数据集--CVAT标注文件导出coco格式及相关操作
mmdetection训练自己的数据集--CVAT标注文件导出coco格式及相关操作
2022-07-02 06:26:00 【chenf0】
前期配置及遇到的乱七八糟的问题等见:https://blog.csdn.net/chenfang0529/article/details/115094036
一、导出
使用mmdetection训练自己的数据集,数据集使用VCAT进行标注,标注的文件是视频文件,将图像帧及标注文件导出为COCO格式。常用的还有PASCAL VOC
导出后包括两个文件
images和annotations
images中包含图像帧
annotations包含标注文件,我们只需要对第三个文件进行修改。
二、相关代码
1.批量修改图片名
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') #可根据自己需求选择格式
# dst=os.path.join(os.path.abspath(path),'00000'+format(str(i))+'.jpg') #可根据自己需求选择格式,自定义图片名字
try:
os.rename(src,dst) #src:原名称 dst新名称d
i+=1
except:
continue
print ('total %d to rename & converted %d png'%(total_num,i))
if __name__=='__main__':
demo = BatchRename()
demo.rename()
2.批量修改json文件内容
json中id等需要和图片进行对应。
需要的json中包含五部分,info,categories,licenses,annotations,images
我们只需要修改annotations和images两部分。
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: # 循环读取路径下的文件并筛选输出
if os.path.splitext(file)[1] == ".json": # 筛选csv文件
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('所选文件夹不存在json文件,请重新确认要选择的文件夹')
else:
print('共{}个json文件'.format(num_flag))
最后将各个对应的部分进行合并
三、其他
1.解析xml文件,查看文件中标注个数
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) # 打开XML文件
collection = dom.documentElement # 获取元素对象
objectlist = collection.getElementsByTagName('box') # s
count = objectlist.length
res =res+count
print("文件名:", filename,"标注数:", count)
print("一共标注:", res)
结果:
边栏推荐
- 【MEDICAL】Attend to Medical Ontologies: Content Selection for Clinical Abstractive Summarization
- A slide with two tables will help you quickly understand the target detection
- 【Torch】最简洁logging使用指南
- Oracle 11g sysaux table space full processing and the difference between move and shrink
- 【信息检索导论】第一章 布尔检索
- Ding Dong, here comes the redis om object mapping framework
- 点云数据理解(PointNet实现第3步)
- 软件开发模式之敏捷开发(scrum)
- 华为机试题-20190417
- @Transitional step pit
猜你喜欢

DNS attack details

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

ERNIE1.0 与 ERNIE2.0 论文解读

Faster-ILOD、maskrcnn_benchmark安装过程及遇到问题

Alpha Beta Pruning in Adversarial Search

Three principles of architecture design

Interpretation of ernie1.0 and ernie2.0 papers

【信息检索导论】第七章搜索系统中的评分计算
![[introduction to information retrieval] Chapter 1 Boolean retrieval](/img/78/df4bcefd3307d7cdd25a9ee345f244.png)
[introduction to information retrieval] Chapter 1 Boolean retrieval
![[Bert, gpt+kg research] collection of papers on the integration of Pretrain model with knowledge](/img/2e/e74d7a9efbf9fe617f4d7b46867c0a.png)
[Bert, gpt+kg research] collection of papers on the integration of Pretrain model with knowledge
随机推荐
腾讯机试题
【Torch】最简洁logging使用指南
《Handwritten Mathematical Expression Recognition with Bidirectionally Trained Transformer》论文翻译
Oracle EBs and apex integrated login and principle analysis
Faster-ILOD、maskrcnn_benchmark训练coco数据集及问题汇总
Illustration of etcd access in kubernetes
【MEDICAL】Attend to Medical Ontologies: Content Selection for Clinical Abstractive Summarization
SSM laboratory equipment management
【调参Tricks】WhiteningBERT: An Easy Unsupervised Sentence Embedding Approach
PHP returns the corresponding key value according to the value in the two-dimensional array
view的绘制机制(三)
[model distillation] tinybert: distilling Bert for natural language understanding
MMDetection模型微调
[introduction to information retrieval] Chapter 3 fault tolerant retrieval
使用百度网盘上传数据到服务器上
离线数仓和bi开发的实践和思考
ABM论文翻译
ModuleNotFoundError: No module named ‘pytest‘
传统目标检测笔记1__ Viola Jones
PointNet理解(PointNet实现第4步)