Home > Software engineering >  How to get the CK Dataset into a dataframe where one column is the image and the second column is t
How to get the CK Dataset into a dataframe where one column is the image and the second column is t

Time:09-14

I want to build a model for emotion classification and tbh I am struggling with the dataset. I am using CK since I read it'd be on industry standard. I don't know how to format it the right way so I can start working. The Dataset is formatted in the following way.

Anger (Folder)

  • File 1
  • File 2
  • ...

Contempt (Folder)

  • File 3
  • File 4
  • ...

I need the foldernames as labels for the files inside of the folder but don't really know how to get there.

CodePudding user response:

You can load all your data in a tf.data.Dataset using the tf.keras.utils.image_dataset_from_directory function. Assuming that your Anger and Contempt folders are located in a directory named Parent you can do like this:

import tensorflow as tf
dataset = tf.keras.utils.image_dataset_from_directory('Parent')

You can then access the images and labels directly from the Dataset, for example like this:

iterator = dataset.as_numpy_iterator()
print(iterator.next()) 
  • Related