Fix Grad-CAM numpy() on tensor with grad (add detach)
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -146,7 +146,7 @@ class DINOv3GradCAM:
|
||||
# Denormalize from ImageNet stats.
|
||||
mean = torch.tensor([0.485, 0.456, 0.406]).view(3, 1, 1).to(image.device)
|
||||
std = torch.tensor([0.229, 0.224, 0.225]).view(3, 1, 1).to(image.device)
|
||||
img = (image * std + mean).clamp(0, 1).cpu().numpy().transpose(1, 2, 0) # [H, W, 3]
|
||||
img = (image * std + mean).clamp(0, 1).detach().cpu().numpy().transpose(1, 2, 0) # [H, W, 3]
|
||||
|
||||
# Resize heatmap to image size.
|
||||
heatmap_resized = torch.tensor(heatmap).unsqueeze(0).unsqueeze(0).float()
|
||||
|
||||
Reference in New Issue
Block a user