简体   繁体   English

Keras:使用文件名而不是目录的flow_from_directory()或flow()

[英]Keras: flow_from_directory() or flow() using filenames instead of directories

I'm importing images to Keras from a directory. 我正在从目录将图像导入Keras。 The code looks something like this: 代码看起来像这样:

gen = datagen.flow_from_directory (
    DIRECTORY,
    target_size = (IMAGE_WIDTH, IMAGE_HEIGHT),
    batch_size = BATCH_SIZE,
    class_mode = "binary"
)

However, my data is organized not by folders, but by filenames. 但是,我的数据不是按文件夹组织的,而是按文件名组织的。 If I couldn't change this structure, is there any way to flow while separating by a regex (say, ending with ".jpg" vs. ".png", or starting with "numeral_7" vs "numeral_8")? 如果我无法更改此结构,是否可以通过正则表达式分隔(例如,以“ .jpg”和“ .png”结尾,或以“ numeral_7”和“ numeral_8”开头)?

According to the official documentation , you can add argument "classes". 根据官方文档 ,您可以添加参数“类”。 Which is an optional list of class subdirectories (eg ['dogs', 'cats']). 这是类子目录的可选列表(例如['dogs','cats'])。 Default: None. 默认值:无。

If not provided, the list of classes will be automatically inferred from the subdirectory names/structure under directory, where each subdirectory will be treated as a different class (and the order of the classes, which will map to the label indices, will be alphanumeric). 如果未提供,则会从目录下的子目录名称/结构自动推断出类列表,其中每个子目录将被视为一个不同的类(并且映射到标签索引的类顺序将为字母数字)。 The dictionary containing the mapping from class names to class indices can be obtained via the attribute class_indices. 包含从类名到类索引的映射的字典可以通过属性class_indices获得。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM