Only Variables are tracked, so you want to wrap it once.
img_tensor = transforms.Compose(...)(numpy_img.transpose(1,2,0))
img_tensor = Variable(img_tensor.cuda(),requires_grad=True)
out = densenet(img_tensor)
out = out.view(-1)
grads = grad(out[1],img_tensor)

or somesuch.
Best regards
Thomas