在上一次分类的基础上将二分类扩展为九分类。
切割图片为2000*2000,space=2000,按类别放在patch文件夹中。
要将整个数据集划分为训练集和测试集。
下面是两种方法划分数据集:
方法1:将源文件夹和目标文件夹相互对应起来,根据图片在文件夹中的位置索引,来判断是放在训练集,还是测试集。
import os
import shutil
path="/home/cad429/code/yue/Week2/patch"
name_list=os.listdir(path)
print(name_list)
train_dir="/home/cad429/code/yue/Week2/train"
if not os.path.exists(train_dir):
os.makedirs(train_dir)
test_dir="/home/cad429/code/yue/Week2/test"
if not os.path.exists(test_dir):
os.makedirs(test_dir)
val_dir="/home/cad429/code/yue/Week2/val"
if not os.path.exists(val_dir):
os.makedirs(val_dir)
for i in range(len(name_list)):
patch_path=os.path.join(path,name_list[i])
print(patch_path)
patch_list=os.listdir(patch_path)
print(patch_list)
patch_name_list = [i.split('.')[0] for i in patch_list]
print(patch_name_list)
print(