title: Clear the graph and free the GPU memory in Tensorflow 2
body: <p>I'm training multiple models sequentially, which will be memory-consuming if I keep all models without any cleanup. However, I am not aware of any way to the graph and free the GPU memory in Tensorflow 2.x.</p>
  <h3>What I've tried but not working</h3>
  <p><code>tf.keras.backend.clear_session</code> does not work in my case as I've defined some custom layers</p>
  <p><code>tf.compat.v1.reset_default_graph</code> does not work either.</p>