#本段代码为k折交叉验证提供了数据集上的准备
#以读入测试集为例,故只列出了测试集图片所在路径,若读入全部数据需把所有路径加
import glob
import os
import numpy as np
PATHS= ['.\\shallow\health_shallow',".\\shallow\\test_001health_shallow",
'.\\shallow\\hypertension_shallow',".\\shallow\\test_002hypertension_shallow"]
sum=0
img_path=[]
#遍历上面的4个路径,依次把信息追加到img_path列表中
for label,p in enumerate(PATHS):
image_dir=glob.glob(p+"\\"+"*.png")#返回路径下的所有图片详细的路径
sum+=len(image_dir)
print(len(image_dir))
for image in image_dir:
img_path.append((image,str(label//2)))
#print(img_path[0])
print("%d 个图像信息已经加载到txt文本!!!"%(sum))
np.random.shuffle(img_path)
print(img_path[0])
file=open(".\\shallow\\all_shuffle_datas.txt","w",encoding="utf-8")
for img in img_path:
file.write(img[0]+' '+img[1]+'\n')
file.close()