title: How to add time-series preprocessing function (sequencing) to Tensorflow model
body: <p>I am currently working with tensorflow to create an inference model. I want to add a preprocessing function inside my model. I have already added an Input layer with shape (1,) as the first layer, but I don't have any clue on how to add the preprocessing function to the layer because I'm not familiar with TensorObject operations.</p>
  <p>My model summary looks like this:</p>
  <pre><code>Model: &quot;sequential&quot;
  _________________________________________________________________
   Layer (type)                Output Shape              Param #   
  =================================================================
   lstm (LSTM)                 (None, 128)               66560     
                                                                   
   dropout (Dropout)           (None, 128)               0         
                                                                   
   repeat_vector (RepeatVector  (None, 60, 128)          0         
   )                                                               
                                                                   
   lstm_1 (LSTM)               (None, 60, 128)           131584    
                                                                   
   dropout_1 (Dropout)         (None, 60, 128)           0         
                                                                   
   time_distributed (TimeDistr  (None, 60, 1)            129       
   ibuted)                                                         
                                                                   
  =================================================================
  Total params: 198,273
  Trainable params: 198,273
  Non-trainable params: 0
  _________________________________________________________________
  </code></pre>
  <p>I have tried to create a custom layer for preprocessing but I got an error that I don't really understand. It calls the function when I create the model, because the first dimension of input shape is None I can't operate the layer. This is the code:</p>
  <pre><code>@tf.function
  def create_sequences(X, time_steps=60):
    Xs = []
    for i in range(len(X)-time_steps):
      Xs.append(X[i:(i+time_steps)])
    return Xs
  
  class SequencingTFLayer(tf.keras.layers.Layer):
      def __init__(self, name=&quot;preprocess_tf&quot;, **kwargs):
          super(SequencingTFLayer, self).__init__(name=name, **kwargs)
          self.preprocess = create_sequences
      
      def call(self, input):
          return self.preprocess(input)
  
      def get_config(self):
          config = super(SequencingTFLayer, self).get_config()
          return config
  
  input = tf.keras.layers.Input(shape=(1,), dtype=&quot;float&quot;, name='input_timeseries')
  x = SequencingTFLayer()(input)
  x = model(x)
  new_model = tf.keras.Model(input, x, name=model.name)
  new_model.output_names = model.output_names
  </code></pre>