1.画某层所有feature maps求和后的热力图
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | # 1.1 获取feature maps features = ... # 尺度大小,如:torch.Size([1,80,45,45]) # 1.2 每个通道对应元素求和 heatmap = torch.sum(features, dim=1) # 尺度大小, 如torch.Size([1,45,45]) max_value = torch.max(heatmap) min_value = torch.min(heatmap) heatmap = (heatmap-min_value)/(max_value-min_value)*255 heatmap = heatmap.cpu().numpy().astype(np.uint8).transpose(1,2,0) # 尺寸大小,如:(45, 45, 1) src_size = (125,125) # 原图尺寸大小 heatmap = cv2.resize(heatmap, src_size,interpolation=cv2.INTER_LINEAR) # 重整图片到原尺寸 heatmap=cv2.applyColorMap(heatmap,cv2.COLORMAP_JET) # 保存热力图 cv2.imshow('heatmap',heatmap) cv2.imwrite('heapmap_rand.jpg', heatmap) cv2.waitKey(0) cv2.destroyAllWindows() |
2. 画某层某个feature map热力图
1 | On the road |