提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档
图像移动图像归类代码
import os
import shutil
value_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 os
for root, dirs, files in os.walk(value_dir):
# root: 当前目录路径
# dirs: 当前目录下的子目录列表
# files: 当前目录下的文件列表
# 处理代码...
count=0
for file_ in files:
# image_name
label_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+1
if count>2:
break
print("Done")