6

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.

Toke Faurby
  • 5,788
  • 9
  • 41
  • 62
  • 1
    I have never user an InputLayer. I always use `Input()` to generate the input tensor. I've also never seen an example using `InputLayer`. – Daniel Möller Jun 12 '17 at 13:18
  • I'm not sure who's right about it (if `InputLayer` should be used or not), but I'm sure it's part of TF's own version hell. It is compounded with problems coming from mixing `tf.keras` with `keras.*` (using Tensorflow backend). – Tomasz Gandor Dec 02 '19 at 11:38

2 Answers2

2

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.

Michele Tonutti
  • 4,298
  • 1
  • 21
  • 22
  • 2
    Where did you read that `InputLayer` is deprecated? TensorFlow 2 still supports it: https://www.tensorflow.org/api_docs/python/tf/keras/layers/InputLayer. – nbro Oct 21 '19 at 16:44
  • You are right, I can't find any reference to it. I honestly don't remember where I got that from. And this is why one should always provide sources to such statements...Anyways, these two threads seem to provide a good explanation https://stackoverflow.com/questions/46147019/keras-difference-of-inputlayer-and-input and https://stackoverflow.com/questions/45217973/what-is-the-advantage-of-using-an-inputlayer-or-an-input-in-a-keras-model-with – Michele Tonutti Oct 23 '19 at 08:07
0

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)
Usman Ahmad
  • 376
  • 4
  • 13