图像移动图像归类代码
提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档
图像移动图像归类代码
import os
import shutilvalue_dir = r'J:\IDM_data\cls_chinese_medicine\cls_chinese_medicine\train'train_dir = r'J:\IDM_data\cls_chinese_medicine\cls_chinese_medicine\all'import osfor root, dirs, files in os.walk(value_dir):# root: 当前目录路径# dirs: 当前目录下的子目录列表# files: 当前目录下的文件列表# 处理代码...count=0for file_ in files:# image_namelabel_name = file_old_path = os.path.join(root, file_)label_name = old_path.split('\\')[-2]new_path = os.path.join(train_dir, file_) # 要存放的目录地址shutil.move(old_path, new_path)count=count+1if count>2:breakprint("Done")