I am trying to build a multi class image classifier but the only returns 0 or 1 .
Why is it not returning "Rock" , "Paper" , "Scissor" ? and why only 0 and 1 but not 2?
CODE:
from keras.preprocessing.image import ImageDataGenerator
from keras.models import Sequential
from keras.layers import Dense, Flatten
import numpy as np
train_directory = 'D:\D_data\Rock_Paper_Scissors\Train'
training_datgagen = ImageDataGenerator(rescale = 1./255)
training_generator = training_datgagen.flow_from_directory(
train_directory,
target_size = (28,28),
class_mode = 'categorical', classes = ["Rock", "Paper" , "Scissor"])
validation_directory = 'D:\D_data\Rock_Paper_Scissors\Train'
validation_datagen = ImageDataGenerator(rescale= 1./255)
validation_generator = validation_datagen.flow_from_directory(
validation_directory,
target_size = (28,28),
class_mode = 'categorical',
classes = ["Rock", "Paper" , "Scissor"]
)
model = Sequential()
model.add(Flatten(input_shape = (28,28,3)))
model.add(Dense(128,activation = 'relu'))
model.add(Dense(64, activation = 'relu'))
model.add(Dense(16, activation = 'relu'))
model.add(Dense(3, activation = 'softmax'))
model.compile(optimizer = 'adam', loss = 'categorical_crossentropy',metrics = ['accuracy'],)
filenames = validation_generator.filenames
nb_samples = len(filenames)
desired_batch_size = 1
model.fit_generator(training_generator,epochs=20,validation_data = validation_generator)
predict = model.predict_classes(validation_generator, batch_size = None)
print(predict)
Output:
[0 1 1 ... 1 0 1]