def _initialize_params(
        self,
        model: KERAS_MODEL_TYPE,
        input_layer: int,
        output_layer: int,
    ):
        """
        Initialize most parameters of the regressor. This is a convenience function called by `__init__` and
        `__setstate__` to avoid code duplication.

        :param model: Keras model
        :param input_layer: Which layer to consider as the Input when the model has multiple input layers.
        :param output_layer: Which layer to consider as the Output when the model has multiple output layers.
        """

        if self.is_tensorflow:
            import tensorflow as tf

            if tf.executing_eagerly():  # pragma: no cover
                raise ValueError("TensorFlow is executing eagerly. Please disable eager execution.")
            import tensorflow.keras as keras  # pylint: disable=consider-using-from-import
            import tensorflow.keras.backend as k

            self._losses = keras.losses
        else:
            import keras
            import keras.backend as k

            if hasattr(keras.utils, "losses_utils"):
                self._losses = keras.utils.losses_utils
            else:
                self._losses = None

        if hasattr(model, "inputs") and model.inputs is not None:
            self._input_layer = input_layer
            self._input = model.inputs[input_layer]
        else:
            self._input = model.input
            self._input_layer = 0

        if hasattr(model, "outputs") and model.outputs is not None:
            self._output = model.outputs[output_layer]
            self._output_layer = output_layer
        else:
            self._output = model.output
            self._output_layer = 0

        self._input_shape = k.int_shape(self._input)[1:]
        logger.debug(
            "Inferred %s as input shape for Keras regressor.",
            str(self.input_shape),
        )

        # Get loss function
        if not hasattr(self._model, "loss"):
            logger.warning("Keras model has no loss set. Regressor tries to use `k.mean_squared_error`.")
            loss_function = k.mean_squared_error
        else:
            self._orig_loss = self._model.loss
            if isinstance(self._model.loss, six.string_types):
                if self._model.loss in [
                    "mean_squared_error",
                    "mean_absolute_error",
                    "mean_absolute_percentage_error",
                    "mean_squared_logarithmic_error",
                    "cosine_similarity",
                ]:
                    loss_function = getattr(keras.losses, self._model.loss)
                else:
                    loss_function = getattr(k, self._model.loss)

            elif "__name__" in dir(self._model.loss) and self._model.loss.__name__ in [
                "mean_squared_error",
                "mean_absolute_error",
                "mean_absolute_percentage_error",
                "mean_squared_logarithmic_error",
                "cosine_similarity",
            ]:
                loss_function = getattr(keras.losses, self._model.loss.__name__)

            elif isinstance(
                self._model.loss,
                (
                    keras.losses.MeanSquaredError,
                    keras.losses.MeanAbsoluteError,
                    keras.losses.MeanSquaredLogarithmicError,
                    keras.losses.MeanAbsolutePercentageError,
                    keras.losses.CosineSimilarity,
                ),
            ):
                loss_function = self._model.loss
            else:
                loss_function = getattr(k, self._model.loss.__name__)

        label_ph = k.placeholder(shape=self._output.shape)
        loss_ = loss_function(label_ph, self._output)

        # Define loss gradients
        loss_gradients = k.gradients(loss_, self._input)

        if k.backend() == "tensorflow":
            loss_gradients = loss_gradients[0]
        elif k.backend() == "cntk":  # pragma: no cover
            raise NotImplementedError("Only TensorFlow is supported as backend for Keras.")

        # Set loss, gradients and prediction functions
        self._predictions_op = self._output
        self._loss_function = loss_function
        self._loss = loss_
        self._loss_gradients = k.function([self._input, label_ph, k.learning_phase()], [loss_gradients])

        # Get the internal layer
        self._layer_names = self._get_layers()

        Initialize most parameters of the regressor. This is a convenience function called by `__init__` and
        `__setstate__` to avoid code duplication.

        :param model: Keras model
        :param input_layer: Which layer to consider as the Input when the model has multiple input layers.
        :param output_layer: Which layer to consider as the Output when the model has multiple output layers.
        
art/estimators/regression/keras.py