From ad50ed287d71ab15bdee453f6a6190197f88ed41 Mon Sep 17 00:00:00 2001 From: Robert Sachunsky Date: Thu, 10 Jun 2021 01:22:28 +0200 Subject: [PATCH] binarizer: reset TF session prior to predict() --- sbb_binarize/sbb_binarize.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/sbb_binarize/sbb_binarize.py b/sbb_binarize/sbb_binarize.py index cd0970c..557ed29 100644 --- a/sbb_binarize/sbb_binarize.py +++ b/sbb_binarize/sbb_binarize.py @@ -15,6 +15,7 @@ environ['TF_CPP_MIN_LOG_LEVEL'] = '3' stderr = sys.stderr sys.stderr = open(devnull, 'w') from keras.models import load_model +from keras.backend import tensorflow_backend sys.stderr = stderr import tensorflow as tf @@ -42,8 +43,10 @@ class SbbBinarizer: config.gpu_options.allow_growth = True self.session = tf.Session(config=config) # tf.InteractiveSession() + tensorflow_backend.set_session(self.session) def end_session(self): + tensorflow_backend.clear_session() self.session.close() del self.session @@ -55,6 +58,7 @@ class SbbBinarizer: return model, model_height, model_width, n_classes def predict(self, model_in, img, use_patches): + tensorflow_backend.set_session(self.session) model, model_height, model_width, n_classes = model_in img_org_h = img.shape[0]