Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

save session for running with webbase app(Flask) #59

Merged
merged 1 commit into from
Nov 6, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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