Caffe中的权重绑定自编码器

13

据我所知,通常情况下自编码器在编码和解码网络中使用绑定权重对吧?

我查看了Caffe的自编码器示例,但我没有看到如何绑定权重。我注意到编码和解码网络共享相同的blob,但如何确保权重被正确更新?

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

1个回答

5
虽然自编码器中使用绑定权重的历史很长,但现在很少使用(据我所知),这也是为什么这个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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接