本文介绍了Keras对每个时间步应用不同的Dense层的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有(-1, 10)形状的训练数据,并且我想在每个时间步上应用不同的Dense层.目前,我试图通过将输入重塑为(-1, 20, 1),然后在顶部使用TimeDistributed(Dense(10))层来实现此目的.但是,这似乎将相同的密集"层应用于每个时间步,因此时间步共享权重.有什么办法吗?

I have training data in the shape of (-1, 10) and I want to apply a different Dense layer to each timestep. Currently, I tried to achieve this by reshaping input to (-1, 20, 1) and then using a TimeDistributed(Dense(10)) layer on top. However, that appears to apply the same Dense layer to each timestep, so timesteps share the weights. Any way to do that?

推荐答案

您可以应用200宽的矢量的密集层,该矢量是通过将输入复制20次而创建的,如下所示:

You can apply a dense layer of a vector 200-wide which is created by copying the input 20 times, like so:

from tensorflow.python import keras
from keras.models import Sequential
from keras.layers import *

model = Sequential()
model.add(RepeatVector(20, input_shape=(10,)))
model.add(Reshape((200,)))
model.add(Dense(1))
model.compile('sgd', 'mse')
model.summary()

这篇关于Keras对每个时间步应用不同的Dense层的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-19 17:54