Combine Acktr model with grad-cam
Opened this issue · 2 comments
I am new on this code, My question is that if i want to get the grad on the CNN layer by using register_backward_hook function. Should I remove the code "with torch.no_grad():" when training this model?
I modify the other grad-cam code but still get bug when I call "register_backward_hook" function.
Is there any one can help me or any example?
My English is not good, Thank u!
but code didnt get in this function
on the enjoy script , if I remove the code "with torch.no_grad():" that it gives me the bug:
Traceback (most recent call last):
File "enjoy.py", line 139, in
cam = gcam(state,recurrent_hidden_states,masks)
File "/media/seed/C2C6AED6C6AEC9CD/AirSim/PythonClient/multirotor/pytorch-a2c-ppo-acktr-gail/pure_code/pytorch-a2c-ppo-acktr-gail/grad_cam_pp.py", line 123, in call
output, _, index, , = self.net.act_test(inputs, h_0, c_0,deterministic = True) # [1,num_classes]
File "/media/seed/C2C6AED6C6AEC9CD/AirSim/PythonClient/multirotor/pytorch-a2c-ppo-acktr-gail/pure_code/pytorch-a2c-ppo-acktr-gail/a2c_ppo_acktr/model.py", line 55, in act_test
value, actor_features, rnn_hxs = self.base(inputs, rnn_hxs, masks)
File "/home/seed/.local/lib/python3.6/site-packages/torch/nn/modules/module.py", line 722, in _call_impl
result = self.forward(*input, **kwargs)
File "/media/seed/C2C6AED6C6AEC9CD/AirSim/PythonClient/multirotor/pytorch-a2c-ppo-acktr-gail/pure_code/pytorch-a2c-ppo-acktr-gail/a2c_ppo_acktr/model.py", line 207, in forward
x = self.main(inputs / 255.0)
File "/home/seed/.local/lib/python3.6/site-packages/torch/nn/modules/module.py", line 722, in _call_impl
result = self.forward(*input, **kwargs)
File "/home/seed/.local/lib/python3.6/site-packages/torch/nn/modules/container.py", line 117, in forward
input = module(input)
File "/home/seed/.local/lib/python3.6/site-packages/torch/nn/modules/module.py", line 722, in _call_impl
result = self.forward(*input, **kwargs)
File "/media/seed/C2C6AED6C6AEC9CD/AirSim/PythonClient/multirotor/pytorch-a2c-ppo-acktr-gail/pure_code/pytorch-a2c-ppo-acktr-gail/a2c_ppo_acktr/algo/kfac.py", line 82, in forward
x = self.module(input)
File "/home/seed/.local/lib/python3.6/site-packages/torch/nn/modules/module.py", line 714, in _call_impl
result = hook(self, input)
File "/media/seed/C2C6AED6C6AEC9CD/AirSim/PythonClient/multirotor/pytorch-a2c-ppo-acktr-gail/pure_code/pytorch-a2c-ppo-acktr-gail/a2c_ppo_acktr/algo/kfac.py", line 144, in _save_input
if torch.is_grad_enabled() and self.steps % self.Ts == 0:
AttributeError: 'KFACOptimizer' object has no attribute 'steps'
can anyone help me? Thank u so much.
@ikostrikov Need ur help. I stuck on this for a long time.
did you solve this?