简体   繁体   English

如何使用包含文件名和标签的数据帧将带有类标签的图像从单个目录加载到Keras模型中?

[英]How to load the images with class labels from a single directory into Keras model using a dataframe containing filenames and labels?

I have two separate folders "train_images" and "val_images". 我有两个单独的文件夹“ train_images”和“ val_images”。 I have all the images inside these two folders. 我在这两个文件夹中都有所有图像。 I am doing a categorical classification using DenseNet121 model. 我正在使用DenseNet121模型进行分类。 I have two different y_df (dataframe) for training and validation. 我有两个不同的y_df (数据y_df )用于训练和验证。 I know about flow_from_directory but for that I need to create different subforlders inside each "train_images" and "val_images" based on classes. 我知道flow_from_directory但是为此,我需要基于类在每个“ train_images”和“ val_images”内部创建不同的子锻造器。

I am willing to to know if I don't want to create those subforlders and don't use flow_from_directory , how do I pass those images into the model? 我想知道是否不想创建那些子锻造者并且不使用flow_from_directory ,如何将这些图像传递到模型中? I am using Keras with Tensorflow as the backend. 我正在使用Keras与Tensorflow作为后端。

If you have a dataframe that contains the image filenames along with their labels, you can use the newly introduced flow_from_dataframe() method which has been exactly defined for this purpose. 如果您有一个包含图像文件名及其标签的数据flow_from_dataframe() ,则可以使用为此目的专门定义的新引入的flow_from_dataframe()方法。 It takes a Pandas dataframe which contains the filenames of the images in one column and their corresponding labels in another column(s). 它采用一个Pandas数据框,该数据框在一个列中包含图像的文件名,在另一列中包含它们的相应标签。 It has not been officially released yet, so you need use the latest development version of Keras on the Keras Github repository . 它尚未正式发布,因此您需要在Keras Github存储库上使用Keras的最新开发版本。 It is expected to be in the next release, though. 不过,预计它将在下一个版本中。

Update: It has been included in Keras Preprocessing 1.0.4 and Keras 2.2.3 . 更新:它已包含在Keras预处理1.0.4Keras 2.2.3中

Also, there is a tutorial about this method as well. 另外,还有关于此方法的教程

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

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