Where can I find the API documentation of the class Input?

That documentation is really hard to go through when you're not used to Keras.

But there are two approaches for building keras models:

  • The Sequential model
  • The Model functional API

The Input layer is not used with the Sequential model, only with Model.

Probably, there is no clear documentation because the Input layer does absolutely nothing except defining the shape of the input data to your model. (In fact it creates a "tensor" that you can use as input to other layers).

Imagine you are creating a model taking batches with MNIST data, which has 28x28 pixel images. Your input shape is then (28,28) (see *).

When creating your model, you use Input just to define that:

#inp will be a tensor with shape (?, 28, 28)
inp = Input((28,28))

The following layers will then use this input:

x = SomeKerasLayer(blablabla)(inp)     
x = SomeOtherLayer(blablabla)(x)    
output = TheLastLayer(balblabla)(x)

And when you create the model, you define the path that the data will follow, which in this case is from the input to the output:

model = Model(inp,output)

With the Model api, it's also possible to create ramifications, multiple inputs and multiple outputs, branches, etc.

In case of having multiple inputs, you'd create several Input layers.

See here for more advanced examples with actual layers: https://keras.io/getting-started/functional-api-guide/


* - This is not a rule. Depending on how you format your input data, this shape can change. There are models that prefer not to care about the 2D information and use a flattened image of shape (784,). Models that will use convolutional layers will often shape the input data as (28,28,1), an image with one channel. (Usually, images have 3 channels, RGB).


Arguments to the Input

The code for the Input method is defined here (December, 22 - 2017)

Possible arguments:

  • shape: defines the shape of a single sample, with variable batch size (as shown above)
  • batch_shape: explicitly define the size of the batch in the passed shape
  • tensor: instead of passing an input shape to the model, pass an existing tensor, you can for instance pass a tensor populated with values, such as a K.variable().
  • Other arguments: name, dtype and sparse.

Most of the things have been summarized by the above answer. But as mentioned in the comment, I think the tf.contrib.keras contains docs about keras. This link contains documentation for the same.

As mentioned in the accepted answer, Input can be used with model to denote the tensor. It, in fact, returns a tensor. The way I understand it is, it is somewhat similar to tf.placeholder as it allows us to define the model in terms of the Input object alone and fit the model later on. The following is the example from the tensorflow docs.

# this is a logistic regression in Keras
x = Input(shape=(32,))
y = Dense(16, activation='softmax')(x)
model = Model(x, y)

It can be seen here how the usage of Input is somewhat similar to that of tf.placeholder

Tags:

Keras