当前位置:网站首页>快速批量修改VOC格式数据集标签的文件名,即快速批量修改.xml文件名
快速批量修改VOC格式数据集标签的文件名,即快速批量修改.xml文件名
2022-08-05 00:44:00 【佐咖】
快速批量修改VOC格式数据集标签的文件名,即快速批量修改.xml文件名,使用下面代码时,只需要修改两个路径即可,见下:

具体代码见下:
import os
class BatchRename():
''' 批量重命名文件夹中的xml文件 '''
def __init__(self):
self.path = 'coco/valxml' #表示需要命名处理的文件夹
self.save_path='coco/valxml 2'#保存重命名后的图片地址
def rename(self):
filelist = os.listdir(self.path) #获取文件路径
total_num = len(filelist) #获取文件长度(个数)
i = 1 #表示文件的命名是从1开始的
for item in filelist:
print(item)
if item.endswith('.xml'): #初始的图片的格式为jpg格式的(或者源文件是png格式及其他格式,后面的转换格式就可以调整为自己需要的格式即可)
src = os.path.join(os.path.abspath(self.path), item)#当前文件中图片的地址
dst = os.path.join(os.path.abspath(self.save_path), ''+str(i) + '.xml')#处理后文件的地址和名称,可以自己按照自己的要求改进
try:
os.rename(src, dst)
print ('converting %s to %s ...' % (src, dst))
i = i + 1
except:
continue
print ('total %d to rename & converted %d jpgs' % (total_num, i))
if __name__ == '__main__':
demo = BatchRename()
demo.rename()
以上方法就是快速批量修改VOC格式数据集标签的文件名,即快速批量修改.xml文件名。希望能帮助到你,多多支持,谢谢!
边栏推荐
- ### Error querying database. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionExcep
- 进程间通信和线程间通信
- 软件测试面试题:测试生命周期,测试过程分为几个阶段,以及各阶段的含义及使用的方法?
- 软件测试面试题:做好测试计划的关键是什么?
- Software Testing Interview Questions: What's the Key to a Good Test Plan?
- 阶段性测试完成后,你进行缺陷分析了么?
- GCC:编译时库路径和运行时库路径
- 2022牛客多校第三场 A Ancestor
- leetcode: 266. All Palindromic Permutations
- 创意代码表白
猜你喜欢
随机推荐
ORA-00257
Kubernetes 网络入门
2022 Hangzhou Electric Multi-School 1004 Ball
Software testing interview questions: What stages should a complete set of tests consist of?
软件测试面试题:做好测试计划的关键是什么?
GCC: Shield dependencies between dynamic libraries
Knowledge Points for Network Planning Designers' Morning Questions in November 2021 (Part 2)
软件测试面试题:软件验收测试的合格通过准则?
软件测试面试题:什么是软件测试?软件测试的目的与原则?
LiveVideoStackCon 2022 上海站明日开幕!
2022 Hangzhou Electric Multi-School Training Session 3 1009 Package Delivery
Software Testing Interview Questions: What do you think about software process improvement? Is there something that needs improvement in the enterprise you have worked for? What do you expect the idea
D - I Hate Non-integer Number (count of selected number dp
软件测试面试题:软件测试类型都有哪些?
leetcode: 269. The Martian Dictionary
Software Testing Interview Questions: About Automated Testing Tools?
软件测试面试题:负载测试、容量测试、强度测试的区别?
Binary tree [full solution] (C language)
B站7月榜单丨飞瓜数据B站UP主排行榜发布!
Software Testing Interview Questions: What's the Difference Between Manual Testing and Automated Testing?









