Explain Sequential model in Keras Architecture?

Sequential Model − Sequential model is basically a linear composition of Keras Layers. Sequential model is easy, minimal as well as has the ability to represent nearly all available neural networks.

A simple sequential model is as follows −

from keras.models import Sequential 
from keras.layers import Dense, Activation 

model = Sequential() 
model.add(Dense(512, activation = 'relu', input_shape = (784,)))

Where,

  • Line 1 imports Sequential model from Keras models
  • Line 2 imports Dense layer and Activation module
  • Line 4 create a new sequential model using Sequential API
  • Line 5 adds a dense layer (Dense API) with relu activation (using Activation module) function.

Layer

Each Keras layer in the Keras model represents the corresponding layer (input layer, hidden layer, and output layer) in the actual proposed neural network model. Keras provides a lot of pre-build layers so that any complex neural network can be easily created. Some of the important Keras layers are specified below,

  • Core Layers
  • Convolution Layers
  • Pooling Layers
  • Recurrent Layers

A simple python code to represent a neural network model using sequential model is as follows −

from keras.models import Sequential 
from keras.layers import Dense, Activation, Dropout model = Sequential() 

model.add(Dense(512, activation = 'relu', input_shape = (784,))) 
model.add(Dropout(0.2)) 
model.add(Dense(512, activation = 'relu')) 
model.add(Dropout(0.2)) 
model.add(Dense(num_classes, activation = 'softmax'))

Where,

  • Line 1 imports Sequential model from Keras models
  • Line 2 imports Dense layer and Activation module
  • Line 4 create a new sequential model using Sequential API
  • Line 5 adds a dense layer (Dense API) with relu activation (using Activation module) function.
  • Line 6 adds a dropout layer (Dropout API) to handle over-fitting.
  • Line 7 adds another dense layer (Dense API) with relu activation (using Activation module) function.
  • Line 8 adds another dropout layer (Dropout API) to handle over-fitting.
  • Line 9 adds final dense layer (Dense API) with softmax activation (using Activation module) function.