首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >拉扎涅神经网络层中的偏差

拉扎涅神经网络层中的偏差
EN

Stack Overflow用户
提问于 2015-08-02 15:05:37
回答 1查看 897关注 0票数 7

我想知道是否有一种方式来增加偏置节点到每一层的拉桑尼神经网络工具包?我一直试图在文件中找到相关的信息。

这是我建立的网络,但我不知道如何在每个层中添加一个偏置节点。

代码语言:javascript
复制
def build_mlp(input_var=None):
    # This creates an MLP of two hidden layers of 800 units each, followed by
    # a softmax output layer of 10 units. It applies 20% dropout to the input
    # data and 50% dropout to the hidden layers.

    # Input layer, specifying the expected input shape of the network
    # (unspecified batchsize, 1 channel, 28 rows and 28 columns) and
    # linking it to the given Theano variable `input_var`, if any:
    l_in = lasagne.layers.InputLayer(shape=(None, 60),
                                     input_var=input_var)

    # Apply 20% dropout to the input data:
    l_in_drop = lasagne.layers.DropoutLayer(l_in, p=0.2)

    # Add a fully-connected layer of 800 units, using the linear rectifier, and
    # initializing weights with Glorot's scheme (which is the default anyway):
    l_hid1 = lasagne.layers.DenseLayer(
            l_in_drop, num_units=800,
            nonlinearity=lasagne.nonlinearities.rectify,
            W=lasagne.init.Uniform())

    # We'll now add dropout of 50%:
    l_hid1_drop = lasagne.layers.DropoutLayer(l_hid1, p=0.5)

    # Another 800-unit layer:
    l_hid2 = lasagne.layers.DenseLayer(
            l_hid1_drop, num_units=800,
            nonlinearity=lasagne.nonlinearities.rectify)

    # 50% dropout again:
    l_hid2_drop = lasagne.layers.DropoutLayer(l_hid2, p=0.5)

    # Finally, we'll add the fully-connected output layer, of 10 softmax units:
    l_out = lasagne.layers.DenseLayer(
            l_hid2_drop, num_units=2,
            nonlinearity=lasagne.nonlinearities.softmax)

    # Each layer is linked to its incoming layer(s), so we only need to pass
    # the output layer to give access to a network in Lasagne:
    return l_out
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-08-02 16:57:33

实际上,您不必显式地创建偏差,因为DenseLayer()和卷积基层也有一个默认的关键字参数:

b=lasagne.init.Constant(0.)

因此,如果不希望具有显式传递bias,则可以避免创建bias=None,但情况并非如此。

因此,简单地说,您确实有偏差参数,而不将None传递给bias参数,例如:

代码语言:javascript
复制
hidden = Denselayer(...bias=None)
票数 9
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31773204

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档