deep-learning - caffe 中的 L2 正则化,从 lasagne 转换

标签 deep-learning caffe lasagne regularized

我有一个烤宽面条代码。我想使用 caffe 创建相同的网络。我可以转换网络。但我需要有关烤宽面条超参数的帮助。 lasagne 中的超参数如下所示:

lr = 1e-2
weight_decay = 1e-5

prediction = lasagne.layers.get_output(net['out'])
loss = T.mean(lasagne.objectives.squared_error(prediction, target_var))

weightsl2 = lasagne.regularization.regularize_network_params(net['out'], lasagne.regularization.l2)
loss += weight_decay * weightsl2

如何在 caffe 中执行 L2 正则化部分?我是否必须在每个卷积/内积层之后添加任何层以进行正则化?我的 solver.prototxt 中的相关部分如下:

base_lr: 0.01
lr_policy: "fixed"
weight_decay: 0.00001
regularization_type: "L2"
stepsize: 300
gamma: 0.1  
max_iter: 2000
momentum: 0.9

也张贴在http://datascience.stackexchange.com .等待答案。

最佳答案

看来你已经做对了。
weight_decay元参数与 'solver.prototxt' 中的 regularization_type: "L2" 相结合,告诉 caffe 使用 L2 正则化和 weight_decay = 1e-5.

您可能想要调整的另一件事是正则化对每个参数的影响程度。您可以通过

为网络中的每个参数 blob 设置此
param { decay_mult: 1 }

例如,一个带有偏差的“InnerProduct”层有两个参数:

layer {
  type: "InnerProduct"
  name: "fc1"
  # bottom and top here
  inner_product_param { 
    bias_term: true
    # ... other params
  }
  param { decay_mult: 1 } # for weights use regularization
  param { decay_mult: 0 } # do not regularize the bias
}

默认情况下,decay_mult 设置为 1,即网络的所有权重都被正则化为相同。您可以更改它以规范更多/更少特定的参数 blob。

关于deep-learning - caffe 中的 L2 正则化,从 lasagne 转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41585226/

相关文章:

python - 如何使用机器学习从扫描文档中提取指定片段

python - caffe 安装找不到 python 3.5,即使它已安装并在路径变量中标记

python - 在python中调整4维数组的图像大小

python - 将 Lasagne 模型转换为 Keras

machine-learning - 如何从train/val损失和精度曲线中选择最佳模型?

numpy - 由于 RAM 使用过多,Colab 中的 session 崩溃

deep-learning - 当图像大小不同时,如何格式化图像数据以进行训练/预测?

c++ - 将 OpenCV 灰度 Mat 转换为 Caffe blob

python - 带有 caffe 的 python 中的 VGG 人脸描述符

theano - 输入维度不匹配二元交叉熵 Lasagne 和 Theano