零碎代碼整理
移動圖片
- 需求:
Data_A:
? 123.jpg
? 123.png
把Data_A目錄分出來變成下面的形式:
Data_A:
? imgs:
? 123.jpg
? masks:
? 123.png
import os
import shutil
dir_root = '/share/home/dongli/Liang/Dataset/MSRAA/masks/'
dir_root_ = '/share/home/dongli/Liang/Dataset/MSRA_total/'
imgs_dir = os.path.join(dir_root_,'imgs')
masks_dir = os.path.join(dir_root_,'masks')
imgs_list = os.listdir(dir_root)
for i in range(len(imgs_list)):
img_path = os.path.join(dir_root,imgs_list[i])
if img_path.find('.jpg')!=-1:
tar_path = os.path.join(imgs_dir,imgs_list[i])
shutil.copy(img_path,tar_path)
elif img_path.find('.png')!=-1:
tar_path = os.path.join(masks_dir,imgs_list[i])
shutil.copy(img_path,tar_path)
print('finish!')
本文摘自 :https://www.cnblogs.com/