简体   繁体   中英

How to draw keras CNN architecture?

I want to draw Keras CNN architecture using my code. Any idea hot to draw that model.

Any help would be appreciated.

Thanks in advance

code:

import keras
from keras.models import Sequential
from keras.layers import Model, Conv2D, MaxPooling2D, Flatten, Dense,BatchNormalization,Dropout
from pptx_util import save_model_to_pptx
from matplotlib_util import save_model_to_file
input_shape=(33,3840,1)
model=sequential()
#c1
model.add(Conv2D(16,(5,5),strides=(2,2),padding='same',activation='relu',input_shape=input_shape))
model.add(keras.layer.MaxPooling2D(pool_size=(2,2),padding='same'))
model.add(BatchNormalization)
#c2
model.add(Conv2D(32,(3,3),strides=(1,1),padding='same',activation='relu'))
model.add(keras.layer.MaxPooling2D(pool_size=(2,2),padding='same'))
model.add(BatchNormalization)
model.add(Dense(32,input_dim=32,kernel_regularizer=regularizer.l2(0.1)))
model.add(keras.layer.Dropout(0.6))
model.add(Flatten())
model.add(Dropout(0.6))
model.add(Dense(256,activation='sigmoid'))
model.add(Dropout(0.6))
model.add(Dense(2,activation='softmax'))
# save as svg file
model.save_fig("example.svg")
# save as pptx file
save_model_to_pptx(model, "example.pptx")
# save via matplotlib
save_model_to_file(model, "example.pdf")

As far I know, keras.utils has a built-in method named plot_model()

Have you tried this one?

tf.keras.utils.plot_model(
    model,
    to_file="model.png",
    show_shapes=False,
    show_dtype=False,
    show_layer_names=True,
    rankdir="TB",
    expand_nested=False,
    dpi=96,
)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM