incubator-mxnet\example\cnn_visualization\gradcam.py有个bug

在我运行这个demo的时候发现这里面获取cam的算法和参考论文中的不一样。论文中卷积层输出乘卷积层梯度的平均值。但是这个代码中卷积层输出乘图片梯度的平均值了。
应该修改这两个方法

def get_cam(conv_out_grad, conv_out):
"""Compute CAM. Refer section 3 of https://arxiv.org/abs/1610.02391 for details"""
weights = np.mean(conv_out_grad, axis=(1, 2))
cam = np.ones(conv_out.shape[1:], dtype=np.float32)
for i, w in enumerate(weights):
    cam += w * conv_out[i, :, :]
cam = np.maximum(cam, 0)
cam = (cam - np.min(cam)) / (np.max(cam) - np.min(cam)) 
cam = np.uint8(cam * 255)
return cam

def visualize(net, preprocessed_img, orig_img, conv_layer_name):
# Returns grad-cam heatmap, guided grad-cam, guided grad-cam saliency
imggrad = get_image_grad(net, preprocessed_img)
conv_out, conv_out_grad = get_conv_out_grad(net, preprocessed_img, conv_layer_name=conv_layer_name)

cam = get_cam(conv_out_grad, conv_out)
cam = cv2.resize(cam, (imggrad.shape[1], imggrad.shape[2]))

ggcam = get_guided_grad_cam(cam, imggrad)
img_ggcam = grad_to_image(ggcam)

img_heatmap = get_img_heatmap(orig_img, cam)

ggcam_gray = to_grayscale(ggcam)
img_ggcam_gray = np.squeeze(grad_to_image(ggcam_gray))

return img_heatmap, img_ggcam, img_ggcam_gray