简体   繁体   English

Tensorflow (v1.12.0) - keras.backend.clear_session() 和 tf.keras.backend.clear_session 有什么区别?

[英]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.

相关问题 tf.keras.backend.clear_session实际做什么? - What tf.keras.backend.clear_session actually do? keras.backend.clear_session()是删除进程中的会话还是全局? - Does keras.backend.clear_session() deletes sessions in a process or globally? 在 Lambda 层以及 Dense 和 keras.backend.clear_session() 中使用 VGG preprocess_input 时出现 KERAS 错误 - KERAS error when using VGG preprocess_input in Lambda layers together with Dense and keras.backend.clear_session() Keras后端:启动交互式TF会话 - Keras backend: starting interactive TF session Tensorflow后端在Keras中进行图形会话空错误 - graph session empty error in Keras with Tensorflow backend tf.keras.backend.get_session()和keras.backend.get_session()返回不同的会话对象 - tf.keras.backend.get_session() and keras.backend.get_session() return different session objects 使用 CPU(在 Tensorflow 2.x 中)“Keras 后端 + Tensorflow”和“来自 Tensorflow 的 Keras”有什么区别 - What is difference between “Keras backend + Tensorflow” and “Keras from Tensorflow” using CPU(in Tensorflow 2.x) 从 keras.backend.tensorflow_backend 导入 set_session - from keras.backend.tensorflow_backend import set_session 如何清除使用 Keras 和 Tensorflow(作为后端)创建的 model? - How can I clear a model created with Keras and Tensorflow(as backend)? keras.backend 的 clear_session() 方法没有清理拟合数据 - The clear_session() method of keras.backend does not clean up the fitting data
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM