Using TensorFlow (version 1.12.0) and Keras (version 2.2.4) on a GPU cluster, I trained 10 simple and identical classifiers in a loop. I encountered unexpectedly wide variation in performance. After some troubleshooting, I decided to look into the way I was clearing the Keras session between models. I found that
import tensorflow as tf
import keras.backend as K
from keras import Sequential
from keras.layers import Lambda, Dense, Flatten
for i in range(10):
K.clear_session()
# train models
did not solve my problem. When I switched to
import tensorflow as tf
import keras.backend as K
from keras import Sequential
from keras.layers import Lambda, Dense, Flatten
for i in range(10):
tf.keras.backend.clear_session()
# train models
the problem went away. All of my models are built on objects from keras
, so I would have thought that having keras
clear the session would work, but evidently it didn't.
What is the difference between K.clear_session()
and tf.keras.backend.clear_session()
in this case? Why did the first not seem to have much effect, while the second brought my classifiers closer to their expected performance?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.