读取/加载全部文件的路径的方法---glob

    imagedata = []
    imagefilenames=[]
    for basedir in ['./miniImagenet_46/']:
        print(basedir)
        alphabetdirs = glob.glob(basedir+'train')
        print(alphabetdirs)
        for alphabetdir in alphabetdirs:
            chardirs = glob.glob(alphabetdir+"/*")
            for chardir in chardirs:
                chardata = []
                charfiles = glob.glob(chardir+'/*')
                for fn in charfiles[:300]:
                    filedata = skimage.io.imread(fn) / 255.0 #plt.imread(fn)
                    chardata.append(filedata)
                imagedata.append(chardata)
                imagefilenames.append(fn)

glob.glob(basedir + "/*")即可加载basedir下的所有文件的路径,然后将文件按对应方法打开即可

你可能感兴趣的:(PYTHON)