diff --git a/n3fit/src/n3fit/backends/keras_backend/MetaLayer.py b/n3fit/src/n3fit/backends/keras_backend/MetaLayer.py index acdf01bc1d..2dc3c24105 100644 --- a/n3fit/src/n3fit/backends/keras_backend/MetaLayer.py +++ b/n3fit/src/n3fit/backends/keras_backend/MetaLayer.py @@ -8,7 +8,7 @@ For instance: np_to_tensor is just a call to K.constant """ -from keras.initializers import Constant, RandomUniform, glorot_normal, glorot_uniform +from keras.initializers import Constant, RandomUniform, glorot_normal, glorot_uniform, RandomNormal from keras.layers import Layer # Define in this dictionary new initializers as well as the arguments they accept (with default values if needed be) @@ -16,6 +16,7 @@ "random_uniform": (RandomUniform, {"minval": -0.5, "maxval": 0.5}), "glorot_uniform": (glorot_uniform, {}), "glorot_normal": (glorot_normal, {}), + "random_normal": (RandomNormal, {"mean": 0.0, "stddev": 0.05}), } diff --git a/n3fit/src/n3fit/layers/preprocessing.py b/n3fit/src/n3fit/layers/preprocessing.py index b716f8f398..78179db327 100644 --- a/n3fit/src/n3fit/layers/preprocessing.py +++ b/n3fit/src/n3fit/layers/preprocessing.py @@ -76,15 +76,15 @@ def generate_weight(self, name: str, kind: str, dictionary: dict, set_to_zero: b single_replica_initializer = MetaLayer.init_constant(0.0) trainable = False else: - minval, maxval = dictionary[kind] + prepro_kwargs = dictionary[kind] trainable = dictionary.get("trainable", True) # Seeds will be set in the wrapper MultiInitializer - single_replica_initializer = MetaLayer.select_initializer( - "random_uniform", minval=minval, maxval=maxval - ) + single_replica_initializer = MetaLayer.select_initializer(**prepro_kwargs) # If we are training, constrain the weights to be within the limits - if trainable: - constraint = constraints.MinMaxWeight(minval, maxval) + if trainable and prepro_kwargs["ini_name"] == "random_uniform": + constraint = constraints.MinMaxWeight( + prepro_kwargs["minval"], prepro_kwargs["maxval"] + ) initializer = MultiInitializer(single_replica_initializer, self._replica_seeds, base_seed=0) # increment seeds for the next coefficient