Spaces:
Sleeping
Sleeping
Fix imports in cam
Browse files- app.py +2 -2
- src/custom_code/custom_grad_cam/ablation_cam.py +3 -3
- src/custom_code/custom_grad_cam/ablation_cam_multilayer.py +1 -1
- src/custom_code/custom_grad_cam/ablation_layer.py +1 -1
- src/custom_code/custom_grad_cam/base_cam.py +4 -4
- src/custom_code/custom_grad_cam/eigen_cam.py +2 -2
- src/custom_code/custom_grad_cam/eigen_grad_cam.py +2 -2
- src/custom_code/custom_grad_cam/feature_factorization/deep_feature_factorization.py +2 -2
- src/custom_code/custom_grad_cam/fullgrad_cam.py +4 -4
- src/custom_code/custom_grad_cam/grad_cam.py +1 -1
- src/custom_code/custom_grad_cam/grad_cam_elementwise.py +2 -2
- src/custom_code/custom_grad_cam/grad_cam_plusplus.py +1 -1
- src/custom_code/custom_grad_cam/guided_backprop.py +1 -1
- src/custom_code/custom_grad_cam/hirescam.py +2 -2
- src/custom_code/custom_grad_cam/layer_cam.py +2 -2
- src/custom_code/custom_grad_cam/metrics/cam_mult_image.py +1 -1
- src/custom_code/custom_grad_cam/metrics/road.py +1 -1
- src/custom_code/custom_grad_cam/random_cam.py +1 -1
- src/custom_code/custom_grad_cam/score_cam.py +1 -1
- src/custom_code/custom_grad_cam/xgrad_cam.py +1 -1
- src/results/infer_image.png +2 -2
app.py
CHANGED
@@ -21,8 +21,8 @@ from PIL import Image, ImageDraw, ImageFont
|
|
21 |
|
22 |
# from pytorch_grad_cam import GradCAM, HiResCAM, GradCAMPlusPlus, AblationCAM, XGradCAM, EigenCAM, FullGrad
|
23 |
from custom_code.custom_grad_cam import GradCAM, HiResCAM, GradCAMPlusPlus, AblationCAM, XGradCAM, EigenCAM, FullGrad
|
24 |
-
from
|
25 |
-
from
|
26 |
|
27 |
from tqdm import tqdm
|
28 |
from util import transform
|
|
|
21 |
|
22 |
# from pytorch_grad_cam import GradCAM, HiResCAM, GradCAMPlusPlus, AblationCAM, XGradCAM, EigenCAM, FullGrad
|
23 |
from custom_code.custom_grad_cam import GradCAM, HiResCAM, GradCAMPlusPlus, AblationCAM, XGradCAM, EigenCAM, FullGrad
|
24 |
+
from custom_code.custom_grad_cam.utils.model_targets import ClassifierOutputTarget
|
25 |
+
from custom_code.custom_grad_cam.utils.image import show_cam_on_image
|
26 |
|
27 |
from tqdm import tqdm
|
28 |
from util import transform
|
src/custom_code/custom_grad_cam/ablation_cam.py
CHANGED
@@ -2,9 +2,9 @@ import numpy as np
|
|
2 |
import torch
|
3 |
import tqdm
|
4 |
from typing import Callable, List
|
5 |
-
from
|
6 |
-
from
|
7 |
-
from
|
8 |
|
9 |
|
10 |
""" Implementation of AblationCAM
|
|
|
2 |
import torch
|
3 |
import tqdm
|
4 |
from typing import Callable, List
|
5 |
+
from custom_grad_cam.base_cam import BaseCAM
|
6 |
+
from custom_grad_cam.utils.find_layers import replace_layer_recursive
|
7 |
+
from custom_grad_cam.ablation_layer import AblationLayer
|
8 |
|
9 |
|
10 |
""" Implementation of AblationCAM
|
src/custom_code/custom_grad_cam/ablation_cam_multilayer.py
CHANGED
@@ -2,7 +2,7 @@ import cv2
|
|
2 |
import numpy as np
|
3 |
import torch
|
4 |
import tqdm
|
5 |
-
from
|
6 |
|
7 |
|
8 |
class AblationLayer(torch.nn.Module):
|
|
|
2 |
import numpy as np
|
3 |
import torch
|
4 |
import tqdm
|
5 |
+
from custom_grad_cam.base_cam import BaseCAM
|
6 |
|
7 |
|
8 |
class AblationLayer(torch.nn.Module):
|
src/custom_code/custom_grad_cam/ablation_layer.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
import torch
|
2 |
from collections import OrderedDict
|
3 |
import numpy as np
|
4 |
-
from
|
5 |
|
6 |
|
7 |
class AblationLayer(torch.nn.Module):
|
|
|
1 |
import torch
|
2 |
from collections import OrderedDict
|
3 |
import numpy as np
|
4 |
+
from custom_grad_cam.utils.svd_on_activations import get_2d_projection
|
5 |
|
6 |
|
7 |
class AblationLayer(torch.nn.Module):
|
src/custom_code/custom_grad_cam/base_cam.py
CHANGED
@@ -2,10 +2,10 @@ import numpy as np
|
|
2 |
import torch
|
3 |
import ttach as tta
|
4 |
from typing import Callable, List, Tuple
|
5 |
-
from
|
6 |
-
from
|
7 |
-
from
|
8 |
-
from
|
9 |
|
10 |
|
11 |
class BaseCAM:
|
|
|
2 |
import torch
|
3 |
import ttach as tta
|
4 |
from typing import Callable, List, Tuple
|
5 |
+
from custom_grad_cam.activations_and_gradients import ActivationsAndGradients
|
6 |
+
from custom_grad_cam.utils.svd_on_activations import get_2d_projection
|
7 |
+
from custom_grad_cam.utils.image import scale_cam_image
|
8 |
+
from custom_grad_cam.utils.model_targets import ClassifierOutputTarget
|
9 |
|
10 |
|
11 |
class BaseCAM:
|
src/custom_code/custom_grad_cam/eigen_cam.py
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
-
from
|
2 |
-
from
|
3 |
|
4 |
# https://arxiv.org/abs/2008.00299
|
5 |
|
|
|
1 |
+
from custom_grad_cam.base_cam import BaseCAM
|
2 |
+
from custom_grad_cam.utils.svd_on_activations import get_2d_projection
|
3 |
|
4 |
# https://arxiv.org/abs/2008.00299
|
5 |
|
src/custom_code/custom_grad_cam/eigen_grad_cam.py
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
-
from
|
2 |
-
from
|
3 |
|
4 |
# Like Eigen CAM: https://arxiv.org/abs/2008.00299
|
5 |
# But multiply the activations x gradients
|
|
|
1 |
+
from custom_grad_cam.base_cam import BaseCAM
|
2 |
+
from custom_grad_cam.utils.svd_on_activations import get_2d_projection
|
3 |
|
4 |
# Like Eigen CAM: https://arxiv.org/abs/2008.00299
|
5 |
# But multiply the activations x gradients
|
src/custom_code/custom_grad_cam/feature_factorization/deep_feature_factorization.py
CHANGED
@@ -3,8 +3,8 @@ from PIL import Image
|
|
3 |
import torch
|
4 |
from typing import Callable, List, Tuple, Optional
|
5 |
from sklearn.decomposition import NMF
|
6 |
-
from
|
7 |
-
from
|
8 |
|
9 |
|
10 |
def dff(activations: np.ndarray, n_components: int = 5):
|
|
|
3 |
import torch
|
4 |
from typing import Callable, List, Tuple, Optional
|
5 |
from sklearn.decomposition import NMF
|
6 |
+
from custom_grad_cam.activations_and_gradients import ActivationsAndGradients
|
7 |
+
from custom_grad_cam.utils.image import scale_cam_image, create_labels_legend, show_factorization_on_image
|
8 |
|
9 |
|
10 |
def dff(activations: np.ndarray, n_components: int = 5):
|
src/custom_code/custom_grad_cam/fullgrad_cam.py
CHANGED
@@ -1,9 +1,9 @@
|
|
1 |
import numpy as np
|
2 |
import torch
|
3 |
-
from
|
4 |
-
from
|
5 |
-
from
|
6 |
-
from
|
7 |
|
8 |
# https://arxiv.org/abs/1905.00780
|
9 |
|
|
|
1 |
import numpy as np
|
2 |
import torch
|
3 |
+
from custom_grad_cam.base_cam import BaseCAM
|
4 |
+
from custom_grad_cam.utils.find_layers import find_layer_predicate_recursive
|
5 |
+
from custom_grad_cam.utils.svd_on_activations import get_2d_projection
|
6 |
+
from custom_grad_cam.utils.image import scale_accross_batch_and_channels, scale_cam_image
|
7 |
|
8 |
# https://arxiv.org/abs/1905.00780
|
9 |
|
src/custom_code/custom_grad_cam/grad_cam.py
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
import numpy as np
|
2 |
-
from
|
3 |
|
4 |
|
5 |
class GradCAM(BaseCAM):
|
|
|
1 |
import numpy as np
|
2 |
+
from custom_grad_cam.base_cam import BaseCAM
|
3 |
|
4 |
|
5 |
class GradCAM(BaseCAM):
|
src/custom_code/custom_grad_cam/grad_cam_elementwise.py
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
import numpy as np
|
2 |
-
from
|
3 |
-
from
|
4 |
|
5 |
|
6 |
class GradCAMElementWise(BaseCAM):
|
|
|
1 |
import numpy as np
|
2 |
+
from custom_grad_cam.base_cam import BaseCAM
|
3 |
+
from custom_grad_cam.utils.svd_on_activations import get_2d_projection
|
4 |
|
5 |
|
6 |
class GradCAMElementWise(BaseCAM):
|
src/custom_code/custom_grad_cam/grad_cam_plusplus.py
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
import numpy as np
|
2 |
-
from
|
3 |
|
4 |
# https://arxiv.org/abs/1710.11063
|
5 |
|
|
|
1 |
import numpy as np
|
2 |
+
from custom_grad_cam.base_cam import BaseCAM
|
3 |
|
4 |
# https://arxiv.org/abs/1710.11063
|
5 |
|
src/custom_code/custom_grad_cam/guided_backprop.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
import numpy as np
|
2 |
import torch
|
3 |
from torch.autograd import Function
|
4 |
-
from
|
5 |
|
6 |
|
7 |
class GuidedBackpropReLU(Function):
|
|
|
1 |
import numpy as np
|
2 |
import torch
|
3 |
from torch.autograd import Function
|
4 |
+
from custom_grad_cam.utils.find_layers import replace_all_layer_type_recursive
|
5 |
|
6 |
|
7 |
class GuidedBackpropReLU(Function):
|
src/custom_code/custom_grad_cam/hirescam.py
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
import numpy as np
|
2 |
-
from
|
3 |
-
from
|
4 |
|
5 |
|
6 |
class HiResCAM(BaseCAM):
|
|
|
1 |
import numpy as np
|
2 |
+
from custom_grad_cam.base_cam import BaseCAM
|
3 |
+
from custom_grad_cam.utils.svd_on_activations import get_2d_projection
|
4 |
|
5 |
|
6 |
class HiResCAM(BaseCAM):
|
src/custom_code/custom_grad_cam/layer_cam.py
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
import numpy as np
|
2 |
-
from
|
3 |
-
from
|
4 |
|
5 |
# https://ieeexplore.ieee.org/document/9462463
|
6 |
|
|
|
1 |
import numpy as np
|
2 |
+
from custom_grad_cam.base_cam import BaseCAM
|
3 |
+
from custom_grad_cam.utils.svd_on_activations import get_2d_projection
|
4 |
|
5 |
# https://ieeexplore.ieee.org/document/9462463
|
6 |
|
src/custom_code/custom_grad_cam/metrics/cam_mult_image.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
import torch
|
2 |
import numpy as np
|
3 |
from typing import List, Callable
|
4 |
-
from
|
5 |
|
6 |
|
7 |
def multiply_tensor_with_cam(input_tensor: torch.Tensor,
|
|
|
1 |
import torch
|
2 |
import numpy as np
|
3 |
from typing import List, Callable
|
4 |
+
from custom_grad_cam.metrics.perturbation_confidence import PerturbationConfidenceMetric
|
5 |
|
6 |
|
7 |
def multiply_tensor_with_cam(input_tensor: torch.Tensor,
|
src/custom_code/custom_grad_cam/metrics/road.py
CHANGED
@@ -30,7 +30,7 @@ import numpy as np
|
|
30 |
from scipy.sparse import lil_matrix, csc_matrix
|
31 |
from scipy.sparse.linalg import spsolve
|
32 |
from typing import List, Callable
|
33 |
-
from
|
34 |
AveragerAcrossThresholds, \
|
35 |
RemoveMostRelevantFirst, \
|
36 |
RemoveLeastRelevantFirst
|
|
|
30 |
from scipy.sparse import lil_matrix, csc_matrix
|
31 |
from scipy.sparse.linalg import spsolve
|
32 |
from typing import List, Callable
|
33 |
+
from custom_grad_cam.metrics.perturbation_confidence import PerturbationConfidenceMetric, \
|
34 |
AveragerAcrossThresholds, \
|
35 |
RemoveMostRelevantFirst, \
|
36 |
RemoveLeastRelevantFirst
|
src/custom_code/custom_grad_cam/random_cam.py
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
import numpy as np
|
2 |
-
from
|
3 |
|
4 |
|
5 |
class RandomCAM(BaseCAM):
|
|
|
1 |
import numpy as np
|
2 |
+
from custom_grad_cam.base_cam import BaseCAM
|
3 |
|
4 |
|
5 |
class RandomCAM(BaseCAM):
|
src/custom_code/custom_grad_cam/score_cam.py
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
import torch
|
2 |
import tqdm
|
3 |
-
from
|
4 |
|
5 |
|
6 |
class ScoreCAM(BaseCAM):
|
|
|
1 |
import torch
|
2 |
import tqdm
|
3 |
+
from custom_grad_cam.base_cam import BaseCAM
|
4 |
|
5 |
|
6 |
class ScoreCAM(BaseCAM):
|
src/custom_code/custom_grad_cam/xgrad_cam.py
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
import numpy as np
|
2 |
-
from
|
3 |
|
4 |
|
5 |
class XGradCAM(BaseCAM):
|
|
|
1 |
import numpy as np
|
2 |
+
from custom_grad_cam.base_cam import BaseCAM
|
3 |
|
4 |
|
5 |
class XGradCAM(BaseCAM):
|
src/results/infer_image.png
CHANGED
![]() |
Git LFS Details
|
![]() |
Git LFS Details
|