binarizer: reset TF session prior to predict()

pull/31/head
Robert Sachunsky 4 years ago
parent 02423648ec
commit ad50ed287d

@ -15,6 +15,7 @@ environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
stderr = sys.stderr stderr = sys.stderr
sys.stderr = open(devnull, 'w') sys.stderr = open(devnull, 'w')
from keras.models import load_model from keras.models import load_model
from keras.backend import tensorflow_backend
sys.stderr = stderr sys.stderr = stderr
import tensorflow as tf import tensorflow as tf
@ -42,8 +43,10 @@ class SbbBinarizer:
config.gpu_options.allow_growth = True config.gpu_options.allow_growth = True
self.session = tf.Session(config=config) # tf.InteractiveSession() self.session = tf.Session(config=config) # tf.InteractiveSession()
tensorflow_backend.set_session(self.session)
def end_session(self): def end_session(self):
tensorflow_backend.clear_session()
self.session.close() self.session.close()
del self.session del self.session
@ -55,6 +58,7 @@ class SbbBinarizer:
return model, model_height, model_width, n_classes return model, model_height, model_width, n_classes
def predict(self, model_in, img, use_patches): def predict(self, model_in, img, use_patches):
tensorflow_backend.set_session(self.session)
model, model_height, model_width, n_classes = model_in model, model_height, model_width, n_classes = model_in
img_org_h = img.shape[0] img_org_h = img.shape[0]

Loading…
Cancel
Save