Caffe 中具有绑定权重的自动编码器

Auto-encoders with tied weights in Caffe

据我了解,自动编码器通常在编码和解码网络中使用绑定权重,对吧?

我看了一下Caffe's auto-encoder example,但我没看到权重是如何绑定的。我注意到编码和解码网络共享相同的 blob,但如何保证权重更新正确?

如何在 Caffe 中实现绑定权重自动编码器?

虽然在自动编码器中有使用绑定权重的历史,但现在很少使用(据我所知),我相信这就是为什么这个 Caffe 示例不使用绑定权重的原因。

尽管如此,Caffe 确实 支持具有绑定权重的自动编码器,并且可以使用两个功能:层与层之间的参数共享全连接层(Caffe 中的 InnerProduct)的转置标志。更具体地说,如果名称相同,则两个参数在 Caffe 中共享,可以在 param 字段下指定,如下所示:

layer {
  name: "encode1"
  type: "InnerProduct"
  bottom: "data"
  top: "encode1"
  param {
    name: "encode1_matrix"
    lr_mult: 1
    decay_mult: 1
  }
  param {
    name: "encode1_bias"
    lr_mult: 1
    decay_mult: 0
  }
  inner_product_param {
    num_output: 128
    weight_filler {
      type: "gaussian"
      std: 1
      sparse: 15
    }
    bias_filler {
      type: "constant"
      value: 0
    }
  }
}

如果另一个全连接层(具有匹配的维度)使用名称 "encode1_matrix" 和 "encode1_bias" 那么这些参数将始终相同,Caffe 将负责聚合梯度和更新参数正确。第二部分是使用全连接层的转置标志,以便共享矩阵在其输入相乘之前进行转置。所以,扩展上面的例子,如果我们想在解码过程中有一个具有与 "encode1_matrix" 相同权重矩阵的全连接层,那么我们将这样定义它:

layer {
  name: "decode1"
  type: "InnerProduct"
  bottom: "encode1"
  top: "decode1"
  param {
    name: "encode1_matrix"
    lr_mult: 1
    decay_mult: 1
  }
  param {
    name: "decode1_bias"
    lr_mult: 1
    decay_mult: 0
  }
  inner_product_param {
    num_output: 784
    transpose: true
    weight_filler {
      type: "gaussian"
      std: 1
      sparse: 15
    }
    bias_filler {
      type: "constant"
      value: 0
    }
  }
}

请注意,偏置参数不共享(不可能是由于不同的输出维度),而矩阵是共享的,解码器层使用转置标志完成绑定的自动编码器架构。

有关使用 Caffe 的绑定自动编码器的完整工作示例,请参见此处:https://gist.github.com/orsharir/beb479d9ad5d8e389800c47c9ec42840