Introduction
We tell the model the shape of the data it will see so it can learn correctly.
Jump into concepts and practice - no test required
tf.keras.layers.Input(shape=(dim1, dim2, ...))
input_layer = tf.keras.layers.Input(shape=(28, 28, 1))
input_layer = tf.keras.layers.Input(shape=(100,))input_layer = tf.keras.layers.Input(shape=(None, 64))
import tensorflow as tf # Define input shape for 28x28 grayscale images input_layer = tf.keras.layers.Input(shape=(28, 28, 1)) # Add a flatten layer to convert 2D image to 1D vector flatten = tf.keras.layers.Flatten()(input_layer) # Add a dense layer with 10 outputs (for example, 10 classes) dense = tf.keras.layers.Dense(10, activation='softmax')(flatten) # Create the model model = tf.keras.Model(inputs=input_layer, outputs=dense) # Compile the model model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy']) # Print model summary to show input shape model.summary()
input_shape parameter specify in a TensorFlow Keras model?input_shape tells the model what size and type of data it will receive as input.model = tf.keras.Sequential([ tf.keras.layers.Input(shape=(32, 32, 3)), tf.keras.layers.Conv2D(16, 3) ])
input_layer = tf.keras.layers.Input(shape=28, 28, 1)