相关疑难解决方法(0)

在密集的 Keras 层中绑定自动编码器权重

我试图在 Keras 中创建一个自定义的 Dense 层来绑定自动编码器中的权重。我已经尝试按照在卷积层中执行此操作的示例here,但似乎某些步骤不适用于 Dense 层(而且,代码来自两年多前)。

通过绑定权重,我希望解码层使用编码层的转置权重矩阵。本文(第 5 页)也采用了这种方法。以下是文章的相关引用:

在这里,我们选择编码和解码激活函数都为 sigmoid 函数,并且只考虑绑定权重的情况,其中 W ?= W T (其中 W T 是W的转置),就像大多数现有的深度学习方法一样。

在上面的引用中,W是编码层中的权重矩阵,W'(等于W的转置)是解码层中的权重矩阵。

我在密集层没有太大变化。我tied_to在构造函数中添加了一个参数,它允许您传递要绑定到的层。唯一的其他更改是对build函数的更改,其代码段如下:

def build(self, input_shape):
    assert len(input_shape) >= 2
    input_dim = input_shape[-1]

    if self.tied_to is not None:
        self.kernel = K.transpose(self.tied_to.kernel)
        self._non_trainable_weights.append(self.kernel)
    else:
        self.kernel = self.add_weight(shape=(input_dim, self.units),
                                      initializer=self.kernel_initializer,
                                      name='kernel',
                                      regularizer=self.kernel_regularizer,
                                      constraint=self.kernel_constraint)
    if self.use_bias:
        self.bias = self.add_weight(shape=(self.units,),
                                    initializer=self.bias_initializer,
                                    name='bias',
                                    regularizer=self.bias_regularizer,
                                    constraint=self.bias_constraint)
    else:
        self.bias = None …
Run Code Online (Sandbox Code Playgroud)

python autoencoder keras

5
推荐指数
2
解决办法
3036
查看次数

标签 统计

autoencoder ×1

keras ×1

python ×1