TensorFlow 建立多个模型导致的运行过慢问题

在 TensorFlow 里,如果反复编译调度多个模型,代码的运行速度会越来越慢。应该及时调用tf.keras.backend.clear_session()进行资源释放。官方说明如下:

If you are creating many models in a loop, this global state will consume an increasing amount of memory over time, and you may want to clear it. Calling clear_session() releases the global state: this helps avoid clutter from old models and layers, especially when memory is limited.

原文地址:https://www.cnblogs.com/yaos/p/14021299.html