Home > Blockchain >  How to split dataset to images and labels using tensorflow
How to split dataset to images and labels using tensorflow

Time:01-28

I imported image dataset using tensorflow.keras.preprocessing.image_dataset_from_directory():

train = tf.keras.preprocessing.image_dataset_from_directory(
    'chest_xray/train/',
    labels = 'inferred',
    label_mode = 'categorical',
    class_names = ['NORMAL', 'PNEUMONIA'],
    color_mode = 'grayscale',
    batch_size = batch_size,
    image_size = (image_height, image_width),
    shuffle = True
    )

I tried to split the dataset into images and labels, however I was unable to do so. Is there a method to split train to train_images and train_labels?

CodePudding user response:

You will be creating two directories, i.e. in your case two folders with one named NORMAL and another named PNEUMONIA. Your directory structure should be something like this

main_directory/
...class_a/
......a_image_1.jpg
......a_image_2.jpg

...class_b/
......b_image_1.jpg
......b_image_2.jpg

Your main directory will be having a folder with class names and their respective images inside. So here you won't be splitting you will be directly sending off the data packed under its label itself. You can refer to the documentation here

If you are looking for the code to split training and testing data, Let me know.

  • Related