keras读写文件

    科技2025-07-06  18

    读写文件,主要代码函数

    import os image_types = (".jpg",".jpeg",".png",".bmp",".tif",".tiff") def list_images(basePath,contains=None): #返回有效的文件集 retrun list_files(basePath,validExts = image_types,contains = contains) def list_files(basePath,validExts = None,contains = None): #遍历目录结构 for (rootDir,dirNames,filenames) in os.walk(basePath): #循环遍历当前目录中的文件名 for filename in filenames: #如果contains字符串不是none并且文件名不包含提供的字符串,然后忽略文件 if contains is not None and filename.find(contains) == -1:#查找文件名包含指定字符串的文件,不等于-1表明包含此字符串。若是=-1,则表明不包含字符串 continue #确定当前文件的文件扩展名 ext = filename[filename.rfind("."):].lower()#将文件后缀转换成小写 #检查文件是否为图像,是否应进行处理 if validExts is None or ext.endswith(validExts): #构造图像的路径并产生它 imagePath = os.path.join(rootDir,filename)#路径拼接文件路径 yield imagePath

    使用代码语句

    imagePaths = sorted(list(utils_paths.list_images(args["dataset"])))
    Processed: 0.009, SQL: 8