[英]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.