gpt4 book ai didi

tensorflow - 为什么 Keras 中的 plot_model 不能正确绘制模型?

转载 作者:行者123 更新时间:2023-12-03 16:21:41 34 4
gpt4 key购买 nike

我想可视化我的神经网络。因此,我使用 from tensorflow.keras.utils import plot_model并像这样使用它:

    model = Sequential()
model.add(Dense(8, activation="relu"))
model.add(Dense(1))
plot_model(model, to_file="model.png", show_shapes=True)

但是,当我打开图形时,它看起来像这样:

enter image description here

我的代码有什么问题?我没有看到任何错误。

最佳答案

原因是模型还没有建立,因为它不知道它的输入形状。使用 input_shape 在第一层指定模型的输入形状(或 input_dim) 参数,或者通过调用 fit 开始在某些数据上拟合模型方法(因此可以自动推断输入形状)。此外,正如@xdurch0 在评论部分所述,另一种选择是调用 build模型的方法并将输入形状作为参数传递给它。

关于tensorflow - 为什么 Keras 中的 plot_model 不能正确绘制模型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61227174/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com