Skip to content

Commit

Permalink
metrics: plug the new operator function for fidelity
Browse files Browse the repository at this point in the history
  • Loading branch information
fel-thomas committed Feb 2, 2023
1 parent 0d9d337 commit c3ef138
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions xplique/metrics/fidelity.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from scipy.stats import spearmanr

from .base import ExplanationMetric
from ..commons import batch_predictions_one_hot
from ..commons import batch_predictions
from ..types import Union, Callable, Optional, Dict


Expand Down Expand Up @@ -83,8 +83,8 @@ def __init__(self,
(self.nb_samples, self.grid_size, self.grid_size, 1))
self.subset_masks = tf.image.resize(subset_masks, inputs.shape[1:-1], method="nearest")

self.base_predictions = batch_predictions_one_hot(self.model, inputs,
targets, self.batch_size)
self.base_predictions = batch_predictions(self.model, inputs,
targets, self.batch_size)

def evaluate(self,
explanations: Union[tf.Tensor, np.ndarray]) -> float:
Expand Down Expand Up @@ -117,8 +117,8 @@ def evaluate(self,
# use the masks to set the selected subsets to baseline state
degraded_inputs = inp * self.subset_masks + (1.0 - self.subset_masks) * baseline
# measure the two terms that should be correlated
preds = base - batch_predictions_one_hot(self.model, degraded_inputs,
label, self.batch_size)
preds = base - batch_predictions(self.model, degraded_inputs,
label, self.batch_size)

attrs = tf.reduce_sum(phi * (1.0 - self.subset_masks), (1, 2, 3))
corr_score = spearmanr(preds, attrs)[0]
Expand Down Expand Up @@ -276,8 +276,8 @@ def detailed_evaluate(self,

batch_inputs = batch_inputs.reshape((-1, *self.inputs.shape[1:]))

predictions = batch_predictions_one_hot(self.model, batch_inputs,
self.targets, self.batch_size)
predictions = batch_predictions(self.model, batch_inputs,
self.targets, self.batch_size)

scores_dict[step] = np.mean(predictions)

Expand Down

0 comments on commit c3ef138

Please sign in to comment.