I have a Keras model saved in a .h5 file. As you know there are a y_pred and a y_act that confusion matrix creates from, at run time, it's easy to get y_pred values but my model is saved and now I need the y_pred values from that saved model. Is there a way to do that?


1 Answer 1


If I've figured it out correctly, the answer is no. The point is that your saved model solely contains the network architecture and the parameters it has. What you want relates to the recall phase where you have to provide input to get output. This means that you need input data to be fed to your network in order to get output. What you want can be done using another approach. First, load your network and feed your data to your model. After that, get the outputs and store the inputs and outputs alongside each other using Numpy save method or maybe .h5 format.

The flow for achieving the y_pred can be like the following sequence of actions:

  1. Load your model.
  2. Feed your data to your model and get y_pred.
  3. define a Numpy array of inputs and a Numpy array of outputs.
  4. Store inputs, real outputs and y_preds using the methods which are available.
  5. Later, when you want to make your confusion matrix, you can load your inputs and outputs, and the real outputs to make your matrix.
  • $\begingroup$ could give more explanation about you approach? I don't think this way gives me y_pred values? the y_pred is only consists of 0 and 1. $\endgroup$
    – Hunar
    Jul 11, 2019 at 7:46

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.