diff --git a/l2rpn_baselines/DuelQSimple/train.py b/l2rpn_baselines/DuelQSimple/train.py index 113e833..0b4d6ae 100755 --- a/l2rpn_baselines/DuelQSimple/train.py +++ b/l2rpn_baselines/DuelQSimple/train.py @@ -115,7 +115,7 @@ def train(env, sizes = [800, 800, 800, 494, 494, 494] # sizes of each hidden layers kwargs_archi = {'observation_size': observation_size, 'sizes': sizes, - 'activs': ["relu" for _ in range(sizes)], # all relu activation function + 'activs': ["relu" for _ in sizes], # all relu activation function "list_attr_obs": li_attr_obs_X} # select some part of the action diff --git a/l2rpn_baselines/SAC/SAC_NN.py b/l2rpn_baselines/SAC/SAC_NN.py index e01a8cd..0a40967 100644 --- a/l2rpn_baselines/SAC/SAC_NN.py +++ b/l2rpn_baselines/SAC/SAC_NN.py @@ -16,7 +16,6 @@ with warnings.catch_warnings(): warnings.filterwarnings("ignore", category=FutureWarning) from tensorflow.keras.models import load_model, Sequential, Model - import tensorflow.keras.optimizers as tfko from tensorflow.keras.layers import Activation, Dense from tensorflow.keras.layers import Input, Concatenate @@ -245,11 +244,12 @@ def load_network(self, path, name=None, ext="h5"): We load all the models using the keras "load_model" function. """ path_model, path_target_model, path_modelQ, path_modelQ2, path_policy = self._get_path_model(path, name) - self.model_value = load_model('{}.{}'.format(path_model, ext)) - self.model_value_target = load_model('{}.{}'.format(path_target_model, ext)) - self.model_Q = load_model('{}.{}'.format(path_modelQ, ext)) - self.model_Q2 = load_model('{}.{}'.format(path_modelQ2, ext)) - self.model_policy = load_model('{}.{}'.format(path_policy, ext)) + self.construct_q_network() + self.model_value.load_weights('{}.{}'.format(path_model, ext)) + self.model_value_target.load_weights('{}.{}'.format(path_target_model, ext)) + self.model_Q.load_weights('{}.{}'.format(path_modelQ, ext)) + self.model_Q2.load_weights('{}.{}'.format(path_modelQ2, ext)) + self.model_policy.load_weights('{}.{}'.format(path_policy, ext)) if self.verbose: print("Succesfully loaded network.") diff --git a/l2rpn_baselines/utils/BaseDeepQ.py b/l2rpn_baselines/utils/BaseDeepQ.py index 2e1d8d8..a9c54d3 100644 --- a/l2rpn_baselines/utils/BaseDeepQ.py +++ b/l2rpn_baselines/utils/BaseDeepQ.py @@ -13,8 +13,6 @@ import tensorflow as tf import tensorflow.keras.optimizers as tfko -from tensorflow.keras.models import load_model - from l2rpn_baselines.utils.TrainingParam import TrainingParam @@ -204,11 +202,14 @@ def load_network(self, path, name=None, ext="h5"): The file extension (by default h5) """ path_model, path_target_model = self.get_path_model(path, name) - self._model = load_model('{}.{}'.format(path_model, ext), custom_objects=self._custom_objects) + # fix for issue https://github.com/keras-team/keras/issues/7440 + self.construct_q_network() + + self._model.load_weights('{}.{}'.format(path_model, ext)) with warnings.catch_warnings(): warnings.filterwarnings("ignore") - self._target_model = load_model('{}.{}'.format(path_target_model, ext), custom_objects=self._custom_objects) + self._target_model.load_weights('{}.{}'.format(path_target_model, ext)) if self.verbose: print("Succesfully loaded network.")