title: Disable tensorflow retracing warning in keras
body: <p>I have created keras functional API model and now I'm trying to look into it's layers outputs creating submodels for every layer which starts with original model's input and ends with the layer of my choosing. I don't understand what is the proper way to do this without getting</p>
  <pre><code>WARNING:tensorflow:11 out of the last 11 calls to 
  &lt;function Model.make_predict_function.&lt;locals&gt;.predict_function at 0x7fb8ebc92700&gt; 
  triggered tf.function retracing.
  Tracing is expensive and the excessive number of tracings could be due to (1) creating @tf.function repeatedly 
  in a loop, (2) passing tensors with different shapes, 
  (3) passing Python objects instead of tensors. 
  For (1), please define your @tf.function outside of the loop. 
  For (2), @tf.function has experimental_relax_shapes=True option that relaxes argument shapes 
  that can avoid unnecessary retracing. 
  For (3), please refer to https://www.tensorflow.org/tutorials/customization/performance#python_or_tensor_args 
  and https://www.tensorflow.org/api_docs/python/tf/function for  more details.
  </code></pre>
  <p>I don't know where to add <code>@tf.function(experimental_relax_shapes=True)</code> because I'm not defining my own functions which I pass to Keras<br>
  I have tried to disable warning with <code>tf.get_logger().setLevel(3)</code> with no success<br></p>
  <p>This is where I get this message:</p>
  <pre><code>def extract(layer):
      submodel = keras.Model(inputs = model.input, outputs = layer.output)
      submodel_output = submodel.predict(np.array(X[random_index]).reshape(1, IMG_SIZE, IMG_SIZE, 3))
      
  for model_layer in model.layers:
      extract(model_layer)
  </code></pre>
  <p>If there is a way to solve this problem / disable warning (optimization is not the issue) please let me know and thank you in advance.</p>