Skip to content

Commit

Permalink
fix: transform normalize params name
Browse files Browse the repository at this point in the history
  • Loading branch information
spencerwooo committed Jan 20, 2024
1 parent a9d1d57 commit 3a85a1e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/torchattack/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def __init__(
batch_size: int = 1,
shuffle: bool = False,
num_workers: int = 4,
normalize: Callable[[torch.Tensor], torch.Tensor] | None = None,
transform: Callable[[torch.Tensor], torch.Tensor] | None = None,
max_samples: int | None = None,
):
# Specifing a custom image root directory is useful when evaluating
Expand All @@ -117,7 +117,7 @@ def __init__(
dataset=NIPSDataset(
image_root=image_root if image_root else f'{path}/images',
pairs_path=pairs_path if pairs_path else f'{path}/images.csv',
transform=normalize,
transform=transform,
max_samples=max_samples,
),
batch_size=batch_size,
Expand Down
10 changes: 8 additions & 2 deletions src/torchattack/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,13 @@ def run_attack(attack, attack_cfg, model='resnet50', samples=100, batch_size=8)
dataloader = NIPSLoader(
path='data/nips2017',
batch_size=batch_size,
transform=tv.transforms.Resize(size=224, antialias=True),
transform=tv.transforms.Compose(
[
tv.transforms.Resize([232]),
tv.transforms.CenterCrop([224]),
tv.transforms.ToTensor(),
]
),
max_samples=samples,
)

Expand All @@ -42,7 +48,7 @@ def run_attack(attack, attack_cfg, model='resnet50', samples=100, batch_size=8)
std=[0.229, 0.224, 0.225],
)
total, acc_clean, acc_adv = len(dataloader.dataset), 0, 0 # type: ignore
attacker = attack(model=model, transform=normalize, device=device, **attack_cfg)
attacker = attack(model=model, normalize=normalize, device=device, **attack_cfg)
print(attacker)

# Wrap dataloader with rich.progress.track if available
Expand Down

0 comments on commit 3a85a1e

Please sign in to comment.