I'm trying test/predict my model, in tensorflow with keras.
For now, I'm using image from train dataset, I'll change once it's working
So I'm calling predict like this:
print(x[0].shape) # <- (128, 128, 3)
print(np.array(x[0])[0].shape) # <- (128, 3)
model.predict(np.array(x[0]))
But it gives me: layer model: expected shape=(None, 128, 128, 3), found shape=(32, 128, 3)
Should not it work? Why is the shape changing when creating array?
CodePudding user response:
You need to add an extra dimension for batch size. For single image batch size would be 1. You can use np.expand_dims to add the extra dimension.
np.expand_dims(np.array(x[0]), axis=0)
CodePudding user response:
model.predict always works in batches. Therefore you need to provide test data in batches, or in other words "provide data point in rows". If you just want to predict for one single data point, you have to either expand it like vivekpadia said or try this:
model.predict(x)