1
$\begingroup$

I tried building a keras model to classify leaves from the leaf classification dataset on kaggle. After i compiled and trained the model, i used it to predict the name of the leaves in the testing images, but all i got is an array of integers. How can i exactly interpret those numbers in order to get the names of the leaves.

model = Sequential()

model.add(Dense(128, kernel_initializer="uniform", input_dim= 192, activation='relu'))
model.add(Dropout(0.25))
model.add(Dense(99, activation='softmax'))

model.compile(loss='categorical_crossentropy',
              optimizer='adam',
              metrics=['accuracy'])
model_history = model.fit(x=X_train,y=Y_train, epochs=500, batch_size= 32, validation_data=(X_val, Y_val), verbose=1)

predictions = model.predict(test_arr, batch_size=32, verbose=1)
computed_predictions = np.argmax(predictions, axis=1)
computed_predictions
array([51, 50,  1, 19, 14,  3,  3, 28, 84,  8, 43, 74, 75, 10, 52, 46, 45,
       73, 13, 71, 61, 68, 57, 77,  1, 70, 28, 15, 35, 70, 53, 74, 47, 50,
        4, 36, 14, 69, 36, 93,  8, 32,  8,  9, 71, 70, 38, 23, 26, 18, 17,
        5, 55, 94, 14, 86, 62, 33, 51, 54, 88, 56, 21, 59, 65, 11, 48,  5,
       13,  4, 54, 57, 29,  7, 31, 98, 92, 84, 25, 10, 61, 43, 85, 24,  1,
        2, 23, 83, 40, 22, 48, 90, 25, 21, 37, 56, 41, 95,  7, 49, 98, 77,
        3, 12, 31, 84, 53, 96, 64, 72, 93, 93, 67, 30,  8, 88, 60, 87,  6,
       57, 34, 34, 60, 17, 75, 27, 51, 73, 39, 23, 38,  2, 41, 61, 24, 97,
       29, 28, 68, 81, 42, 51, 86, 62, 60, 52, 95, 81, 42, 96, 95, 20, 59,
       35, 86,  1, 26, 38, 43, 75, 20, 60, 46, 79, 22, 79, 69, 87, 65, 97,
       75, 21, 29, 21, 11, 10, 58, 94, 27, 22, 15, 45, 89, 54, 43,  5, 23,
       94, 40, 49, 89, 72, 36, 11, 81, 95, 18, 91, 29, 64, 80,  6, 78, 45,
       28,  9, 78, 90, 44, 89, 92, 13,  2, 59,  0, 96, 70, 32, 29, 78, 91,
       55, 44, 38,  5, 60, 49, 58, 93, 67, 92, 88, 90, 79, 25, 37, 18,  0,
       76, 27, 70, 71, 44, 70, 32, 90, 30, 82, 34, 30, 82, 96, 48, 65, 57,
       64, 26, 53, 69, 73,  9,  3, 83, 26, 30, 63, 17, 22, 36, 63, 12, 78,
       36, 14, 27, 25, 67, 38, 20, 54, 76, 69, 67, 97, 80, 44, 92, 69, 23,
       21, 11, 51, 33, 77, 16, 11, 97,  1, 52, 39, 24, 52, 42, 17,  2, 73,
       96, 83, 88,  9, 63, 50, 16, 37, 87, 95,  3, 35, 83, 60, 59, 58,  0,
       79, 62, 38, 93, 68, 69, 46, 19, 46, 94, 18,  0, 33, 89, 40, 62, 48,
       42,  6, 31, 91, 73, 81, 12, 85, 26,  6, 79,  2, 22, 35, 43,  6, 80,
       78, 82,  5, 61, 37, 43, 33, 69, 56, 71, 45, 59, 42, 66, 86, 98, 83,
       90, 64, 82, 11, 79, 56, 56, 49, 48, 20, 74, 15, 33, 49, 89, 44,  7,
       35, 14, 55, 23, 34, 44, 32, 30, 36,  9, 72, 31, 61, 50, 82, 34, 28,
       22, 92, 72, 11, 19,  4, 87, 51, 80, 39, 84, 32, 66, 36, 41, 31, 80,
        4, 26, 68, 96, 20, 36, 34, 39, 56, 73, 76, 84,  7, 67, 37,  8, 95,
       85, 62, 10, 65, 41,  2, 83, 86, 41, 52,  3, 49, 47, 76, 52, 11, 26,
       88, 71, 45, 39, 66, 87, 75, 74,  7, 64, 65, 78, 63, 56, 21, 61, 88,
       62, 91, 59, 12, 74, 15, 85,  8, 66, 57, 83, 82, 72, 58, 96,  7, 67,
       66, 57, 66, 92, 35, 18,  9, 54, 91, 65, 19, 15, 10, 24, 71, 69, 48,
       39, 98, 16, 19, 45, 74,  6, 69, 42, 34, 71, 47, 85, 28, 85, 47, 25,
       27, 58, 68, 84, 97, 63, 97, 76, 81, 87, 77, 14,  0, 28, 41, 14, 12,
       33, 86, 46,  4,  4, 47, 30, 19, 58, 13, 77, 98,  5, 49, 72, 53, 32,
       77, 40, 68, 26, 92, 16, 81, 37, 14, 93, 80, 53, 46, 25, 50, 17, 37,
       93,  0, 20, 54, 10, 91, 40, 81, 53, 18, 27,  1, 12, 54, 73, 15],
      dtype=int64) 
$\endgroup$
  • $\begingroup$ Please add sections of code that output this section. This will greatly help people to understand context of your problem and provide better solution $\endgroup$ – Yohanes Alfredo Dec 26 '19 at 1:15
0
$\begingroup$

Simple do backwards transformation of y_pred.

You label-encoded Y_train (i.e. every number 1-99 essentially represents a leaf) you you need to do is find mapping from leaf number and leaf name (thats in LabelEncoder) you would proceede something like this

le=LabelEncoder()
bla bal
Y_train=le.fit_transform()
predictions_test = le.inverse_transform(prediction_test)
| improve this answer | |
$\endgroup$
0
$\begingroup$

you have 99 leaf species and 594 test records. Also the output is (594,). Here each value represents corresponding leaf species columns index. check the species data you would have received after One-HotEncoder/get_dummies. each value of "computed_predictions" corresponds to their respective column number. you can export species column_name to a list(of 99 labels) and get the labels using list index(i.e. computed_predictions respective value)

| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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