def clone_for_refitting(
        self,
    ) -> "TensorFlowV2Classifier":  # pragma: no cover
        """
        Create a copy of the classifier 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

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

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

        model.compile(
            optimizer=optimizer,
            loss=self.model.loss,
            metrics=self.model.metrics,
            loss_weights=self.model.compiled_loss._loss_weights,
            weighted_metrics=self.model.compiled_metrics._weighted_metrics,
            run_eagerly=self.model.run_eagerly,
        )

        clone = type(self)(model, self.nb_classes, self.input_shape)
        params = self.get_params()
        del params["model"]
        clone.set_params(**params)
        clone._train_step = self._train_step
        clone._reduce_labels = self._reduce_labels
        clone._loss_object = self._loss_object
        clone._optimizer = self._optimizer
        return clone

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

        :return: new estimator
        
art/estimators/classification/tensorflow.py