Reputation: 63
I have a code running where as data input I have two numpy array (X_train,y_true). I like the data augmentation of the ImageDataGenerator.
Can I use this for getting corresponding numpy arrays?
Here is some code:
train_data_dir="Path to directory containing for each class a directory of images"
from keras.preprocessing.image import ImageDataGenerator
datagen = ImageDataGenerator(rescale=1. / 255,
horizontal_flip=True,
rotation_range=360)
generator = datagen.flow_from_directory(
train_data_dir,
target_size=(img_width, img_height),
batch_size=22,
class_mode=None,
shuffle=True)
x=generator.next()
Now x a a np.array, containing images of both my classes. Can I find the corresponding array with labels somewhere?
Upvotes: 3
Views: 7968
Reputation: 86600
It's quite simple. A generator must output both x and y:
x, y = generator.next()
Another option depending on your python:
x, y = next(generator)
Your generator is not returning any Y, though, because you used class_mode=None
.
You should use one of these to make the generator produce labels:
Usually, for a multiclass purpose, you'd go with "categorical". For one class (yes/no), use a "binary".
Upvotes: 10