Skip to content

Commit

Permalink
save session for running with webbase app(Flask) (#59)
Browse files Browse the repository at this point in the history
  • Loading branch information
WisTiCeJEnT authored and titipata committed Nov 6, 2019
1 parent 15293b8 commit c29f0df
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions deepcut/deepcut.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ def __init__(self, ngram_range=(1, 1), stop_words=None,
self.model = get_convo_nn2()
self.model.load_weights(WEIGHT_PATH)
self.graph = backend.get_session().graph # save graph for reference in async
self.sess = backend.get_session()

self.vocabulary_ = {}
self.ngram_range = ngram_range
Expand Down Expand Up @@ -299,6 +300,7 @@ def tokenize(self, text, custom_dict=None):
# Fix thread-related issue in Keras + TensorFlow + Flask async environment
# ref: https://github.com/keras-team/keras/issues/2397
with self.graph.as_default():
backend.set_session(self.sess)
y_predict = self.model.predict([x_char, x_type])
y_predict = (y_predict.ravel() > 0.5).astype(int)
word_end = y_predict[1:].tolist() + [1]
Expand Down

0 comments on commit c29f0df

Please sign in to comment.