我正在尝试使用 lasgne 来训练一个简单的神经网络,并使用我自己的 C++ 代码进行推理。我使用 lasgne 生成的权重,但无法获得好的结果。有没有办法打印隐藏层的输出和/或计算本身?我想看看它在幕后工作的是谁,这样我就可以在 C++ 中以相同的方式实现它。
最佳答案
我可以在 Python 中使用 Lasagne + Theano 提供帮助,根据你的问题我不确定你是否完全使用 C++ 工作,或者你只需要在你的 C++ 代码中使用 Python + Lasagne 的结果。
假设您有一个像这样的简单网络:
l_in = lasagne.layers.InputLayer(...)
l_in_drop = lasagne.layers.DropoutLayer(l_in, ...)
l_hid1 = lasagne.layers.DenseLayer(l_in_drop, ...)
l_out = lasagne.layers.DenseLayer(l_hid1, ...)
可以通过调用特定层的get_output
方法来获取每一层的输出:
lasagne.layers.get_output(l_in, deterministic=False) # this will just give you the input tensor
lasagne.layers.get_output(l_in_drop, deterministic=True)
lasagne.layers.get_output(l_hid1, deterministic=True)
lasagne.layers.get_output(l_out, deterministic=True)
当你处理 dropout 并且你不在训练阶段时,重要的是要记住调用 get_output
方法并将 deterministic
参数设置为 True,以避免非确定性行为。这适用于一个或多个 dropout 层之前的所有层。
我希望这能回答您的问题。
关于c++ - 如何在烤宽面条中打印隐藏层的输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45252752/