Keras Bug 解决方法 Exception ignored in: bound method BaseSession.__del__ of

报错信息

Exception ignored in: >
Traceback (most recent call last):
  File "python3.5.2\lib\site-packages\tensorflow\python\client\session.py", line xxx, in __del__
TypeError: 'NoneType' object is not callable

原因:Python垃圾回收机制在回收session对象时,发现 c_api_util 或 tf_session已经被回收了,造成了空指针。下面这段注释就是tensorflow源码中抛出异常时给出的原因

# At shutdown, `c_api_util` or `tf_session` may have been garbage
# collected, causing the above method calls to fail. In this case,
# silently leak since the program is about to terminate anyway.

解决方法

方法一:

import keras.backend as K

# your code

K.clear_session()

方法二:

import gc

# your code

gc.collect()

参考

https://github.com/tensorflow/tensorflow/issues/3388

https://www.cnblogs.com/kaituorensheng/p/4449457.html

你可能感兴趣的:(深度学习)