我想使用我的代码绘制 Keras CNN 架构。绘制该模型的任何想法都很热门。
任何帮助将不胜感激。
提前致谢
代码:
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")
答案 0 :(得分:1)
据我所知,keras.utils 有一个名为 plot_model()
你试过这个吗?
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,
)