新建一个文件夹,用来存放整个数据集,或者和voc2007一样的名字:VOC2007 
然后在文件夹里面新建如下文件夹:

制作自己的数据集(VOC2007格式)用于Faster-RCNN训练

二、将训练图片放到JPEGImages

将所有的训练图片放到该文件夹里,然后将图片重命名为VOC2007的“000005.jpg”形式

重命名的python代码为:

import os
path = r"D:\VOC2007\JPEGImages"
filelist = os.listdir(path) #该文件夹下所有的文件(包括文件夹)
count=0
for file in filelist:
    print(file)
for file in filelist:   #遍历所有文件
    Olddir=os.path.join(path,file)   #原来的文件路径
    if os.path.isdir(Olddir):   #如果是文件夹则跳过
        continue
    filename=os.path.splitext(file)[0]   #文件名
    filetype=‘.jpg’   #文件扩展名
    Newdir=os.path.join(path,str(count).zfill(6)+filetype)  #用字符串函数zfill 以0补全所需位数
    os.rename(Olddir,Newdir)#重命名
    count+=1
重命名

相关文章:

  • 2021-05-14
  • 2022-01-25
  • 2021-07-15
  • 2022-12-23
  • 2022-01-20
  • 2022-12-23
  • 2022-12-23
  • 2021-09-03
猜你喜欢
  • 2022-12-23
  • 2022-01-30
  • 2021-08-25
  • 2021-05-29
  • 2021-12-26
相关资源
相似解决方案