- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我有一个这样定义的自动编码器
inputs = Input(batch_shape=(1,timesteps, input_dim))
encoded = LSTM(4,return_sequences = True)(inputs)
encoded = LSTM(3,return_sequences = True)(encoded)
encoded = LSTM(2)(encoded)
decoded = RepeatVector(timesteps)(encoded)
decoded = LSTM(3,return_sequences = True)(decoded)
decoded = LSTM(4,return_sequences = True)(decoded)
decoded = LSTM(input_dim,return_sequences = True)(decoded)
sequence_autoencoder = Model(inputs, decoded)
encoder = Model(inputs,encoded)
我希望编码器像这样连接到 LSTM 层
f_input = Input(batch_shape=(1, timesteps, input_dim))
encoder_input = encoder(inputs=f_input)
single_lstm_layer = LSTM(50, kernel_initializer=RandomUniform(minval=-0.05, maxval=0.05))(encoder_input)
drop_1 = Dropout(0.33)(single_lstm_layer)
output_layer = Dense(12, name="Output_Layer"
)(drop_1)
final_model = Model(inputs=[f_input], outputs=[output_layer])
但它给我一个尺寸错误。
Input 0 is incompatible with layer lstm_3: expected ndim=3, found ndim=2
我怎样才能正确地做到这一点?
最佳答案
我认为主要问题源于最后一个 encoded
不是重复向量这一事实。要将编码器输出提供给 LSTM,需要通过 RepeatVector
层发送。换句话说,编码器的最后一个输出需要具有 [batch_size, time_steps, dim]
形状才能被送入 LSTM。这可能是您要找的东西?
inputs = Input(batch_shape=(1,timesteps, input_dim))
encoded = LSTM(4,return_sequences = True)(inputs)
encoded = LSTM(3,return_sequences = True)(encoded)
encoded = LSTM(2)(encoded)
encoded_repeat = RepeatVector(timesteps)(encoded)
decoded = LSTM(3,return_sequences = True)(encoded_repeat)
decoded = LSTM(4,return_sequences = True)(decoded)
decoded = LSTM(input_dim,return_sequences = True)(decoded)
sequence_autoencoder = Model(inputs, decoded)
encoder = Model(inputs,encoded_repeat)
f_input = Input(batch_shape=(1, timesteps, input_dim))
encoder_input = encoder(inputs=f_input)
single_lstm_layer = LSTM(50, kernel_initializer=RandomUniform(minval=-0.05, maxval=0.05))(encoder_input)
drop_1 = Dropout(0.33)(single_lstm_layer)
output_layer = Dense(12, name="Output_Layer"
)(drop_1)
final_model = Model(inputs=[f_input], outputs=[output_layer])
我已将您的第一个 decoded
重命名为 encode_repeat
关于python - 将编码器从 AutoEncoder 连接到 LSTM,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52201643/
有没有更简单的方法来设置数据加载器,因为在自动编码器的情况下输入和目标数据是相同的,并且在训练期间加载数据? DataLoader总是需要两个输入。 目前我这样定义我的数据加载器: X_train
我正在基于医疗保健开展项目,将针对症状和疾病进行自动编码器培训,即我的输入为文本形式。那行得通吗? (我正在使用Rstudio)。请任何人帮助我 最佳答案 您必须将文本转换为向量/数字。要实现诸如“单
有人可以向我解释为什么自动编码器不收敛吗?对我来说,下面两个网络的结果应该是一样的。然而,下面的自动编码器没有收敛,而它下面的网络却是。 # autoencoder implementation, d
我已经在 Tensorflow 中实现了以下自动编码器,如下所示。它基本上将 MNIST 数字作为输入,学习数据的结构并在其输出处再现输入。 from __future__ import divisi
我尝试在 Keras (tf.keras) 中构建一个 Stacked Autoencoder。作者 堆叠 我不是说深 .我为 Keras 找到的所有示例都在生成,例如3 个编码器层,3 个解码器层,
我正在尝试修复我的 Web 应用程序中的 XSS 漏洞,但我受困于 jqGrid。 我为我所有的网格激活了“自动编码”,文档说:“当设置为 true 时,会对传入的(来自服务器)和发布的数据(来自编辑
引发这个问题的具体原因是 return_sequence TensorFlow 版本的 LSTM 层的参数。 文档说: Boolean. Whether to return the last outp
我在实现变分自动编码器时遇到了一个大问题,它是所有图像最终看起来像这样: 当真实图像是这样的: 训练集是 CIFAR10,预期结果是设法构建相似的图像。虽然结果似乎正确预测了特征图,但我不明白为什么
在变分自编码器中,目标函数有两项,一项使输入和输出 x 相同,另一项是正则化,q(z) 和 p(z) 接近 KL 散度。 我不明白的是为什么我们可以假设 p(z)~Normal Gaussian 具有
我目前使用的生成器在卷积网络上运行良好。但是,当我使用相同的生成器来拟合自动编码器时,出现以下错误。 **Exception: output of generator should be a tupl
我有一个这样定义的自动编码器 inputs = Input(batch_shape=(1,timesteps, input_dim)) encoded = LSTM(4,return_sequence
我使用 lasagne/nolearn 训练了一个自动编码器。假设网络层是 [500, 100, 100, 500]。我已经像这样训练了神经网络: net.fit(X, X) 我想做如下的事情: ne
我的数据是 DataFrame : dOpen dHigh dLow dClose dVolume day_of_week_0 day_of_week_1
我在本教程中阅读了 LSTM-autoencoder:https://blog.keras.io/building-autoencoders-in-keras.html ,并在下面粘贴相应的 kera
我使用 Python 和 Tensorflow 构建了一个自动编码器。为了构建自动编码器,我使用了关于如何构建自动编码器以读取手写数字上的 MNIST 数据集的 Tensorflow 教程。我用它来寻
我做了一个自动编码器模型,并运行测试 行为在我的印象中: 输入:7数据* 88宽度 输出:7数据* 88宽度 行为真实 输入:7数据* 88宽度 输出:7data * 88 * 88 如何解决这个问题
我想向我的自动编码器添加初始化程序 autoencoder=Model(input_img, decoded) autoencoder.add(Dense(64,kernel_initializer=
我在 this tutorial 之后在 Keras 中创建一个自动编码器我不断收到以下错误。 decoder = tf.keras.Model(encoded_input, decoded(inpu
我是 Python 3.5 的新手。我正在尝试编写一个简单的自动编码器,它将在 60 张苹果图像的数据集上进行训练,并尝试重建根中给出的图像。我使用了以下代码: from keras.layers i
我是一名优秀的程序员,十分优秀!