input = tf.keras.Input(shape=(100,), dtype='int32', name='input')
x = tf.keras.layers.Embedding(
output_dim=512, input_dim=10000, input_length=100)(input)
x = tf.keras.layers.LSTM(32)(x)
x = tf.keras.layers.Dense(64, activation='relu')(x)
x = tf.keras.layers.Dense(64, activation='relu')(x)
x = tf.keras.layers.Dense(64, activation='relu')(x)
output = tf.keras.layers.Dense(1, activation='sigmoid', name='output')(x)
model = tf.keras.Model(inputs=[input], outputs=[output])
dot_img_file = '/tmp/model_1.png'
tf.keras.utils.plot_model(model, to_file=dot_img_file, show_shapes=True)
但它返回此消息
您必须安装 pydot (
) 并安装 graphviz(请参阅 https://graphviz.gitlab.io/download/ 中的说明)才能使plot_model 工作。pip install pydot
我安装了(在 jupyter 控制台中使用
pip install
)并验证(使用 pip show
)库的安装:
名称:pydot
版本:1.2.3
名称:graphviz
版本:0.20.1
名称: pydotplus
版本:2.0.2
我可以导入笔记本中的包,但仍然是相同的消息。
常见问题,请注意您引用的消息说:
and install graphviz (see instructions at https://graphviz.gitlab.io/download/) for plot_model to work.
你应该使用 conda 而不是 pip。