import cv2
import numpy as np
def norm_image(image):
"""
Normalization image
:param image: [H,W,C]
:return:
"""
image = image.copy()
image -= np.max(np.min(image), 0)
image /= np.max(image)
image *= 255.
return np.uint8(image)
def visualize_heatmap(image, mask):
'''
Save the heatmap of ones
'''
masks = norm_image(mask).astype(np.uint8)
# mask->heatmap
heatmap = cv2.applyColorMap(masks, cv2.COLORMAP_JET)
heatmap = np.float32(heatmap)
heatmap = cv2.resize(heatmap, (image.shape[1], image.shape[0])) # same shape
# merge heatmap to original image
cam = 0.4*heatmap + 0.6*np.float32(image)
return cam
注意力机制中生成的类似热力图或者柱状图是如何生成的?计算出attention map后,如何将其可视化?
最新推荐文章于 2024-08-13 18:41:26 发布