Felox
Felox

Reputation: 492

Issues with input dimension in a simple tensorflow model

I have issues with making prediction with a custom trained model.

It inputs 128 dimensions vector and output two values.

So far my model looks like this:

_________________________________________________________________
Layer (type)                 Output Shape              Param #
=================================================================
dense_12 (Dense)             (None, 128)               16512
_________________________________________________________________
dense_13 (Dense)             (None, 2)                 258
=================================================================
Total params: 16,770
Trainable params: 16,770
Non-trainable params: 0

Thus I try to input data to make a prediciton, (for the example purpose its only a np.ones array)

my_model = tf.keras.models.load_model('my_saved_model.h5')


probability_model = tf.keras.Sequential([my_model, tf.keras.layers.Softmax()])


simple_data = np.ones((128))

predictions = probability_model.predict(simple_data)
print(predictions)

And output an error about the shape of the simple_data being as (32, 1) :

ValueError: Input 0 of layer sequential is incompatible with the layer: expected axis -1 of input shape to have value 128 but received input with shape (32, 1)

I have no idea why.

Thanks in advance

Upvotes: 1

Views: 226

Answers (1)

Maybe you should try to add the batch dimension in your input data, something like this:

simple_data = np.ones((1, 128))

And I think you must add the arg batch_size=1 in the predict method.

Upvotes: 2

Related Questions