Faur
Faur

Reputation: 5968

Keras: What is the difference between layers.Input and layers.InputLayer?

When should I use Input and when should I use InputLayer? In the source code there is a description, but I am not sure what it means.

InputLayer:

Layer to be used as an entry point into a graph. It can either wrap an existing tensor (pass an input_tensor argument) or create its a placeholder tensor (pass arguments input_shape or batch_input_shape as well as dtype).

Input:

Input() is used to instantiate a Keras tensor. A Keras tensor is a tensor object from the underlying backend (Theano or TensorFlow), which we augment with certain attributes that allow us to build a Keras model just by knowing the inputs and outputs of the model.

Upvotes: 6

Views: 1838

Answers (2)

Usman Ahmad
Usman Ahmad

Reputation: 416

InputLayer is a callable, just like other keras layers, while Input is not callable, it is simply a Tensor object.

You can use InputLayer when you need to connect it like layers to the following layers:

inp = keras.layers.InputLayer(input_shape=(32,))(prev_layer)

and following is the usage of Input layer:

x = Input(shape=(32,))
y = Dense(16, activation='softmax')(x)
model = Model(x, y)

Upvotes: 0

Michele Tonutti
Michele Tonutti

Reputation: 4348

I think InputLayer has been deprecated together with the Graph models. I would suggest you use Input, as all the examples on the Keras documentations show.

Upvotes: 2

Related Questions