Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
284 views
Welcome To Ask or Share your Answers For Others

1 Answer

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...