Comments (5)
from torch-cam.
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 toTrue
- so far so good, because for each input tensor I set its
requires_grad
toTrue
(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.
Good! Thank you for solving this!
from torch-cam.
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.
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)
- VGG16 can't assist with plain CAM? HOT 2
- IS-CAM formula error? HOT 4
- Error when clearing hooks HOT 1
- self._normalize() got NAN... HOT 7
- What is class_idx in __call__() ?? HOT 6
- What are the requirements of the model by using these visual code? HOT 10
- [demo] Automate deployment to HF Spaces
- Upcoming support for new CAM methods
- Release tracker - v0.5.0
- More NaNs HOT 7
- didn't find remove_hooks() in cam_extractor HOT 2
- RuntimeError: 'cannot register a hook on a tensor that doesn't require gradient' HOT 7
- Remove hooks once we're done with CAM extractors
- target_layer path error HOT 3
- Does torch-cam still support 3D resnet model? HOT 3
- SmoothGradCAMpp returning GRAD CAM with NANs for some images, not all HOT 3
- How to get CAM for custom 3D model? HOT 19
- RuntimeError: cannot register a hook on a tensor that doesn't require gradient HOT 1
- No difference between GradCAM and XGradCAM HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from torch-cam.