I missed the line causing the bug. Check it Link 21
from torchvision.models import densenet121
model = densenet121(pretrained=True).eval()
img = read_image("image.png")
input_tensor = normalize(resize(img, (224, 224)) / 255., [0.485, 0.456, 0.406], [0.229, 0.224, 0.225])
extract = _Grad(model=model,target_layer="features")
out = model(input_tensor.unsqueeze(0))

I am implementing the Grad-cam Link 7  for visual explanations of classification models. Given the target-layer, I want extract the activations during forward pass and gradients during backward pass for it.
torch version: 1.8.1+cu101