|
13 | 13 |
|
14 | 14 | import numpy as np
|
15 | 15 |
|
| 16 | +import h5py |
| 17 | +from keras.engine import saving |
16 | 18 | from keras.callbacks import EarlyStopping
|
17 | 19 | from keras.layers import (
|
18 | 20 | LSTM,
|
|
30 | 32 | from keras.models import Model
|
31 | 33 | from keras.optimizers import Adam, RMSprop
|
32 | 34 | from keras_contrib.layers import CRF
|
33 |
| -from keras_contrib.utils import save_load_utils |
34 | 35 | from sklearn_crfsuite import metrics
|
35 | 36 |
|
36 | 37 | from deep_reference_parser.logger import logger
|
@@ -976,26 +977,17 @@ def load_weights(self):
|
976 | 977 |
|
977 | 978 | if not self.model:
|
978 | 979 |
|
979 |
| - # Assumes that model has been buit with build_model! |
980 |
| - |
981 | 980 | logger.exception(
|
982 | 981 | "No model. you must build the model first with build_model"
|
983 | 982 | )
|
984 | 983 |
|
985 |
| - # NOTE: This is not required if incldue_optimizer is set to false in |
986 |
| - # load_all_weights. |
987 |
| - |
988 |
| - # Run the model for one epoch to initialise network weights. Then load |
989 |
| - # full trained weights |
990 |
| - |
991 |
| - # self.model.fit(x=self.X_testing, y=self.y_test_encoded, |
992 |
| - # batch_size=2500, epochs=1) |
993 |
| - |
994 | 984 | logger.debug("Loading weights from %s", self.weights_path)
|
995 | 985 |
|
996 |
| - save_load_utils.load_all_weights( |
997 |
| - self.model, self.weights_path, include_optimizer=False |
998 |
| - ) |
| 986 | + with h5py.File(self.weights_path, mode='r') as f: |
| 987 | + saving.load_weights_from_hdf5_group( |
| 988 | + f['model_weights'], self.model.layers |
| 989 | + ) |
| 990 | + |
999 | 991 |
|
1000 | 992 | def predict(self, X, load_weights=False):
|
1001 | 993 | """
|
|
0 commit comments