英文:
ANN Visualizer ERROR: Layer not supported for visualizing
问题
我是相对新手,使用Python和Tensorflow/Keras进行机器学习。我现在已经运行了一个模型,并想要可视化我的网络。为此,有一个用于可视化人工神经网络(ANN)的Python库:ANN Visualizer。
不幸的是,我收到以下错误消息:
ValueError: ANN Visualizer: Layer not supported for visualizing
我建模型的方法如下:
def build_ann(self, nLayers=4, nNeurons=64, LR_init=1e-2, LR_adapt=1e-4, LR_steps=1e5, regularizer=1e-2, dropout=0.3):
model = Sequential()
for runs in range(nLayers):
return_seq = True if runs < nLayers-1 else False
model.add(LSTM(int(Neurons[runs]), return_sequences=return_seq))
model.add(Dropout(dropout))
model.add(Dense(int(Neurons[-1])))
model.add(Dense(len(self.targets), activation='sigmoid'))
model.compile(loss='mean_squared_error', optimizer='Adam', metrics=['accuracy'])
model.build(input_shape=(1, self.maxlen, len(self.features)))
model.summary()
return model
然后创建对象:
model = ann.build_ann(nLayers=2, nNeurons=2)
history = model.fit(trainx, trainy, batch_size=1, epochs=30, validation_data=(testsetx, testsety))
ann_viz(model)
为什么无法创建可视化?在其他示例中,是因为Flatten()层。我没有这样的层。是for循环吗?谢谢!
英文:
I am relatively new to machine learning with Python and Tensorflow/Keras.
I have now got a model running and would like to visualise my network.
For this there is a python library for visualizing Artificial Neural Networks (ANN): ANN Visualizer.
Unfortunately I receive this error message:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
C:\Temp\ipykernel_1787626106579.py in
24 history = model.fit(trainx, trainy, batch_size=1, epochs=30, validation_data=(testsetx, testsety))
25
---> 26 ann_viz(model)
c:\Users\aalles\Anaconda3\lib\site-packages\ann_visualizer\visualize.py in ann_viz(model, view, filename, title)
121 c.node(str(n), label="Image\n"+pxls[1]+" x"+pxls[2]+" pixels\n"+clrmap, fontcolor="white");
122 else:
--> 123 raise ValueError("ANN Visualizer: Layer not supported for visualizing");
124 for i in range(0, hidden_layers_nr):
125 with g.subgraph(name="cluster_"+str(i+1)) as c:
ValueError: ANN Visualizer: Layer not supported for visualizing
My method of building the model looks like this:
def build_ann(self, nLayers=4, nNeurons=64, LR_init=1e-2, LR_adapt=1e-4, LR_steps=1e5, regularizer=1e-2, dropout=0.3):
model = Sequential()
for runs in range(nLayers):
return_seq = True if runs < nLayers-1 else False
model.add(LSTM(int(Neurons[runs]), return_sequences=return_seq)) # , dropout=0.3
model.add(Dropout(dropout))
model.add(Dense(int(Neurons[-1])))
model.add(Dense(len(self.targets), activation='sigmoid'))
model.compile(loss='mean_squared_error', optimizer='Adam', metrics=['accuracy'])
model.build(input_shape=(1, self.maxlen, len(self.features)))
model.summary()
return model
Consequently, the object will be created:
model = ann.build_ann(nLayers=2, nNeurons=2)
history = model.fit(trainx, trainy, batch_size=1, epochs=30, validation_data=(testsetx, testsety))
ann_viz(model)
And the error appears.
Why can't a visualisation be created? In the other examples it was because of the Flatter() layer. I do not have such a layer. Is it the for loop?
Thank You very much!
答案1
得分: 0
以下是已翻译的内容:
错误的原因可能是 ann_visualizer
API 的更新。因此,您需要明确使用 graphviz
来访问 ann_visualizer 生成的文件(.gv
)以可视化模型。
from ann_visualizer.visualize import ann_viz
ann_viz(model, filename="iris.gv", title="Iris NN")
import graphviz
graph_file = graphviz.Source.from_file("iris.gv")
graph_file
请查看此复制的 gist 以供参考。
注意: 您还可以使用 TensorFlow 的 plot_model
API 通过以下代码来可视化模型:
from tensorflow.keras.utils import plot_model
plot_model(model, to_file="iris_model.png", show_shapes=True)
英文:
The reason behind this error could be the update in ann_visualizer
API. So you need to use graphviz
explicitly to access the ann_visualizer generated file(.gv
) for visualizing the model.
from ann_visualizer.visualize import ann_viz
ann_viz(model, filename="iris.gv", title="Iris NN")
import graphviz
graph_file = graphviz.Source.from_file("iris.gv")
graph_file
Please check this replicated gist for your reference.
Note: You can also use tensorflow's plot_model
api to visualize the model by using below code:
from tensorflow.keras.utils import plot_model
plot_model(model, to_file="iris_model.png", show_shapes=True)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论