Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

keras

Where can I find the API documentation of the class keras.layers.Input? I couldn't find it at https://keras.io/.

like image 788
L.Iridium Avatar asked May 03 '17 16:05

L.Iridium


People also ask

What information is included in the API endpoints section?

This includes most of the information needed to get started. The API Endpoints subsection includes navigation, a list of endpoints, the documentation of the currently selected endpoint, and a code snippet ( available in 8 different programming languages) to help you get started with your code.

How can I see what data and functionality an API has?

The two biggest recommendations we have for seeing what data and functionality an API has: 1 Contact the API Provider to ask them directly. API providers are the best resource of knowledge for their API, so you... 2 Test out the API yourself before subscribing to a paid plan. Many APIs will have a free BASIC plan associated with their... More ...

Why API documentation is important for web services?

With a lot of web services emerging, the need to have clear API documentation for adopting these services became clear. API documentation is the information that is required to successfully consume and integrate with an API. This can be in the form of technical writing, code samples and examples for better understanding how to consume an API.

What are APIs and where do you use them?

For communication between applications to take place, an API must have an Endpoint. An API Endpoint is the touchpoint of interactionwhen an API wants to access resources from a server. It is another word for URL, which is the path that allows an API to access data from a server. Now that we know what APIs are and their use, where do you find them.


2 Answers

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.
like image 116
Daniel Möller Avatar answered Oct 19 '22 17:10

Daniel Möller


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

like image 1
Ameet Deshpande Avatar answered Oct 19 '22 16:10

Ameet Deshpande