我已经将可视化应用于 DNN 模型,但图像只包含一个密集层,没有输入和输出层的值!下面的代码解释了可视化过程没有任何错误,我试图在图像中显示输入和输出层的值。
import pandas as pd
.
.
tf.keras.utils.plot_model
.
.
def create_model():
model = Sequential()
model.add(Input(n_features))
model.add(BatchNormalization())
model.add(Dense(51, activation='relu'))
model.add(Dropout(0.5))
model.add(Dense(68, activation='relu'))
model.add(Dropout(0.5))
model.add(Dense(85, activation='relu'))
model.add(Dropout(0.5))
model.add(Dense(85, activation='relu'))
model.add(Dropout(0.5))
model.add(Dense(68, activation='relu'))
model.add(Dropout(0.5))
model.add(Dense(51, activation='relu'))
model.add(Dropout(0.5))
model.add(Dense(n_outputs, activation='sigmoid'))
model.compile(loss='binary_crossentropy',
optimizer='Adam',
metrics=['accuracy'])
tf.keras.utils.plot_model(model, to_file='model_combined.png')
#model.summary()
return model
#I have tried to use
#from keras.utils.vis_utils import plot_model
# but i found this error : TypeError: 'InputLayer' object is not iterable
# so i use the above library to implement visualization without any error.
请注意,我已经下载了所有这些库:Graphviz、pydot、pydotplus、python-graphviz