(confusion_mat, classes, set_name, out_dir)
| 110 | |
| 111 | |
| 112 | def show_confMat(confusion_mat, classes, set_name, out_dir): |
| 113 | |
| 114 | # 归一化 |
| 115 | confusion_mat_N = confusion_mat.copy() |
| 116 | for i in range(len(classes)): |
| 117 | confusion_mat_N[i, :] = confusion_mat[i, :] / confusion_mat[i, :].sum() |
| 118 | |
| 119 | # 获取颜色 |
| 120 | cmap = plt.cm.get_cmap('Greys') # 更多颜色: http://matplotlib.org/examples/color/colormaps_reference.html |
| 121 | plt.imshow(confusion_mat_N, cmap=cmap) |
| 122 | plt.colorbar() |
| 123 | |
| 124 | # 设置文字 |
| 125 | xlocations = np.array(range(len(classes))) |
| 126 | plt.xticks(xlocations, list(classes), rotation=60) |
| 127 | plt.yticks(xlocations, list(classes)) |
| 128 | plt.xlabel('Predict label') |
| 129 | plt.ylabel('True label') |
| 130 | plt.title('Confusion_Matrix_' + set_name) |
| 131 | |
| 132 | # 打印数字 |
| 133 | for i in range(confusion_mat_N.shape[0]): |
| 134 | for j in range(confusion_mat_N.shape[1]): |
| 135 | plt.text(x=j, y=i, s=int(confusion_mat[i, j]), va='center', ha='center', color='red', fontsize=10) |
| 136 | # 保存 |
| 137 | plt.savefig(os.path.join(out_dir, 'Confusion_Matrix' + set_name + '.png')) |
| 138 | plt.close() |
| 139 | |
| 140 | |
| 141 | def normalize_invert(tensor, mean, std): |
no outgoing calls
no test coverage detected