utkuozbulak / pytorch-cnn-visualizations

Pytorch implementation of convolutional neural network visualization techniques
MIT License
7.81k stars 1.49k forks source link

Class correctness in gradcam.py #85

Closed AND2797 closed 4 years ago

AND2797 commented 4 years ago

There is a line in gradcam.py which says that if target_class = None then the target_class takes the argmax of the ouptut. Is it possible that the actual class might be different from the expected class?

utkuozbulak commented 4 years ago

If it is a misclassification and the true class is not provided, yeah.

AND2797 commented 4 years ago

So in this case would it be appropriate to raise an assertion error? For eg: I input class 5, but the model output indicates that the image is classified as class 4, which would be incorrect

utkuozbulak commented 4 years ago

If you enter a target class then target class would not be None.

AND2797 commented 4 years ago

No what I mean is this ->

  1. User enters target_class = 5, and image corresponding to target_class = 5.
  2. Output of torch.argmax(model_output).item() is not 5, then in this case it means that the model has incorrectly classified the image, so will it not give incorrect results?
utkuozbulak commented 4 years ago

If the user enters target_class = 5, then the target_class is not None and what is inside the if condition will not be executed.

AND2797 commented 4 years ago

I am a little confused, can you explain what happens if the true class is given and a mis-classification occurs?

utkuozbulak commented 4 years ago

Please read the code. If the target_class is not provided, it is taken from the prediction. When the target_class is provided, what comes out of the prediction is not used. So, there is no case when the user provides a class (e.g., 5) and the target_class magically changes to 44.

AND2797 commented 4 years ago

Thanks for the clarification.