【问题标题】:How to plot the actual numbers of the confusion matrix along with the color while using tensorboard to view them?如何在使用张量板查看混淆矩阵的同时绘制混淆矩阵的实际数字和颜色?
【发布时间】:2021-05-15 07:25:35
【问题描述】:

我正在运行这个 Github 上提供的代码 - https://github.com/arthurdouillard/CVPR2021_PLOP/blob/381cb795d70ba8431d864e4b60bb84784bc85ec9/metrics/stream_metrics.py

现在我可以查看颜色变化的混淆矩阵,但看不到实际数字。您建议进行哪些更改以在可视化上显示这些数字?

【问题讨论】:

标签: tensorflow matplotlib tensorboardx


【解决方案1】:

您可以将confusion_matrix_to_fig 更改为:

import itertools

def confusion_matrix_to_fig(self):
    cm = self.confusion_matrix.astype('float') / (self.confusion_matrix.sum(axis=1) +
                                                  0.000001)[:, np.newaxis]
    fig, ax = plt.subplots()
    im = ax.imshow(cm, interpolation='nearest', cmap=plt.cm.Blues)
    ax.figure.colorbar(im, ax=ax)

    ax.set(title=f'Confusion Matrix', ylabel='True label', xlabel='Predicted label')

    # Adding text to cm
    thresh = cm.max() / 1.5  # Thresh is used to decide color of text (white or black)
    for i, j in itertools.product(range(cm.shape[0]), range(cm.shape[1])):
        ax.text(j, i, "{:0.4f}".format(cm[i, j]),
                  horizontalalignment="center",
                  color="white" if cm[i, j] > thresh else "black")

    fig.tight_layout()
    return fig

您可能已经注意到,这将绘制混淆矩阵的归一化值。

查看this notebook了解更多信息。

【讨论】:

  • @RamMohan 很高兴我能提供帮助。随意接受它作为答案,也可以帮助其他开发人员。
猜你喜欢
  • 2016-01-31
  • 2022-01-02
  • 1970-01-01
  • 2016-06-04
  • 1970-01-01
  • 2015-07-07
  • 1970-01-01
  • 2021-07-21
相关资源
最近更新 更多