【问题标题】:Why are the parameters of my encoder and decoder not symmetric in my autoencoder?为什么我的编码器和解码器的参数在我的自动编码器中不对称?
【发布时间】:2019-04-03 09:28:04
【问题描述】:

我正在尝试使用 Keras API 在 Tensorflow 中实现自动编码器。我的代码灵感来自 Keras 网站上的示例:https://blog.keras.io/building-autoencoders-in-keras.html

目标是能够通过测量重构误差来检测数据集中的异常值。我的代码如下所示(我删除了一些层以使其更适合):

inputD = tf.keras.Input(shape=(1602,))
encoded = tf.keras.layers.Dense(1024, activation=tf.nn.leaky_relu, kernel_initializer='glorot_normal' )(inputD)
encoded = tf.keras.layers.Dense(8, activation=tf.nn.leaky_relu, kernel_initializer='glorot_normal')(encoded)
encoded = tf.keras.layers.Dense(4, activation=tf.nn.leaky_relu, kernel_initializer='glorot_normal')(encoded)
encoded = tf.keras.layers.Dense(3, activation=tf.nn.leaky_relu, kernel_initializer='glorot_normal')(encoded)

decoded = tf.keras.layers.Dense(4, activation=tf.nn.leaky_relu, kernel_initializer='glorot_normal')(encoded)
decoded = tf.keras.layers.Dense(8, activation=tf.nn.leaky_relu, kernel_initializer='glorot_normal')(decoded)
decoded = tf.keras.layers.Dense(1024, activation=tf.nn.leaky_relu, kernel_initializer='glorot_normal')(decoded)
decoded = tf.keras.layers.Dense(1602, activation='sigmoid', kernel_initializer='glorot_normal')(decoded)


autoencoder = tf.keras.Model(inputD, decoded)
adam = tf.keras.optimizers.Adam(lr=0.0001)
autoencoder.compile(optimizer=adam, loss='binary_crossentropy',  metrics=['mse'])

autoencoder.summary()

这会产生以下模型摘要:

_________________________________________________________________
Layer (type)                 Output Shape              Param #   
=================================================================
input_3 (InputLayer)         (None, 1602)              0         
_________________________________________________________________
dense_12 (Dense)             (None, 1024)              1641472   
_________________________________________________________________
dense_13 (Dense)             (None, 8)                 8200      
_________________________________________________________________
dense_14 (Dense)             (None, 4)                 36        
_________________________________________________________________
dense_15 (Dense)             (None, 3)                 15        
_________________________________________________________________
dense_16 (Dense)             (None, 4)                 16        
_________________________________________________________________
dense_17 (Dense)             (None, 8)                 40        
_________________________________________________________________
dense_18 (Dense)             (None, 1024)              9216      
_________________________________________________________________
dense_19 (Dense)             (None, 1602)              1642050   
=================================================================
Total params: 3,301,045
Trainable params: 3,301,045
Non-trainable params: 0

我不明白为什么我的参数不是对称的,例如,我希望最后一层的权重矩阵的形状与输入层相同,但事实并非如此。这是正常的吗?

当我输入这个时,我认为这可能是因为隐藏层中的偏差。如果我设置use_bias=False 我会得到镜像参数,但我不确定最常用的是什么?编码器和解码器是否应该有镜像参数以获得更好的性能?

【问题讨论】:

    标签: python tensorflow keras autoencoder


    【解决方案1】:

    正如您已经认为这里的问题是偏见。如果你以 Dense 12 和 Dense 13 之间的权重为例,你有 1024*8 = 8192 正常权重 + 8 偏差(总共8200)。

    如果您取 Dense 17 和 18 之间的权重,您将拥有 8*1024 = 8192 正常权重 + 1024 偏差(总共 9216)。下一层神经元的数量总是与偏差一样多。

    希望能回答你的问题。

    【讨论】:

      猜你喜欢
      • 2020-01-31
      • 2020-02-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-22
      • 1970-01-01
      • 2019-02-15
      • 1970-01-01
      相关资源
      最近更新 更多