forked from huawei/mindspore2022
Avoid zero devision, fix faithfulness deletion bug
This commit is contained in:
parent
7f731faa9b
commit
8d2f42e244
|
|
@ -233,7 +233,6 @@ def calc_auc(x: _Array) -> _Array:
|
|||
# take mean for multiple patches if the model is fully convolutional model
|
||||
if len(x.shape) == 4:
|
||||
x = np.mean(np.mean(x, axis=2), axis=3)
|
||||
|
||||
auc = (x.sum() - x[0] - x[-1]) / len(x)
|
||||
return auc
|
||||
|
||||
|
|
|
|||
|
|
@ -164,7 +164,7 @@ class AblationWithSaliency(Ablation):
|
|||
up_bound = low_bound + pixel_per_step
|
||||
for j in range(num_perturbations):
|
||||
masks[i, j, :, ((saliency_rank[i] >= low_bound) & (saliency_rank[i] < up_bound))] = True
|
||||
low_bound = up_bound + factor
|
||||
low_bound = up_bound * factor
|
||||
up_bound += pixel_per_step
|
||||
|
||||
masks = masks if has_channel else np.squeeze(masks, axis=2)
|
||||
|
|
@ -178,6 +178,9 @@ class AblationWithSaliency(Ablation):
|
|||
if self._pixel_per_step:
|
||||
pixel_per_step = self._pixel_per_step
|
||||
num_perturbations = math.floor(num_pixels * self._perturb_percent / self._pixel_per_step)
|
||||
if not num_perturbations:
|
||||
raise ValueError("Number of perturbations is not valid. Please enlarge the value of perturb_percent or "
|
||||
"reduce the value of pixel_per_step when instantiating AblationWithSaliency.")
|
||||
elif self._num_perturbations:
|
||||
pixel_per_step = math.floor(num_pixels * self._perturb_percent / self._num_perturbations)
|
||||
num_perturbations = self._num_perturbations
|
||||
|
|
|
|||
Loading…
Reference in New Issue