Reputation: 279
I'm trying to figure out how to determine the class from a one hot encoded vector that is returned from keras. The problem is I use the flow_from_directory with ImageDataGenerator to train my network, leading to keras automatically converting the folder structure into the class vector to my knowledge, how do I go about resolving this?
Here's how my training is laid out in code:
checkpoint = [ModelCheckpoint(
'model.checkpoint.hdf5',
period=1
)]
train_datagen = ImageDataGenerator(
rotation_range=30)
test_datagen = ImageDataGenerator(
rotation_range=30)
train_generator = train_datagen.flow_from_directory(
'/train/',
target_size=(x, y),
batch_size=batch_size,
class_mode='categorical')
test_generator = test_datagen.flow_from_directory(
'/test/',
target_size=(x, y),
batch_size=batch_size,
class_mode='categorical')
self.discriminator.fit_generator(
train_generator,
steps_per_epoch=10000,
epochs=epochs,
validation_data=test_generator,
validation_steps=10,
callbacks=checkpoint
)
My folder structure is like so:
root/
train/
cow/
0.jpg
1.jpg
pig/
0.jpg
1.jpg
test/
cow/
0.jpg
1.jpg
pig/
0.jpg
1.jpg
Upvotes: 0
Views: 40
Reputation: 6044
print(train_generator.class_indices)
{'cow': 0, 'pig': 1}
From the documentation, "The dictionary containing the mapping from class names to class indices can be obtained via the attribute class_indices."
https://keras.io/preprocessing/image/#flow_from_directory
Upvotes: 1
Reputation: 453
The prediction in keras refers to your own structure of the folder. if train is composed of cow and pig. Then cow = 0
and pig = 1
. So if the predict returns 0 is cow otherwise it's pig.
Upvotes: 1