title: Can I use loops inside a model using functional API?
body: <p>I have a trained keras model which takes inputs of size (batchSize,2). This works well and gives good results.</p>
  
  <p>My main problem is to have a model which takes an input a vector of size(batchSize,2,16) and slice it inside the model to 16 vectors of size(batchSize,2) and concatenate the outputs together.</p>
  
  <p>I have used this code for this </p>
  
  <pre><code>    y = layers.Input(shape=(2,16,))
  
      model_x= load_model('saved_model')
  
      for i in range(16):
          x_input = Lambda(lambda x: x[:, :, i])(y)
  
          if i == 0:
             x_output = model_x(x_input)
          else:
              x_output = layers.concatenate([x_output, 
                                        model_x(x_input)])
  
      x_output = Lambda(lambda x: x[:, :tf.cast(N, tf.int32)])(x_output)
  
      final_model = Model(y, x_output)
  
  
  </code></pre>
  
  <p>Although the saved model gives me good performance, this code does not trains well and doesn't give the intended performance. 
  What can I do to get better results?</p>