当前位置:网站首页>快速批量修改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文件名。希望能帮助到你,多多支持,谢谢!
边栏推荐
猜你喜欢
If capturable=False, state_steps should not be CUDA tensors
PCIe 核配置
node uses redis
Dynamic Programming/Knapsack Problem Summary/Summary - 01 Knapsack, Complete Knapsack
金九银十面试跳槽季;你准备好了吗?
内存取证系列1
could not build server_names_hash, you should increase server_names_hash_bucket_size: 32
After the staged testing is complete, have you performed defect analysis?
PCIe Core Configuration
Will domestic websites use Hong Kong servers be blocked?
随机推荐
僵尸进程和孤儿进程
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
Software Testing Interview Questions: What is Software Testing?The purpose and principle of software testing?
软件测试面试题:BIOS, Fat, IDE, Sata, SCSI, Ntfs windows NT?
gorm joint table query - actual combat
E - Distance Sequence (prefix and optimized dp
2022 Hangzhou Electric Power Multi-School Session 3 Question L Two Permutations
ora-00604 ora-02429
Helm Chart
软件测试面试题:手工测试与自动测试有哪些区别?
tiup update
oracle create tablespace
2022牛客多校训练第二场 J题 Link with Arithmetic Progression
oracle create user
[FreeRTOS] FreeRTOS and stm32 built-in stack occupancy
Difference between MBps and Mbps
2022 The Third J Question Journey
SV class virtual method of polymorphism
Software Testing Interview Questions: What's the Difference Between Manual Testing and Automated Testing?
LiveVideoStackCon 2022 Shanghai Station opens tomorrow!