Javatpoint Logo
Javatpoint Logo

The Model class

Model class

It is very beneficial in alliancing the layers into an object that encompasses features like training and inference.


  • inputs: It can be defined as an input that is being fed to the model. It can either be an object of Input or a list of objects, i.e., keras.Input.
  • outputs: It refers to the model's output.
  • name: It can be a string that defines the model's name.

Following are the two ways by which the models can be instantiated:

I. In the first way, we will do with the help of "Functional API". We will start with the Input followed by connecting the layer calls for specifying the forward pass of the model and thus end by creating the model by utilizing the inputs as well as outputs.

II. In the second way we will do by subclassing the Model class. Here first we will define layers in _init_ followed by executing the forward pass of the model in the call.

While subclassing the Model, we can also have a training argument called Boolean (which is optional) in the call for specifying distinct behavior in inference as well as training:

After creating the model, we can config the model by incorporating losses and metrics by model.compile(). The model can be trained by using the and with the help of model.predict() the model can make the predictions.

summary method

It can be used to print out the network's summary in the form of a string.


  • line_length: It can be defined as an aggregate length of the printed lines. Also, it can be set to adapt for displaying the window sizes of distinct terminals.
  • positions: It refers to the log elements position in each and every line that can be either a Relative or Absolute. In case if it isn't provided, then is it set the default to [.33, .55, .67, 1.].
  • print_fn: It can be used as a print function that defaults to print and will be called on summary's each line. In order to capture the string summary, it can be set to the custom function.


  • ValueError: It may generate the value error if we call the summary() before building the model.

get_layer method

It helps in the retrieval of a layer either on the basis of its unique name or index. The index will take precedence in case if both the name as well as index are already provided, such that the indices rely on the bottom-up approach (horizontal traversal graph).


  • name: It can be defined as a string that represents the layer's name.
  • index: It refers to an integer that depicts the layer's index.


It outputs an instance of the layer.


  • ValueError: A value error is generated if the layer has an invalid name or an index.

Youtube For Videos Join Our Youtube Channel: Join Now


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Trending Technologies

B.Tech / MCA