Fix clear_session
For `threading.local`, a field needs to be set in `__init__` for it to be bound in each thread.
@@ -62,10 +62,17 @@ _GRAPH = threading.local()
# A graph which is used for constructing functions in eager mode.
_CURRENT_SCRATCH_GRAPH = threading.local()
+
# This is a thread local object that will hold the default internal TF session
# used by Keras. It can be set manually via `set_session(sess)`.
-_SESSION = threading.local()
-_SESSION.session = None
+class SessionLocal(threading.local):
+
+ def __init__(self):
+ super().__init__()
+ self.session = None
+
+
+_SESSION = SessionLocal()
# A global dictionary mapping graph objects to an index of counters used
