def clone_for_refitting(
        self,
    ) -> "KERAS_ESTIMATOR_TYPE":
        """
        Create a copy of the estimator that can be refit from scratch. Will inherit same architecture, optimizer and
        initialization as cloned model, but without weights.

        :return: new estimator
        """

        import tensorflow as tf
        import keras

        try:
            # only works for functionally defined models
            model = keras.models.clone_model(self.model, input_tensors=self.model.inputs)
        except ValueError as error:
            raise ValueError("Cannot clone custom models") from error

        optimizer = self.model.optimizer
        # reset optimizer variables
        for var in optimizer.variables():
            var.assign(tf.zeros_like(var))

        loss_weights = None
        weighted_metrics = None
        if self.model.compiled_loss:
            loss_weights = self.model.compiled_loss._loss_weights
        if self.model.compiled_metrics:
            weighted_metrics = self.model.compiled_metrics._weighted_metrics

        model.compile(
            optimizer=optimizer,
            loss=self.model.loss,
            metrics=[m.name for m in self.model.metrics],  # Need to copy metrics this way for keras
            loss_weights=loss_weights,
            weighted_metrics=weighted_metrics,
            run_eagerly=self.model.run_eagerly,
        )

        clone = type(self)(model=model, channels_first=self.channels_first)
        params = self.get_params()
        del params["model"]
        clone.set_params(**params)
        return clone

        Create a copy of the estimator that can be refit from scratch. Will inherit same architecture, optimizer and
        initialization as cloned model, but without weights.

        :return: new estimator
        
art/estimators/keras.py