标签:pre name 文件 new code imp col list div
做caffe的训练数据的时候,有时候需要对图片进行批量重命名,脚本如下,
import os def rename_jpg(main_path, i): jpg_list = os.listdir(main_path) for jpg in jpg_list: if jpg.endswith(".jpg"): src = os.path.join(main_path, jpg) new_name = str(i) + ".jpg" i = i + 2 dst = os.path.join(main_path, new_name) print(src) print(dst) os.rename(src, dst) if __name__ == "__main__": rename_jpg(r"/data/test1", 0)#命名为偶数的,0,2,4,,, rename_jpg(r"/data/test2", 1)#命名为奇数的,1,3,5,7,,,
标签:pre name 文件 new code imp col list div
原文地址:https://www.cnblogs.com/cumtchw/p/12455854.html