Closed jnsgnstr closed 2 years ago
Hi, Looks like we need to define a custom reshape_transform.
def yolo4_reshape_transform(outputs):
return outputs[0]
and pass it to the reshape_transform argument.
The result would be the same as what you did, but this is the "correct" way of doing it.
For grad-cam, it's a different story. Usually YOLO doesn't really expose gradients. You would need to use a custom target. Is there some tensor that represents the bounding box you want to taget? Does the yolo model you're doing support doing back-propagation on one of the bounding box objects? To get an idea you could look at the example for faster-rcnn, this would need adapting: https://github.com/jacobgil/pytorch-grad-cam/blob/master/pytorch_grad_cam/utils/model_targets.py#L69
Hi, thanks for the fast answer. I try to implement a custom target for YOLOV4-tiny.
EigenCAM: I wanted to use some of the CAMs with the YOLOV4-tiny model. However,
pytorch-grad-cam/base_cam.py
(line 76) outputs a list and has no attribute.cpu()
. The error is fixed by replacingoutputs
withoutputs[0]
. But this is not an elegant solution. I implemented everything as described in the YOLOV5-EigenCAM notebook.Additionally to EigenCAM I wanted to use GradCAM and its derivatives. After running the same code, but with GradCAM, the following error occured in
pytorch-grad-cam/base_cam.py
(line 82):RuntimeError: grad can be implicitly created only for scalar outputs
As for the first problem, a quick fix is done by replacing
target(output)
withtarget(output).sum()
.As target I use
ClassifierOutputTarget
.Are those fixes okay or do they distort the results?