1

I am training a CNN model. I am using a dataframe which contains one column for the image path. The other columns(bbox, category,attributes) contains target labels stored as encoded list. The snippet of the dataframe is given here: The dataframe used for training

Now the keras.preprocessing.ImageDatagenerator.flow_from_dataframe method in keras asks for the argumentclass_mode. No class mode seem to work.

Can anyone guide me on what should be done to read target labels directly in form of vector?

Jerry
  • 366
  • 4
  • 22
Shrey Shah
  • 109
  • 5

1 Answers1

1

Sample Dataframe -

     images     labels                bbox
0  img1.jpg  [0, 0, 1]  [72, 79, 232, 273]
1  img2.jpg  [1, 0, 0]  [67, 59, 155, 161]
2  img3.jpg  [0, 1, 0]  [51, 62, 167, 182]
from tensorflow.keras.preprocessing import image

generator = image.ImageDataGenerator()
generator.flow_from_dataframe(dataframe=df, x_col="images", y_col="labels")

Outputs an iterator object which u can iterate over or pass to your model -

Found 3 validated image filenames belonging to 2 classes.
<keras_preprocessing.image.dataframe_iterator.DataFrameIterator at 0x13b379898>
Aditya Mishra
  • 1,687
  • 2
  • 15
  • 24
  • In this case, shouldn't the image belong to **3 different classes**? I want it to be divided into 3 classes (as per your sample dataframe). In my data the "category" column is the one hot representation of the category of fashion apparel in image. There are total 50 categories and hence the one hot labels are of shape [1,50] – Shrey Shah Jul 31 '20 at 16:38
  • How is it different than the sample dataframe I created? The solution would work even if it's just 3, 10 or 20 categories – Aditya Mishra Jul 31 '20 at 17:25
  • I want something like: ```Found XYZ validated image filenames belonging to 50 classes```. – Shrey Shah Jul 31 '20 at 17:46