Skip to content

[Solved] Exception ignored in: bound method BaseSession.__del__ of tensorflow.python.client.session.Session object at 0x7ff1243e0358

Problem

Today when I running a Keras program with Tensorflow backend, the following error message unexpectedly occurred:

Exception ignored in: <bound method BaseSession.__del__ of <tensorflow.python.client.session.Session object at 0x7ff1243e0358>>

I checked on the Internet and found that this is related to Python’s automatic resource recovery mechanism. It seems that Tensorflow also has a resource recovery mechanism, and one party took the lead in recovering the resource, causing the other one to find a null value.

So far, there are four solutions found on the Internet:

  • Update Tensorflow version
  • Delete __pycache__ folder
  • Use Keras package to clear session
  • Use gc module to reclaim resources (after testing, the problem can be solved in Tensorflow==1.12.0)

Use Keras Package To Clear Session

Importing the following module in head of program:

import keras.backend as K



Use the following code at the end.

K.clear_session()



Complete program:

import keras.backend as K

# ----------
# Your code
# ----------

K.clear_session()



Use gc Module To Reclaim Resource

By analogy, the method of using gc module to reclaim resources is as follows:

import gc 

# ----------
# Your code
# ----------

gc.collect()



References


Read More

Leave a Reply