简体   繁体   中英

Keras apply different Dense layer to each timestep

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?

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()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM