报错信息

Exception ignored in: <bound method BaseSession.__del__ of <tensorflow.python.client.session.Session object at 0x000000001AB286D8>>
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

Logo

有“AI”的1024 = 2048,欢迎大家加入2048 AI社区

更多推荐