import cv2
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
# x = gap
for i in range(x.shape[1]):
# # 方法1
# ax = sns.heatmap(x[0][i].cpu().numpy())
# # plt.show()
# plt.close()
# figure = ax.get_figure()
# figure.savefig(r'C:\Users\kah\Desktop\DAM\sns_heatmap_{}.png'.format(i))
# 方法二
ax = cv2.applyColorMap(x[0][i].cpu().numpy().astype(np.uint8), cv2.COLORMAP_JET) #生成heat map
# ax = ax[:, :, ::-1] # 注意cv2(BGR)和matplotlib(RGB)通道是相反的
plt.imshow(ax)
cv2.imwrite(r'C:\Users\kah\Desktop\DAM\sns_heatmap_{}.png'.format(i), ax)
# ax.savefig(r'C:\Users\kah\Desktop\DAM\sns_heatmap_{}.png'.format(i))