【问题标题】:removing bias from neural network layer从神经网络层去除偏差
【发布时间】:2016-02-21 08:03:19
【问题描述】:

我想删除偏差参数。我试图在我定义我的神经网络的地方包含thebias=None,但它不起作用。

net1 = NeuralNet(
layers=[ # three layers: one hidden layer
('input', layers.InputLayer),
#('hidden', layers.DenseLayer),
('output', layers.DenseLayer),
],
# layer parameters:
input_shape=(None,2), # 2 inputs
#hidden_num_units=200, # number of units in hidden layer
output_nonlinearity=None, # output layer uses identity function
output_num_units=1, # 1 target value

# optimization method:
update=nesterov_momentum,
update_learning_rate=0.01,
update_momentum=0.9,

regression=True,  # flag to indicate we're dealing with regression problem
max_epochs=400,  # we want to train this many epochs
verbose=1,
bias = None
) 

【问题讨论】:

    标签: python lasagne nolearn


    【解决方案1】:
    # Build the network yourself
    inputs = InputLayer(shape=(None, 2))
    network = DenseLayer(inputs, num_units=1, nonlinearity=None, b = None)
    
    net1 = NeuralNet(
    network,
    #We don't need any of these parameters since we provided them above
    # layer parameters:
    #input_shape=(None,2), # 2 inputs
    #hidden_num_units=200, # number of units in hidden layer
    #output_nonlinearity=None, # output layer uses identity function
    #output_num_units=1, # 1 target value
    
    # optimization method:
    update=nesterov_momentum,
    update_learning_rate=0.01,
    update_momentum=0.9,
    
    regression=True,  # flag to indicate we're dealing with regression problem
    max_epochs=400,  # we want to train this many epochs
    verbose=1,
    bias = None
    ) 
    

    我认为这应该可行。可能有一个 kwarg 可以在网络中传递(我不记得了),但我认为如果没有给出任何参数,默认情况下它是第一个参数。

    【讨论】:

    【解决方案2】:

    根据Lasagne Documentation for conv layers(密集层类似),您有以下偏差选项:

    b = None 
    

    至少根据 Lasagne 文档,似乎没有任何层的“偏差”参数,而是使用“b”。我不能代表 NoLearn,因为我不使用那个包。

    编辑:

    这是一些千层面示例代码:

    import lasagne
    net = {}
    net['input'] = lasagne.layers.InputLayer(shape=(None, 3, 224,224), input_var=None)
    net['conv'] = lasagne.layers.Conv2DLayer(net['input'], num_filters=5, filter_size=3, b = None)
    print net['conv'].get_params()
    

    返回:

    [W]
    

    单独,意味着没有偏见项。

    对于 NoLearn,我不确定,因为我不使用该软件包。

    【讨论】:

    • 当使用 'b=None' 时,我得到 'ValueError: Unused kwarg: b'
    • 我已经用一些示例千层面代码更新了我的答案。我不使用 NoLearn。我提供了千层面的答案,因为您在问题中包含了千层面标签。希望这对您仍然有用。
    猜你喜欢
    • 1970-01-01
    • 2015-10-24
    • 1970-01-01
    • 2016-09-08
    • 1970-01-01
    • 2017-12-06
    • 2018-03-14
    • 2010-12-02
    • 2018-03-01
    相关资源
    最近更新 更多