From 782f111e76b2ab656e499e38a001eec3ac3df537 Mon Sep 17 00:00:00 2001
From: leufen1 <l.leufen@fz-juelich.de>
Date: Thu, 4 Mar 2021 10:46:12 +0100
Subject: [PATCH] addendum to FCN class: enable linear activations and add
 output_activation parameter

---
 mlair/model_modules/fully_connected_networks.py | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/mlair/model_modules/fully_connected_networks.py b/mlair/model_modules/fully_connected_networks.py
index 940c9846..dbcd3a9f 100644
--- a/mlair/model_modules/fully_connected_networks.py
+++ b/mlair/model_modules/fully_connected_networks.py
@@ -63,12 +63,13 @@ class FCN(AbstractModelClass):
     """
 
     _activation = {"relu": keras.layers.ReLU, "tanh": partial(keras.layers.Activation, "tanh"),
-                   "sigmoid": partial(keras.layers.Activation, "sigmoid")}
+                   "sigmoid": partial(keras.layers.Activation, "sigmoid"),
+                   "linear": partial(keras.layers.Activation, "linear")}
     _optimizer = {"adam": keras.optimizers.adam, "sgd": keras.optimizers.SGD}
     _requirements = ["lr", "beta_1", "beta_2", "epsilon", "decay", "amsgrad", "momentum", "nesterov"]
 
-    def __init__(self, input_shape: list, output_shape: list, activation="relu", optimizer="adam",
-                 n_layer=1, n_hidden=10, **kwargs):
+    def __init__(self, input_shape: list, output_shape: list, activation="relu", activation_output="linear",
+                 optimizer="adam", n_layer=1, n_hidden=10, **kwargs):
         """
         Sets model and loss depending on the given arguments.
 
@@ -82,6 +83,7 @@ class FCN(AbstractModelClass):
 
         # settings
         self.activation = self._set_activation(activation)
+        self.activation_output = self._set_activation(activation_output)
         self.optimizer = self._set_optimizer(optimizer, **kwargs)
         self.layer_configuration = (n_layer, n_hidden)
         self._update_model_name()
@@ -127,7 +129,7 @@ class FCN(AbstractModelClass):
             x_in = keras.layers.Dense(n_hidden)(x_in)
             x_in = self.activation()(x_in)
         x_in = keras.layers.Dense(self._output_shape)(x_in)
-        out = self.activation()(x_in)
+        out = self.activation_output()(x_in)
         self.model = keras.Model(inputs=x_input, outputs=[out])
 
     def set_compile_options(self):
-- 
GitLab