1、RuntimeError: Trying to backward through the graph a second time (or directly access saved tensors after they have already been freed). Saved intermediate values of the graph are freed when you call .backward() or autograd.grad(). Specify retain_graph=True if you need to backward through the graph a second time or if you need to access saved tensors after calling backward.
对于某个backward或者grad调用了两次,需要仔细检查才能发现。
2、RuntimeError: cannot register a hook on a tensor that doesn’t require gradient
我修改了一下cam_example.py
https://github.com/frgfm/torch-cam/discussions/132
https://github.com/frgfm/torch-cam/issues/202
https://github.com/frgfm/torch-cam/pull/204/files