Skip to content

Commit

Permalink
Bump version and update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
spencerwooo committed Nov 25, 2024
1 parent f5db6b0 commit a71df81
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: CI
name: ci

on:
pull_request:
Expand Down
39 changes: 33 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,38 @@
<sub><b>Install from GitHub source -</b></sub>

```shell
python -m pip install git+https://github.com/spencerwooo/torchattack
python -m pip install git+https://github.com/spencerwooo/torchattack@v1.0.1
```

<sub><b>Install from Gitee mirror -</b></sub>

```shell
python -m pip install git+https://gitee.com/spencerwoo/torchattack
python -m pip install git+https://gitee.com/spencerwoo/torchattack@v1.0.1
```

## Usage

```python
import torch

from torchattack import AttackModel, FGSM, MIFGSM

device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
```

Load a pretrained model to attack from either torchvision or timm.

```python
from torchattack import AttackModel

# Load a model
# Load a model with `AttackModel`
model = AttackModel.from_pretrained(model_name='resnet50', device=device)
# `AttackModel` automatically attach the model's `transform` and `normalize` functions
transform, normalize = model.transform, model.normalize
```

Initialize an attack by importing its attack class.

```python
from torchattack import FGSM, MIFGSM

# Initialize an attack
attack = FGSM(model, normalize, device)
Expand All @@ -51,7 +62,23 @@ attack = FGSM(model, normalize, device)
attack = MIFGSM(model, normalize, device, eps=0.03, steps=10, decay=1.0)
```

Check out [`torchattack.eval.runner`](torchattack/eval/runner.py) for a quick example.
Initialize an attack by its name with `create_attack()`.

```python
from torchattack import create_attack

# Initialize FGSM attack with create_attack
attack = create_attack('FGSM', model, normalize, device)

# Initialize PGD attack with specific eps with create_attack
attack = create_attack('PGD', model, normalize, device, eps=0.03)

# Initialize MI-FGSM attack with extra args with create_attack
attack_cfg = {'steps': 10, 'decay': 1.0}
attack = create_attack('MIFGSM', model, normalize, device, eps=0.03, attack_cfg=attack_cfg)
```

Check out [`torchattack.eval.runner`](torchattack/eval/runner.py) for a full example.

## Attacks

Expand Down
2 changes: 1 addition & 1 deletion torchattack/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from torchattack.vmifgsm import VMIFGSM
from torchattack.vnifgsm import VNIFGSM

__version__ = '1.0.0'
__version__ = '1.0.1'

__all__ = [
# Helper function to create an attack by its name
Expand Down

0 comments on commit a71df81

Please sign in to comment.