From 3f4528e3bddf04282d0a382daead4b2b093f148c Mon Sep 17 00:00:00 2001 From: Nalini Singh Date: Sun, 19 Aug 2018 14:00:37 -0700 Subject: [PATCH] Initialize GradCAM mask summation with zeros. From my read of the GradCAM paper, this matrix should be initialized with zeroes, so that cam contains only the weighted sum of the entries in outputs. Feel free to correct me here if I'm misinterpreting anything! [This doesn't affect the qualitative trend you see across the image in any of the generated GradCAM masks, since this is a constant shift at each pixel, but it does slightly perturb some of the numeric values.] --- grad-cam.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/grad-cam.py b/grad-cam.py index a175db7..0a824e3 100644 --- a/grad-cam.py +++ b/grad-cam.py @@ -103,7 +103,7 @@ def grad_cam(input_model, image, category_index, layer_name): output, grads_val = output[0, :], grads_val[0, :, :, :] weights = np.mean(grads_val, axis = (0, 1)) - cam = np.ones(output.shape[0 : 2], dtype = np.float32) + cam = np.zeros(output.shape[0 : 2], dtype = np.float32) for i, w in enumerate(weights): cam += w * output[:, :, i]