Search code examples
kerasdeep-learningkeras-layer

How to see keras.engine.sequential.Sequential


I am new to Keras and deep learning and was working with MNIST on Keras. When I created a model using

model = models.Sequential()
model.add(layers.Dense(512,activation = 'relu',input_shape=(28*28,)))
model.add(layers.Dense(32,activation ='relu'))
model.add(layers.Dense(10,activation='softmax'))

and then I printed it

print(model)

output is

<keras.engine.sequential.Sequential at 0x7f3d554f6710>

My question is that is there any way to see a better result of Keras, meaning if i print model i can see that i have 3 hidden layers with first hidden layer having 512 hidden units and 784 input units, 2nd hidden layer having 512 input units and 32 hidden units and so on.


Solution

  • model.summary() will print he entire model for you.

    model = Sequential()
    model.add(Dense(512,activation = 'relu',input_shape=(28*28,)))
    model.add(Dense(32,activation ='relu'))
    model.add(Dense(10,activation='softmax'))
    model.summary()
    
    Model: "sequential_1"
    _________________________________________________________________
    Layer (type)                 Output Shape              Param #   
    =================================================================
    dense (Dense)                (None, 512)               401920    
    _________________________________________________________________
    dense_1 (Dense)              (None, 32)                16416     
    _________________________________________________________________
    dense_2 (Dense)              (None, 10)                330       
    =================================================================
    Total params: 418,666
    Trainable params: 418,666
    Non-trainable params: 0
    ____________________________