Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is meant by sequential model in Keras

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.

like image 514
Aadnan Farooq A Avatar asked Sep 02 '19 04:09

Aadnan Farooq A


2 Answers

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/

like image 149
amkr Avatar answered Oct 21 '22 12:10

amkr


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

like image 23
Hasee Amarathunga Avatar answered Oct 21 '22 14:10

Hasee Amarathunga