Skip to content Skip to sidebar Skip to footer

Where Does The Additional Dimension Of The Input In A Keras.model Come From?

When I define a model like: import tensorflow as tf from tensorflow.keras import layers import numpy as np input_shape = (20,20) input = tf.keras.Input(shape=input_shape) nn = la

Solution 1:

In Keras (TensorFlow), one cannot predict on a single input. Therefore, even if you have a single example, you need to add the batch_axis to it.

Practically, in this situation, you have a batch size of 1, hence the batch axis.

This is how TensorFlow and Keras are built, and even for a single prediction you need to add the batch axis (batch size of 1 == 1 single example).

You can use np.expand_dims(input,axis=0) or tf.expand_dims(input,axis=0) to transform your input into a suitable format for prediction.

Post a Comment for "Where Does The Additional Dimension Of The Input In A Keras.model Come From?"