当前位置:网站首页>快速批量修改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文件名。希望能帮助到你,多多支持,谢谢!
边栏推荐
猜你喜欢

国内网站用香港服务器会被封吗?

JVM类加载简介

LiveVideoStackCon 2022 上海站明日开幕!

DHCP的工作过程

JUC thread pool (1): FutureTask use
![[230] Execute command error after connecting to Redis MISCONF Redis is configured to save RDB snapshots](/img/fa/5bdc81b1ebfc22d31f42da34427f3e.png)
[230] Execute command error after connecting to Redis MISCONF Redis is configured to save RDB snapshots

码率vs.分辨率,哪一个更重要?

MongoDB construction and basic operations

金九银十面试跳槽季;你准备好了吗?

CNI(Container Network Plugin)
随机推荐
2022 The Third J Question Journey
FSAWS 的全球基础设施和网络
活动推荐 | 快手StreamLake品牌发布会,8月10日一起见证!
软件测试面试题:您以往所从事的软件测试工作中,是否使用了一些工具来进行软件缺陷(Bug)的管理?如果有,请结合该工具描述软件缺陷(Bug)跟踪管理的流程?
After the staged testing is complete, have you performed defect analysis?
主库预警日志报错ORA-00270
oracle create user
Raw and scan of gorm
Software testing interview questions: Have you used some tools for software defect (Bug) management in your past software testing work? If so, please describe the process of software defect (Bug) trac
[idea] idea configures sql formatting
The method of freely controlling concurrency in the sync package in GO
仅3w报价B站up主竟带来1200w播放!品牌高性价比B站投放标杆!
Inter-process communication and inter-thread communication
软件测试面试题:网络七层协仪具体?
Software Testing Interview Questions: What's the Key to a Good Test Plan?
Helm Chart
ORA-00257
软件测试面试题:做好测试计划的关键是什么?
TinyMCE禁用转义
D - I Hate Non-integer Number (count of selected number dp