美文网首页
数据集批量重命名(txt+jpg)

数据集批量重命名(txt+jpg)

作者: 疯人愿的疯言疯语 | 来源:发表于2019-02-27 17:22 被阅读0次
    #!usr/bin/python
    # -*- coding:utf-8 -*-
    
    import os
    
    
    # source train dir,训练集文件夹
    train_img_dir = "D:/gyh/DataSets/长微博数据/data"
    # source train dir,训练标注集文件夹
    train_txt_dir = "D:/gyh/DataSets/长微博数据/txt"
    
    
    # rename and move img to target_img_dir
    # train img
    i=0
    for file in os.listdir(train_img_dir):
        i=i+1
        img_name = os.path.splitext(os.path.basename(file))
        for txtfile in os.listdir(train_txt_dir):
            txt_name = os.path.splitext(os.path.basename(txtfile))
            if txt_name[0] == img_name[0]:
                os.rename(os.path.join(train_img_dir, file),
                  os.path.join(train_img_dir, "cwb_" + str(i) + ".jpg"))
                os.rename(os.path.join(train_txt_dir, txtfile),
                  os.path.join(train_txt_dir, "cwb_" + str(i) + ".txt"))
    

    相关文章

      网友评论

          本文标题:数据集批量重命名(txt+jpg)

          本文链接:https://www.haomeiwen.com/subject/pjgfuqtx.html