Giter Club home page Giter Club logo

Comments (5)

zhangzw12319 avatar zhangzw12319 commented on June 3, 2024 1

from torch-cam.

frgfm avatar frgfm commented on June 3, 2024

Hello @Ethan-Chen-plus 👋

Thanks for reporting this!
I just investigated and here is what happened:

  • in order to save memory for users, I started removing unnecessary gradient computation in scripts
  • now this library uses pytorch hooks, and some hooks (including the ones I use to store gradients) throw errors if the output tensor doesn't have requires_grad set to True
  • so far so good, because for each input tensor I set its requires_grad to True (we avoid the grad computation for each model's parameter that way, which can save a lot of memory depending on the model size)
  • however, after investigating your problem, I realized the script was failing on SmoothGradCAMpp which is a bit specific. It creates a noisy input that will be forwarded into the model. And I had forgotten to set the grad computation there (until now, it couldn't crash because everything else was requiring gradient so the hook couldn't crash)

As this is pretty simple to fix, I just opened a PR (#204) to address this! This should be solved on the "main" branch within a few minutes :)

Let me know if you have any questions!

from torch-cam.

Ethan-Chen-plus avatar Ethan-Chen-plus commented on June 3, 2024

Good! Thank you for solving this!

from torch-cam.

zhangzw12319 avatar zhangzw12319 commented on June 3, 2024

Thank you for solving this problem!
However in current version(2023-02-05), this bug is not fixed in current main branch, and thus I've spent several hours debugging until coming across this issue. Therefore it is recommended that this small bug be fixed as soon as possible to help new rookies to save time. THX a lot.

from torch-cam.

frgfm avatar frgfm commented on June 3, 2024

Hi @zhangzw12319 👋

What do you mean?
About the specific bug mentioned in this very issue, I merged the PR fixing it 3 weeks ago and I just tried again the exact same snippet, it works correctly 🤔
Perhaps it's because you're using the last published version of the library? Does the problem persist if you install it in developer mode first?

git clone https://github.com/frgfm/torch-cam.git
pip install -e torch-cam/.

If you're referring to another bug or another snippet, this might be unrelated and in this case, feel free to open another issue :)

from torch-cam.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.