repeats the input n times example x keras inputshape32 y keras layers repeatvector3x y shape none 3 32 args n integer repetition factor input shape 2d tensor with shape batchsize features output shape 3d tensor with shape batchsize n features repeats the input n times example x keras input shape 32 y keras layers repeatvector 3 x y shape none 3 32 args n integer repetition factor input shape 2d tensor with shape batch_size features output shape 3d tensor with shape batch_size n features
from keras import ops
from keras.api_export import keras_export
from keras.layers.input_spec import InputSpec
from keras.layers.layer import Layer


@keras_export("keras.layers.RepeatVector")
class RepeatVector(Layer):
    

    def __init__(self, n, **kwargs):
        super().__init__(**kwargs)
        self.n = n
        if not isinstance(n, int):
            raise TypeError(
                f"Expected an integer value for `n`, got {type(n)}."
            )
        self.input_spec = InputSpec(ndim=2)

    def compute_output_shape(self, input_shape):
        return (input_shape[0], self.n, input_shape[1])

    def call(self, inputs):
        input_shape = ops.shape(inputs)
        reshaped = ops.reshape(inputs, (input_shape[0], 1, input_shape[1]))
        return ops.repeat(reshaped, self.n, axis=1)

    def get_config(self):
        config = {"n": self.n}
        base_config = super().get_config()
        return {**base_config, **config}