I'm using a pre-trained ResNet50 model in keras and am trying to see predictions for single samples
The issue is that model.predict()
is returning different values, depending on when I input a single sample vs the same sample within a larger array.
My model outputs a 1x6 vector of probabilities
I run on a single sample:
Case A: model.predict(X_test[0:1])
and within an array of multiple samples:
Case B: model.predict(X_test[0:2])
The prediction for X_test[0]
is
Case A: [9.999e-01, 4.228e-06, 8.278e-05, 1.121e-06, 1.061e-06, 2.958e-05]
Case B: [1.000e+00, 7.702e-13, 2.969e-13, 6.343e-11, 7.477e-14, 1.304e-10]
Why are the predictions different? (predictions here being the probabilities themselves, not argmax
)
As requested, the main code is below:
from keras.models import load_model
from my_utils import load_dataset
import numpy as np
X_train, Y_train, X_test, Y_test, classes = load_dataset()
model = load_model('model.h5') # ResNet50 with pre-trained weights
model.predict(X_test[0:1]) # Case A
model.predict(X_test[0:2]) # Case B
The model architecture of ResNet50 can be found here; the one difference with the implementation I'm using is that I'm using 6 classes not 1000
Thanks!
model.summary()
here. $\endgroup$model.summary()
is similar to what is in the link but can add if still helpful $\endgroup$