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