24

I have recently started working Tensorflow for deep learning. I found this statement model = tf.keras.models.Sequential() bit different. I couldn't understand what is actually meant and is there any other models as well for deep learning? I worked a lot on MatconvNet (Matlab library for convolutional neural network). never saw any sequential definition in that.

Prometheus
  • 1,148
  • 14
  • 21
Aadnan Farooq A
  • 626
  • 4
  • 8
  • 19

4 Answers4

30

There are two ways to build Keras models: sequential and functional.

The sequential API allows you to create models layer-by-layer for most problems. It is limited in that it does not allow you to create models that share layers or have multiple inputs or outputs.

Alternatively, the functional API allows you to create models that have a lot more flexibility as you can easily define models where layers connect to more than just the previous and next layers. In fact, you can connect layers to (literally) any other layer. As a result, creating complex networks such as siamese networks and residual networks become possible.

for more details visit : https://machinelearningmastery.com/keras-functional-api-deep-learning/

amkr
  • 639
  • 5
  • 8
15

From the definition of Keras documentation the Sequential model is a linear stack of layers.You can create a Sequential model by passing a list of layer instances to the constructor:

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

model = Sequential([
    Dense(32, input_shape=(784,)),
    Activation('relu'),
    Dense(10),
    Activation('softmax'),
])

You can also simply add layers via the .add() method:

model = Sequential()
model.add(Dense(32, input_dim=784))
model.add(Activation('relu'))

For More details click here

Hasee Amarathunga
  • 1,901
  • 12
  • 17
5

The Sequential model is a linear stack of layers.

The common architecture of ConvNets is a sequential architecture. However, some architectures are not linear stacks. For example, siamese networks are two parallel neural networks with some shared layers. More examples here.

Mehdi
  • 4,202
  • 5
  • 20
  • 36
3

As others have already mentioned that "The Sequential model is a linear stack of layers."

The Sequential model API is a way of creating deep learning models where an instance of the Sequential class is created and model layers are created and added to it.

The most common method to add layers is Piecewise

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

#initialising the classifier
#defining sequential i.e sequense of layers


classifier = Sequential()

# Adding the input layer and the first hidden layer
classifier.add(Dense(units = 6,activation = 'relu'))
#units = 6 as no. of column in X_train = 11 and y_train =1 --> 11+1/2

#Adding the second hidden lyer
classifier.add(Dense(units = 6, activation='relu'))

#adding the output layer
classifier.add(Dense(units = 1, activation = 'sigmoid))