2个LSTM自动编码器之间的差异

时间:2018-04-28 19:03:25

标签: python keras autoencoder

我想知道这两个模型之间的区别。上面的一个有4个图层查看模型摘要,您还可以定义维数减少的单位数。但是第二个模型它有3层,你不能直接定义隐藏单位的数量? LSTM自动编码器是否用于降维和回归分析?是否有任何好的论文描述了我从kerashere找到的这两个例子。我没有确定变量,事实上我没有直接要求编码问题。我希望这也是这个话题的好地方。 1.型号:

from keras.layers import *
from keras.models import Model
from keras.layers import Input, LSTM, Dense, RepeatVector

samples=1000
timesteps=300
features=input_dim=1
data_shape=np.reshape(data,(samples,timestep,input_dim)

inputs = Input(shape=(timestep, input_dim))
encoded = LSTM(units, return_sequences=False, name="encoder")(inputs)
decoded = RepeatVector(timestep)(encoded)
decoded = LSTM(input_dim, return_sequences=True, name='decoder')(decoded)
autoencoder = Model(inputs, decoded)
encoder = Model(inputs, encoded)
print (autoencoder.summary())

2。型号:

x = np.random.random((1000, 300, 1))

2.model:

m = Sequential()
m.add(LSTM(100, input_shape=(300,1)))
m.add(RepeatVector(300))
m.add(LSTM(100, return_sequences=True))
print (m.summary())
m.compile(loss='mse', optimizer='rmsprop', metrics=['mse', 'mape'])
history = m.fit(x, x, nb_epoch=2000, batch_size=100)

当我尝试向他们两个添加具有例如形状的数据时(1000,300,1)第一个接受第二个不是,我得到错误预期lstm_4有形状(无,300,100)但得到形状的数组(1000,300,1)。选择input_dim 1和units = 100。我究竟做错了什么 ?这就是我想要的:

LSTM(100, input_shape=(300, 1))

单位= 100 当我运行模型时,我收到以下错误:检查目标时出错:预期lstm_2有形状(无,300,100)但是有形状的数组(1000,300,1)

我的错误是模型不接受我的数据形状和单位大小?

2 个答案:

答案 0 :(得分:0)

第二个模型中LSTM图层的单位数是其初始化程序的第一个参数,即2.即,如果您允许timestep = 10input_dim = 2units = 2,然后两个模型完全等效。

答案 1 :(得分:0)

这两种型号没有结构差异;它们都由编码器和LSTM层实现的解码器组成。区别在于符号;第一个模型在functional API上定义,输入被视为一个层,而第二个模型使用sequential API定义。至于编码器 - 解码器(也称为seq2seq)架构,它最初被提出here,并且自那以后发展很快,最显着的改进是关注层。

相关问题