jacobgil / pytorch-grad-cam

Advanced AI Explainability for computer vision. Support for CNNs, Vision Transformers, Classification, Object detection, Segmentation, Image similarity and more.
https://jacobgil.github.io/pytorch-gradcam-book
MIT License
10.29k stars 1.54k forks source link

Bug: use_cuda still exist in swin transformer example code #504

Closed chilin0525 closed 1 month ago

chilin0525 commented 4 months ago

Hi,

I found model parameter use_cuda already removed in the commit: 00711a20b7a8dfb6d6d1d892216997daeeee6288, but in usage_examples/swinT_example.py still use use_cuda. So the user may got error when running the example code.

Steps to Reproduce:

$ python3 usage_examples/swinT_example.py

Using CPU for computation
Exception ignored in: <function BaseCAM.__del__ at 0x7fa71550f820>
Traceback (most recent call last):
  File "/home/chilin/.pyenv/versions/pytorch_grad_cam/lib/python3.9/site-packages/pytorch_grad_cam/base_cam.py", line 196, in __del__
    self.activations_and_grads.release()
AttributeError: 'ScoreCAM' object has no attribute 'activations_and_grads'
Traceback (most recent call last):
  File "/home/chilin/pytorch-grad-cam/usage_examples/swinT_example.py", line 104, in <module>
    cam = methods[args.method](model=model,
TypeError: __init__() got an unexpected keyword argument 'use_cuda'

The code execute successfully after removing the parameter, I will create a MR to fix it ! Just leave the issue for someone confused about the error.

wap1024 commented 3 months ago

Hello, may I ask how to modify it?

chilin0525 commented 3 months ago

@wap1024 sure, I already create a MR(#505) to fix it. You can see change in MR how to fix it, remove use_cuda of model interface should work

jacobgil commented 1 month ago

This MR was merged. Thank you!