Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keras Image Data Generator show labels

I am using an ImageDataGenerator to augment my images. I need to get the y labels from the generator.

Example : I have 10 training images, 7 are label 0 and 3 are label 1. I want to increase training set size to 100.

total_training_images = 100 total_val_images = 50

model.fit_generator(
    train_generator,
    steps_per_epoch= total_training_images // batch_size,
    epochs=epochs,
    validation_data=validation_generator,
    validation_steps= total_val_images // batch_size)

By my understanding, this trains a model on 100 training images for each epoch, with each image being augmented in some way or the other according to my data generator, and then validates on 50 images.

If I do train_generator.classes, I get an output [0,0,0,0,0,0,0,1,1,1]. This corresponds to my 7 images of label 0 and 3 images of label 1.

For these new 100 images, how do I get the y-labels? Does this mean when I am augmenting this to 100 images, my new train_generator labels are the same thing, but repeated 10 times? Essentially np.append(train_generator.classes) 10 times?

I am following this tutorial, if that helps : https://blog.keras.io/building-powerful-image-classification-models-using-very-little-data.html

like image 445
Adit Sanghvi Avatar asked Dec 14 '22 21:12

Adit Sanghvi


1 Answers

The labels generate as one-hot-encoding with the images.Hope this helps !

training_set.class_indices

from keras.preprocessing import image
import matplotlib.pyplot as plt

x,y = train_generator.next()
for i in range(0,3):
    image = x[i]
    label = y[i]
    print (label)
    plt.imshow(image)
    plt.show()
like image 148
Dip Avatar answered Dec 29 '22 08:12

Dip