Skip to content

Commit

Permalink
Adding Attack Comparator Metric (pytorch#699)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: pytorch#699

Add Attack Comparator metric as a robustness metrics to work with Captum perturbations as well as arbitrary transformations such as torchvision transforms.

Also adds support for summarizers / metrics to take floats as well as tensors.

Differential Revision: D29122998

fbshipit-source-id: f652e52dc373f248030cf97915b3f02f8f2ae55e
  • Loading branch information
vivekmig authored and facebook-github-bot committed Jul 1, 2021
1 parent d5ac614 commit 18936f8
Show file tree
Hide file tree
Showing 5 changed files with 675 additions and 0 deletions.
3 changes: 3 additions & 0 deletions captum/attr/_utils/summarizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from typing import Dict, List, Optional, Tuple, Type, Union

import torch
from torch import Tensor

from captum.attr._utils.stat import MSE, Count, Max, Mean, Min, Stat, StdDev, Sum, Var
Expand Down Expand Up @@ -76,6 +77,8 @@ def update(self, x: Union[Tensor, Tuple[Tensor, ...]]):
stats=stats, summary_stats_indices=self._summary_stats_indicies
)
)
if not isinstance(inp, torch.Tensor):
inp = torch.tensor(inp, dtype=torch.float)
self._summarizers[i].update(inp)

@property
Expand Down
1 change: 1 addition & 0 deletions captum/robust/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python3

from captum.robust._core.fgsm import FGSM # noqa
from captum.robust._core.metrics.attack_comparator import AttackComparator # noqa
from captum.robust._core.perturbation import Perturbation # noqa
from captum.robust._core.pgd import PGD # noqa
Loading

0 comments on commit 18936f8

Please sign in to comment.