Exemplo n.º 1
0
    def multi_test_epoch_end(self, outputs, dataloader_idx: int = 0):
        test_loss_mean = torch.stack([x['test_loss'] for x in outputs]).mean()
        correct_counts = torch.stack([x['test_correct_counts'].unsqueeze(0) for x in outputs])
        total_counts = torch.stack([x['test_total_counts'].unsqueeze(0) for x in outputs])

        topk_scores = compute_topk_accuracy(correct_counts, total_counts)

        tensorboard_log = {'test_loss': test_loss_mean}
        for top_k, score in zip(self._accuracy.top_k, topk_scores):
            tensorboard_log['test_epoch_top@{}'.format(top_k)] = score

        return {'log': tensorboard_log}
Exemplo n.º 2
0
    def multi_test_epoch_end(self, outputs, dataloader_idx: int = 0):
        self.val_loss_mean = torch.stack([x['test_loss']
                                          for x in outputs]).mean()
        correct_counts = torch.stack(
            [x['test_correct_counts'] for x in outputs])
        total_counts = torch.stack([x['test_total_counts'] for x in outputs])

        topk_scores = compute_topk_accuracy(correct_counts, total_counts)
        logging.info("test_loss: {:.3f}".format(self.val_loss_mean))
        tensorboard_log = {'test_loss': self.val_loss_mean}
        for top_k, score in zip(self._accuracy.top_k, topk_scores):
            tensorboard_log['test_epoch_top@{}'.format(top_k)] = score
            self.accuracy = score * 100

        return {'log': tensorboard_log}