How to see the training samples my neural network mised in python tensorflow

Viewed 24

I just got started coding neural networks and my code si as follows

#create model
model = keras.Sequential([
    keras.layers.Flatten(input_shape=(28,28)),
    keras.layers.Dense(16, activation="relu"),
    keras.layers.Dense(16, activation="relu"),
    keras.layers.Dense(10, activation="softmax")
])
model.compile(optimizer="adam",
              loss="sparse_categorical_crossentropy",
              metrics=["accuracy"])

#train model
history = model.fit(x_train, y_train, epochs=5)

But how do I see what training samples my model got wrong. printing history gives me
<tensorflow.python.keras.callbacks.History object at 0x000000001CCAB2B0>

1 Answers

You can use model.predict to predict the labels on images. So for the training images you could do:

import numpy as np
y_probabilities = model.predict(x_train)
y_pred = np.array([np.argmax(probs) for probs in y_probs]

and then compare y_pred with y_train. For example

np.where(y_pred != y_train)[0]

will give you a numpy array with all the indices of the images that the model got wrong. Please refer to this Keras tutorial for more details.

Related