将数据集中的猫和狗分别放在train_0和train_1中:

39 阅读1分钟

import os import re import shutil

origin_path = '/workspace/src/how-to-read-paper/dataset/train' target_path_0 = '/workspace/src/how-to-read-paper/dataset/train_0/0' target_path_1 = '/workspace/src/how-to-read-paper/dataset/train_0/1'

os.makedirs(target_path_0, exist_ok=True) os.makedirs(target_path_1, exist_ok=True)

file_list = os.listdir(origin_path)

for i in range(len(file_list)): old_path = os.path.join(origin_path, file_list[i]) result = re.findall(r'\w+', file_list[i])[0] if result == 'cat': shutil.move(old_path, target_path_0) else: shutil.move(old_path, target_path_1) www.laipuhuo.com/goodsDetail… www.laipuhuo.com/goodsDetail… www.laipuhuo.com/goodsDetail… www.laipuhuo.com/goodsDetail… www.laipuhuo.com/goodsDetail… www.laipuhuo.com/goodsDetail… www.laipuhuo.com/goodsDetail… www.laipuhuo.com/goodsDetail…

www.laipuhuo.com/goodsDetail… www.laipuhuo.com/goodsDetail… www.laipuhuo.com/goodsDetail… www.laipuhuo.com/goodsDetail…