jacobgil / keras-grad-cam

An implementation of Grad-CAM with keras
MIT License
657 stars 237 forks source link

Requesting help with GradCam on Segmentation #36

Open varungupta31 opened 2 years ago

varungupta31 commented 2 years ago

@jacobgil Thank you for this repository. I am trying to implement this in my keras trained segmentation model (FCN8+VGG19). I have referenced the Segmentation Notebook from your gradcam repo for pytroch, where you have created a wrapper, as pytorch model was returning a dictionary rather than a tensor. However, with Keras, I loaded my model, pre-processed and fed the input image, and ran model.predict(), I get a tensor which is basically of the shape of input image and has values depending on the category (in my case 0 and 1).

I'm having issues proceeding from here. This repo does:

top_1 = decode_predictions(predictions)[0][0]
print('Predicted class:')
print('%s (%s) with probability %.2f' % (top_1[1], top_1[0], top_1[2]))

predicted_class = np.argmax(predictions)
cam, heatmap = grad_cam(model, preprocessed_input, predicted_class, "block5_conv3")

So it's basically picking up a category, and calculating gradients. What should I do in my case?

Kindly help me out, Thank you.