Keras's RepeatVector layer allows me to repeat a given vector/Tensor n times: https://www.tensorflow.org/api_docs/python/tf/keras/layers/RepeatVector.
However, it appears n has to be a constant. Is there any way to specify this parameter dynamically?
Use case: I'm generating variable length sequences, and RepeatVector will be followed by an LSTM layer.
It can be a symbolic tensor. Therefore, you can use the backend function shape() (or alternatively tf.shape()) to dynamically find the number of timesteps from input tensor of LSTM layer:
from keras import backend as K
reps = RepeatVector(K.shape(lstm_input)[1])(lstm_out)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With