MECLabTUDA / M3d-Cam

MIT License
306 stars 40 forks source link

You really need to improve your documentation #10

Closed jenridunn closed 3 years ago

jenridunn commented 3 years ago

Thanks for all your effort. But it's kind of annoying not to understand how for example get only the attention map as a tensor or something i can work with that's not an image saved always in the attention_maps folder that your code generates by default. Thanks.

Karol-G commented 3 years ago

Hi,

you can use one of the two:

# Use parameter 'replace' to get the attention instead of the prediction
model = medcam.inject(model, output_dir="attention_maps", save_maps=False, replace=True)
...
attention_map= model(input)

Or:

# Use parameter 'return_attention' to get the prediction and the attention
model = medcam.inject(model, output_dir="attention_maps", save_maps=False, return_attention=True)
...
prediction, attention_map = model(input)

I hope I was able to help :)

Best Karol

jenridunn commented 3 years ago

Thank you for your answer. Now the issue is, when I get the attention_map, it comes with one channel (grayscale - torch.Size([1, 1, 300, 300])) not RGB (3 channels) what can I do to get the attention_map as an RGB tensor (I already tried to convert the tensor to RGB using PIL (.convert("RGB")), but it didn't work. Thanks!

jenridunn commented 3 years ago

Well I've solved the one channel issue squeezing the tensor two times and then converting this tensor to a numpy array. After checking your code I saw that you use cm.get_cmap('jet') from matplotlib to get the colors for the heatmap so I applied this to my numpy array and now I've got the correct colors I need. Thanks for your help, but I kindly insist, improve your documentation, please. Have a nice day!