Exemple #1
0
    def on_epoch_end(self, epoch, logs: dict = None):
        self.loss.append(logs.get(METRIC_LOSS))
        self.accuracy.append(logs.get(METRIC_ACCURACY))
        self.val_loss.append(logs.get(METRIC_VAL_LOSS, 0))
        self.val_accuracy.append(logs.get(METRIC_VAL_ACCURACY, 0))

        if self.config.dp:
            # Account for tf-privacy library writing to stdout
            with redirect_stdout(io.StringIO()):
                eps, _ = compute_epsilon(self.total_token_count, self.config,
                                         epoch)
                logs[METRIC_EPSILON] = eps

            # NOTE: this is just a list of the same value, but
            # is simpler for creating the history csv
            delta = 1 / float(self.total_token_count)
            logs[METRIC_DELTA] = delta

        self.epsilon.append(logs.get(METRIC_EPSILON, 0))
        self.delta.append(logs.get(METRIC_DELTA, 0))

        # NOTE: When we do the final history saving, one of these items
        # will flip to 1 to denote the actual best model that is saved
        # This just seeds the column for now
        self.best.append(0)
    def on_epoch_end(self, epoch, logs: dict = None):
        self.loss.append(logs.get(METRIC_LOSS))
        self.accuracy.append(logs.get(METRIC_ACCURACY))
        self.val_loss.append(logs.get(METRIC_VAL_LOSS, 0))
        self.val_accuracy.append(logs.get(METRIC_VAL_ACCURACY, 0))

        if self.config.dp:
            # Account for tf-privacy library writing to stdout
            with redirect_stdout(io.StringIO()):
                eps, _ = compute_epsilon(self.total_token_count, self.config,
                                         epoch)
                self.epsilon.append(eps)

            # NOTE: this is just a list of the same value, but
            # is simpler for creating the history csv
            self.delta.append(1 / float(self.total_token_count))
        else:
            # Append 0,0 for epsilon and delta. These will be dropped afterwards anyway in
            # non-DP mode.
            self.epsilon.append(0)
            self.delta.append(0)

        # NOTE: When we do the final history saving, one of these items
        # will flip to 1 to denote the actual best model that is saved
        # This just seeds the column for now
        self.best.append(0)