# How to Visualise a CNN model using Python

I am new to Deep Learning and have been trying to show a plot of the CNN architecture using Python in Google Colab. Besides importing the necessary libraries, I have noticed from other resource that normally, we would declare a model {model = sequential()}, and then model.add (Conv2d or MaxPool or Activation etc.) and for visualising, print(model.summary()).

However, I have developed the CNN architecture using the below code and struggling with generating a model print. Could anybody tell what I am missing here. Thanks

input = Input(shape=X.shape[1:])                                  # 154x154x3
x = Conv2D(12, (3, 3), padding='same', activation='relu')(input)  # 154x154x12
x = Conv2D(12, (2, 2), strides=(2, 2), activation='relu')(x)      # 77x77x12
x = Conv2D(16, (3, 3), padding='same', activation='relu')(x)      # 77x77x16
x = Conv2D(16, (2, 2), strides=(2, 2), activation='relu')(x)      # 38x38x16
x = Conv2D(24, (3, 3), padding='same', activation='relu')(x)      # 38x38x24
x = Conv2D(24, (2, 2), strides=(2, 2), activation='relu')(x)      # 19x19x24
x = Conv2D(32, (3, 3), padding='same', activation='relu')(x)      # 19x19x32
x = Conv2D(32, (2, 2), strides=(2, 2), activation='relu')(x)      # 9x9x32
x = Conv2D(48, (3, 3), padding='same', activation='relu')(x)      # 9x9x48
x = Conv2D(48, (2, 2), strides=(2, 2), activation='relu')(x)      # 4x4x48
x = Dropout(0.5)(x)                                               # 4x4x48
x = Conv2D(n_classes, (1, 1))(x)                                  # 4x4x62
x = GlobalAvgPool2D()(x)                                          # 62
output = Activation('softmax')(x)                                 # 62

• Hi Emanuel and welcome to AI SE! I undeleted your post to let you know that this question is more appropriate for Stack Overflow. I was trying to migrate it to SO, but, for some reason, the post was just being closed and automatically downvoted. I will try again to migrate it to SO, if that's fine for you. Anyway, if you have any question about theoretical, philosophical and social aspects of AI, this is the best place to ask your question. Certain implementation-related questions are also on-topic here, but your question is more a general programming issue! Please, ask your question on SO. – nbro Mar 10 at 17:47
• Hi nbro, Thank you so much for attending to this question. I am an undergraduate student and did not realise that StackOverflow had blocked me from asking questions for six months. I have always respected the ethos and think 10 times before posting questions, but that's where I am. I though, AI would be the right place to ask these questions. Thank you so much for trying to paste it in stack overflow but I don't think, I can post any question there for at least another 4 months. Thank you so much again. Emanuel – Emanuel Mar 12 at 14:28

from keras.models import Model

• Small spelling error, it should be model.summary instead of model.summery. – Oxbowerce Mar 12 at 19:48