You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
/tmp/ipykernel_1145163/286742431.py in <module>
1 ## First is the data, second is the index of the predicted bbox
----> 2 mask, box, class_id = grad_cam(data, 0)
/tmp/ipykernel_1145163/2352451777.py in __call__(self, data, index)
54 score = res[0][0][index]
55
---> 56 score.backward()
57
58 gradient = self.gradient.cpu().data.numpy() # [C,H,W]
~/anaconda3/envs/open-mmlab3/lib/python3.7/site-packages/torch/_tensor.py in backward(self, gradient, retain_graph, create_graph, inputs)
394 create_graph=create_graph,
395 inputs=inputs)
--> 396 torch.autograd.backward(self, gradient, retain_graph, create_graph, inputs=inputs)
397
398 def register_hook(self, hook):
~/anaconda3/envs/open-mmlab3/lib/python3.7/site-packages/torch/autograd/__init__.py in backward(tensors, grad_tensors, retain_graph, create_graph, grad_variables, inputs)
173 Variable._execution_engine.run_backward( # Calls into the C++ engine to run the backward pass
174 tensors, grad_tensors_, retain_graph, create_graph, inputs,
--> 175 allow_unreachable=True, accumulate_grad=True) # Calls into the C++ engine to run the backward pass
176
177 def grad(
RuntimeError: element 0 of tensors does not require grad and does not have a grad_fn
你好,在使用
gradcam-yolov3
时报错:RuntimeError: element 0 of tensors does not require grad and does not have a grad_fn
使用的模型和权重是自己在
mmdetection
中训练的,可用在gradcam-yolov3
中正确画出框并输出结果。但是在使用GradCAM_YOLOV3
函数时出现梯度的错误。在该文件定义时使用到self.net.eval()
,去掉后依旧没有梯度,请问可以解决嘛?The text was updated successfully, but these errors were encountered: