在Jupyter Notebook中使用plot_model绘制张量流模型

问题描述 投票:0回答:2

尝试 plot_model 文档的示例

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 (

pip install pydot
) 并安装 graphviz(请参阅 https://graphviz.gitlab.io/download/ 中的说明)才能使plot_model 工作。

我安装了(在 jupyter 控制台中使用

pip install
)并验证(使用
pip show
)库的安装: 名称:pydot 版本:1.2.3 名称:graphviz 版本:0.20.1 名称: pydotplus 版本:2.0.2

我可以导入笔记本中的包,但仍然是相同的消息。

jupyter-notebook graphviz
2个回答
0
投票

常见问题,请注意您引用的消息说:

and install graphviz (see instructions at https://graphviz.gitlab.io/download/) for plot_model to work.

two 软件包需要安装(不幸的是 both 都被命名为 Graphviz)
如果您还没有,请转到指示的链接,下载并安装适当的版本。
另请参阅无法安装 pygraphviz:致命错误 C1083:无法打开包含文件:'graphviz/cgraph.h':没有这样的文件或目录


0
投票

你应该使用 conda 而不是 pip。

© www.soinside.com 2019 - 2024. All rights reserved.