I used keras data augmentation to perform image classification (ten-class images). The last training epoch gives the results as follows:
Epoch 50/50
4544/4545 [============================>.] - ETA: 0s - loss: 0.7628 - acc: 0.7359 loss: 0.762710434054
New learning rate: 0.00214407973866
4545/4545 [==============================] - 115s - loss: 0.7627 - acc: 0.7360 - val_loss: 0.5563 - val_acc: 0.8124
Then evaluate the trained model by:
scores = model.evaluate_generator(test_generator,1514) #1514 testing images
print("Accuracy = ", scores[1])
It leads to the following results:
('Accuracy = ', 0.80713342132152621)
The accuracy is not exactly the same as that obtained in the last training epoch. I don't understand the difference, even though it is marginal.
Further, model.predict_generator gives totally different result that is an array shown as follows:
array([[ 4.98306963e-06, 1.83774697e-04, 5.49453034e-05, ...,
9.25193787e-01, 7.74697517e-04, 5.79946618e-06],
[ 2.06657965e-02, 2.35974863e-01, 2.66802781e-05, ...,
2.16283044e-03, 8.42395966e-05, 2.46680051e-04],
[ 1.40222355e-05, 1.22740224e-03, 7.52218883e-04, ...,
3.76749843e-01, 3.85622412e-01, 6.47417846e-06],
...,
[ 9.94064331e-01, 1.30184961e-03, 1.08694976e-05, ...,
1.25828717e-06, 2.29093766e-05, 9.01326363e-04],
[ 7.10375488e-01, 2.01397449e-01, 3.10241080e-06, ...,
3.66877168e-10, 1.66322934e-05, 1.93767438e-08],
[ 8.13350256e-04, 2.67575349e-04, 6.79878794e-05, ...,
8.63052785e-01, 9.70983761e-04, 8.54507030e-04]], dtype=float32)
I don't know what the matrix represents, and what is the difference between model.evaluate_generator and model.predict_generator.
It is noted that the resultant array has a shape of 1514*10. The array should be the prediction probabilities at each class for the set of testing images. If so how to compute a confusion matrix based on the result?
evaluate_generator. Evaluates the model on a data generator. The generator should return the same kind of data as accepted by test_on_batch . steps: Total number of steps (batches of samples) to yield from generator before stopping.
predict_generator returns a list of predictions which is a list of float values between 0 and 1.
Evaluation is a process during development of the model to check whether the model is best fit for the given problem and corresponding data. Keras model provides a function, evaluate which does the evaluation of the model.
predict_generator
takes your test data and gives you the output.
evaluate_generator
uses both your test input and output. It first predicts output using training input and then evaluates performance by comparing it against your test output. So it gives out a measure of performance, i.e. accuracy in your case.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With