简体   繁体   English

Keras:绘制 model 时出现断言错误

[英]Keras: Assertion Error when plotting model

I want to plot my Keras model using the function below.我想 plot 我的 Keras model 使用下面的 ZC1C425268E68385D1AB5074C17AF4。 Every time I try to do that, it gives me the following AssertionError.每次我尝试这样做时,它都会给我以下 AssertionError。 Can someone help?有人可以帮忙吗?

---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
<ipython-input-37-4e7b8789844d> in <module>
      9 
     10 model,_ = create_model()
---> 11 plot_keras_model(model, show_shapes=True, show_layer_names=False)

<ipython-input-37-4e7b8789844d> in plot_keras_model(model, show_shapes, show_layer_names)
      6 from keras.utils.vis_utils import model_to_dot
      7 def plot_keras_model(model, show_shapes=True, show_layer_names=True):
----> 8     return SVG(model_to_dot(model, show_shapes=show_shapes, show_layer_names=show_layer_names, expand_nested=True).create(prog='dot',format='svg'))
      9 
     10 model,_ = create_model()

/opt/conda/lib/python3.6/site-packages/keras/utils/vis_utils.py in model_to_dot(model, show_shapes, show_layer_names, rankdir, expand_nested, dpi, subgraph)
    180                             if not is_model(layer) and (
    181                                     not is_wrapped_model(layer)):
--> 182                                 assert dot.get_node(inbound_layer_id)
    183                                 assert dot.get_node(layer_id)
    184                                 dot.add_edge(pydot.Edge(inbound_layer_id,

AssertionError: 

import pydotplus as pydot
from IPython.display import SVG
from keras.utils.vis_utils import model_to_dot
def plot_keras_model(model, show_shapes=True, show_layer_names=True):
    return SVG(model_to_dot(model, show_shapes=show_shapes, show_layer_names=show_layer_names).create(prog='dot',format='svg'))

model,_ = create_model()
plot_keras_model(model, show_shapes=True, show_layer_names=False)

I just want to point out that I was having same assertion error ----> dot.get_node(inbound_layer_id) while trying keras.utils.plot_model(model, etc)我只想指出我在尝试keras.utils.plot_model(model, etc)时遇到了相同的断言错误----> dot.get_node(inbound_layer_id) )

The issue got solved when I changed my imports:当我改变我的进口时,这个问题得到了解决:

from keras.models import Sequential
from keras.layers import Dense

To:至:

from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense

I also had to change tensorflow.keras.utils import to_categorical because of the fully integration of Keras into Tensorflow.我还不得不更改tensorflow.keras.utils import to_categorical因为 Keras 完全集成到 ZCB20B802A3F0255EED0 As seen here: Error in "from keras.utils import to_categorical"如此处所示: “从 keras.utils 导入 to_categorical”中的错误

We cannot exactly tell without knowing how you built your model.如果不知道您是如何构建 model 的,我们无法准确判断。 But if I had to guess then you're probably mixing tf.keras.layers with keras.layers in your Keras model.但是,如果我不得不猜测,那么您可能正在将 tf.keras.layers 与 keras.layers 混合在您的 Keras Z290F35E68FDAF43 中。 This is one of the reasons this type of error is thrown.这是引发此类错误的原因之一。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 theano 后端加载 keras model 时出现断言错误 - Assertion error when loading keras model with theano backend Keras 拟合 Model 时出现断言错误 - Keras Assertion Error while Fitting Model 使用Keras编译LSTM时出现断言错误 - Assertion Error when compiling LSTM with Keras 在连接嵌入式层后,在 Keras 中安装 model 时出现断言错误 - I got Assertion Error when fitting a model in Keras after concatenating Embedded layers 绘制 keras 自定义模型时,“ListWrapper”对象没有属性“name” - 'ListWrapper' object has no attribute 'name' when plotting keras custom model KeyError:绘制 Keras 模型训练进度时出现“mae” - KeyError: 'mae' when plotting Keras model training progress Keras:解开模型进行绘图/汇总 - Keras: Unravel model for plotting / summary Keras神经网络断言错误 - Keras neural net assertion error keras model with tf.contrib.losses.metric_learning.triplet_semihard_loss断言错误 - keras model with tf.contrib.losses.metric_learning.triplet_semihard_loss Assertion error 当尝试将 model 装入 Keras 时,如何修复失败的断言“输出通道应按组整除”? - How to fix failed assertion `output channels should be divisible by group' when trying to fit the model in Keras?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM