try catched error around capture session

This commit is contained in:
Abubakar Abid 2020-07-01 11:43:26 -05:00
parent aa26636c27
commit 41cb88d635

View File

@ -118,7 +118,7 @@ class Interface:
durations = [] durations = []
for predict_fn in self.predict: for predict_fn in self.predict:
start = time.time() start = time.time()
if self.capture_session: if self.capture_session and not(self.session is None):
graph, sess = self.session graph, sess = self.session
with graph.as_default(): with graph.as_default():
with sess.as_default(): with sess.as_default():
@ -212,9 +212,12 @@ class Interface:
# self.validate() # self.validate()
if self.capture_session: if self.capture_session:
import tensorflow as tf try:
self.session = tf.get_default_graph(), \ import tensorflow as tf
tf.keras.backend.get_session() self.session = tf.get_default_graph(), \
tf.keras.backend.get_session()
except (ImportError, AttributeError): # If they are using TF >= 2.0 or don't have TF, just ignore this.
pass
# If an existing interface is running with this instance, close it. # If an existing interface is running with this instance, close it.
if self.status == "RUNNING": if self.status == "RUNNING":