|
5 | 5 | from keras.models import Sequential |
6 | 6 | from keras.layers import LSTM, Dense, TimeDistributed, Bidirectional, Embedding, Dropout |
7 | 7 | from tensorflow import keras |
| 8 | +import tensorflow as tf |
8 | 9 |
|
9 | 10 | from . import constants |
10 | 11 | from .helpers import sigmoid |
@@ -600,7 +601,9 @@ def save_model(self): |
600 | 601 | This function saves the current trained model of this word_segmenter instance. |
601 | 602 | """ |
602 | 603 | # Save the model using Keras |
603 | | - self.model.save(Path.joinpath(Path(__file__).parent.parent.absolute(), "Models/" + self.name)) |
| 604 | + model_path = (Path.joinpath(Path(__file__).parent.parent.absolute(), "Models/" + self.name)) |
| 605 | + tf.saved_model.save(self.model, model_path) |
| 606 | + |
604 | 607 | # Save one np array that holds all weights |
605 | 608 | file = Path.joinpath(Path(__file__).parent.parent.absolute(), "Models/" + self.name + "/weights") |
606 | 609 | np.save(str(file), self.model.weights) |
@@ -652,7 +655,7 @@ def pick_lstm_model(model_name, embedding, train_data, eval_data): |
652 | 655 | eval_data: the data set to test the model. Often, it should have the same structure as training data set. |
653 | 656 | """ |
654 | 657 | file = Path.joinpath(Path(__file__).parent.parent.absolute(), 'Models/' + model_name) |
655 | | - model = keras.models.load_model(file) |
| 658 | + model = keras.layers.TFSMLayer(file, call_endpoint='serving_default') |
656 | 659 |
|
657 | 660 | # Figuring out name of the model |
658 | 661 | language = None |
|
0 commit comments