[英]Tensorflow (v1.12.0) - what is the difference between keras.backend.clear_session() and tf.keras.backend.clear_session()?
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.在 GPU 集群上使用 TensorFlow(版本 1.12.0)和 Keras(版本 2.2.4),我在一个循环中训练了 10 个简单且相同的分类器。 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.
经过一些故障排除后,我决定研究清除模型之间的 Keras session 的方式。 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.我所有的模型都建立在
keras
的对象上,所以我认为让keras
清除 session 会起作用,但显然它没有。
What is the difference between K.clear_session()
and tf.keras.backend.clear_session()
in this case?在这种情况下,
K.clear_session()
和tf.keras.backend.clear_session()
有什么区别? Why did the first not seem to have much effect, while the second brought my classifiers closer to their expected performance?为什么第一个似乎没有太大效果,而第二个使我的分类器更接近预期的性能?
The difference is that TF v1.12
was released on Nov 5, 2018 whereas Keras v2.2.4
was released on Oct 03, 2018 which means Keras v2.2.4
uses TF v1.11
as backend.不同之处在于
TF v1.12
v1.12 发布于 2018 年 11 月 5 日,而Keras v2.2.4
发布于 2018 年 10 月 3 日,这意味着Keras v2.2.4
使用TF v1.11
作为后端。
Take a look at Tensorflow release history here and the Keras release history here .在这里查看Tensorflow 发布历史和 Keras 发布历史。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.