MCPcopy
hub / github.com/TingsongYu/PyTorch_Tutorial / show_confMat

Function show_confMat

Code/utils/utils.py:112–138  ·  view source on GitHub ↗
(confusion_mat, classes, set_name, out_dir)

Source from the content-addressed store, hash-verified

110
111
112def 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
141def normalize_invert(tensor, mean, std):

Callers 2

main.pyFile · 0.90
2_finetune.pyFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected