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

fix keras tensorflow.keras.models load_model is legacy #390 #391

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion nmma/em/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ def __init__(
import tensorflow as tf

tf.get_logger().setLevel("ERROR")
from tensorflow.keras.models import load_model
from keras.models import load_model

if not local_only:
_, model_filters = get_model(self.svd_path, f"{self.model}_tf", filters=filters)
Expand Down
9 changes: 5 additions & 4 deletions nmma/em/training.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,8 +415,9 @@ def train_tensorflow_model(self, dropout_rate=0.6):

tf.get_logger().setLevel("ERROR")
from sklearn.model_selection import train_test_split
from tensorflow.keras import Sequential
from tensorflow.keras.layers import Dense, Dropout
import keras
from keras import Sequential
from keras.layers import Dense, Dropout
except ImportError:
print("Install tensorflow if you want to use it...")
return
Expand All @@ -436,7 +437,7 @@ def train_tensorflow_model(self, dropout_rate=0.6):
random_state=self.random_seed,
)

tf.keras.utils.set_random_seed(self.random_seed)
keras.utils.set_random_seed(self.random_seed)

if self.model_exists and self.continue_training:
model = self.svd_model[filt]["model"]
Expand Down Expand Up @@ -561,7 +562,7 @@ def load_model(self):

elif self.interpolation_type == "tensorflow":
try:
from tensorflow.keras.models import load_model as load_tf_model
from keras.models import load_model as load_tf_model
except ImportError:
print("Install tensorflow if you want to use it...")
return
Expand Down
6 changes: 3 additions & 3 deletions tutorials/tutorial-KN-models-training.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -873,9 +873,9 @@
"outputs": [],
"source": [
"import tensorflow as tf\n",
"from tensorflow.keras import Sequential\n",
"from tensorflow.keras.layers import Dense, Dropout\n",
"from tensorflow.keras.utils import plot_model"
"from keras import Sequential\n",
"from keras.layers import Dense, Dropout\n",
"from keras.utils import plot_model"
]
},
{
Expand Down
Loading