I am trying to classify pre-downloaded images from my dataset to "Rock" , "Paper" , "Scissor" classifications but I am getting outputs as numbers.

I have already divided the dataset to Train folder where 3 folders with the names of the categories exist.

Is it because I am not using a convolutional neural network?

I don't understand what to do here .


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(
    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(
    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_generator(validation_generator, steps = np.ceil(nb_samples/desired_batch_size))



[[2.2792105e-01 7.7206087e-01 1.8017196e-05]
 [2.8221733e-03 9.9715865e-01 1.9176909e-05]
 [5.1788869e-04 9.9948126e-01 8.8551565e-07]
 [9.9283433e-01 7.1645100e-03 1.1474091e-06]
 [9.9999678e-01 3.2666808e-06 4.5816462e-09]
 [9.9640071e-01 3.5960779e-03 3.1497514e-06]]

1 Answer 1


m.predict_generator returns a numpy array. you can take the maximum probability of a class by numypy argmax function or use predict_classes. This link might help-

How to predict class label from class probability given by predict_generator for testdata?


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.