
내장된 적대적 강건성 도구(PGD 공격, 적대적 학습, 비전 연구용 강건한 사전 학습 모델 포함)를 사용하여 신경망을 훈련하고, 평가하고, 탐색하세요.
pip으로 설치: pip install robustness
문서 보기: https://robustness.readthedocs.io/en/latest/index.html
robustness는 우리(MadryLab <http://madry-lab.ml>_의 학생들)가 신경망 훈련, 평가, 탐색을 유연하고 쉽게 만들기 위해 만든 패키지입니다. 우리는 거의 모든 프로젝트에서 이 패키지를 사용합니다(적대적 훈련과 관련이 있든 없든!). 또한 향후 많은 코드 릴리스에서 이 패키지를 의존성으로 사용할 것입니다. 이 라이브러리를 사용하는 몇 가지 프로젝트는 다음과 같습니다:
Code for "Learning Perceptually-Aligned Representations via Adversarial Robustness" <https://github.com/MadryLab/robust_representations>_ (https://arxiv.org/abs/1906.00945)Code for "Image Synthesis with a Single (Robust) Classifier" <https://github.com/MadryLab/robustness_applications>_ (https://arxiv.org/abs/1906.09453)Code for "Do Adversarially Robust ImageNet Models Transfer Better?" <https://github.com/microsoft/robust-models-transfer>_ (https://arxiv.org/abs/2007.08489)Code for "BREEDS: Benchmarks for Subpopulation Shift" <https://github.com/MadryLab/BREEDS-Benchmarks>_ (https://arxiv.org/abs/2008.04859)Code for "Certified Patch Robustness via Smoothed Vision Transformers." <https://github.com/MadryLab/smoothed-vit>_ (https://arxiv.org/abs/2110.07719)Code for "Unadversarial Examples: Designing Objects for Robust Vision." <https://github.com/microsoft/unadversarial>_ (https://arxiv.org/abs/2012.12235)우리는 일련의 워크스루와 API 레퍼런스를 통해 라이브러리 사용 방법을 보여줍니다. 라이브러리가 제공하는 기능은 다음과 같습니다:
CLI 인터페이스 <https://robustness.readthedocs.io/en/latest/example_usage/cli_usage.html>를 사용하여 다양한 데이터셋/아키텍처에 대한 표준 및 강건 모델을 훈련하고 평가합니다. 라이브러리는 또한 사용자 지정 데이터셋 <https://robustness.readthedocs.io/en/latest/example_usage/training_lib_part_2.html#training-on-custom-datasets> 및 모델 아키텍처 <https://robustness.readthedocs.io/en/latest/example_usage/training_lib_part_2.html#training-with-custom-architectures>_ 추가를 지원합니다... code-block:: bash
python -m robustness.main --dataset cifar --data /path/to/cifar
--adv-train 0 --arch resnet18 --out-dir /logs/checkpoints/dir/
입력 조작 <https://robustness.readthedocs.io/en/latest/example_usage/input_space_manipulation.html>_을 수행합니다. 여기에는 적대적 예제 생성, 표현(representation) 역변환, 특징 시각화 등이 포함됩니다. 라이브러리는 다양한 최적화 옵션(예: 실제/추정 그래디언트 선택, 푸리에/픽셀 기저, 사용자 정의 손실 함수 등)을 제공하며 쉽게 확장할 수 있습니다... code-block:: python
import torch as ch from robustness.datasets import CIFAR from robustness.model_utils import make_and_restore_model
ds = CIFAR('/path/to/cifar') model, _ = make_and_restore_model(arch='resnet50', dataset=ds, resume_path='/path/to/model', state_dict_path='model') model.eval() attack_kwargs = { 'constraint': 'inf', # L-inf PGD 'eps': 0.05, # Epsilon constraint (L-inf norm) 'step_size': 0.01, # Learning rate for PGD 'iterations': 100, # Number of PGD steps 'targeted': True # Targeted attack 'custom_loss': None # Use default cross-entropy loss }
_, test_loader = ds.make_loaders(workers=0, batch_size=10) im, label = next(iter(test_loader)) target_label = (label + ch.randint_like(label, high=9)) % 10 adv_out, adv_im = model(im, target_label, make_adv, **attack_kwargs)
robustness를 패키지로 가져와 사용자 정의 손실 함수, 로깅, 데이터 로딩 등을 지원하는 신경망 훈련을 쉽게 수행할 수 있습니다. 좋은 소개는 두 부분으로 구성된 워크스루(Part 1 <https://robustness.readthedocs.io/en/latest/example_usage/training_lib_part_1.html>, Part 2 <https://robustness.readthedocs.io/en/latest/example_usage/training_lib_part_2.html>)에서 찾을 수 있습니다... code-block:: python
from robustness import model_utils, datasets, train, defaults from robustness.datasets import CIFAR
from cox.utils import Parameters import cox.store
ds = CIFAR('/path/to/cifar') m, _ = model_utils.make_and_restore_model(arch='resnet50', dataset=ds) train_loader, val_loader = ds.make_loaders(batch_size=128, workers=8)
out_store = cox.store.Store(OUT_DIR)
train_kwargs = { 'out_dir': "train_out", 'adv_train': 1, 'constraint': '2', 'eps': 0.5, 'attack_lr': 1.5, 'attack_steps': 20 } train_args = Parameters(train_kwargs)
train_args = defaults.check_and_fill_args(train_args, defaults.TRAINING_ARGS, CIFAR) train_args = defaults.check_and_fill_args(train_args, defaults.PGD_ARGS, CIFAR)
train.train_model(train_args, m, (train_loader, val_loader), store=out_store)
참고: robustness는 CUDA가 지원되는 PyTorch가 설치되어 있어야 합니다.
훈련 코드와 함께 다양한 데이터셋, 노름(norm), ε-train 값에 대한 여러 사전 훈련된 모델을 공개합니다. 더 많거나 개선된 모델을 공개함에 따라 이 목록은 업데이트됩니다. 연구에서 이 모델을 사용하는 경우 이 라이브러리를 인용해 주시기 바랍니다(아래 bibtex 항목 참조).
각 (모델, ε-test) 조합에 대해 2.5 * ε-test / num_steps의 스텝 크기로 20-스텝 및 100-스텝 PGD를 평가합니다. 이 두 정확도는 서로 매우 가깝기 때문에 더 많은 PGD 스텝은 고려하지 않습니다. 각 ε-test 값에 대해 서로 다른 ε-train에서 달성한 최고 강건 정확도를 굵게 표시했습니다.
참고 #1: 우리는 하이퍼파라미터 튜닝을 수행하지 않았으며 표준 훈련과 동일한 하이퍼파라미터를 사용했습니다. 다른 훈련 하이퍼파라미터를 탐색하면 이러한 강건 정확도를 몇 퍼센트 포인트 높일 수 있을 것입니다.
참고 #2: 아래의 PyTorch 체크포인트(.pt) 파일은 다음 버전의 PyTorch와 Dill로 저장되었습니다:
.. code-block::
torch==1.1.0 dill==0.2.9
CIFAR10 L2-노름(ResNet50):
ε = 0.0 <https://www.dropbox.com/s/yhpp4yws7sgi6lj/cifar_nat.pt?dl=0>_ (표준 훈련)ε = 0.25 <https://www.dropbox.com/s/2qsp7pt6t7uo71w/cifar_l2_0_25.pt?dl=0>_ε = 0.5 <https://www.dropbox.com/s/1zazwjfzee7c8i4/cifar_l2_0_5.pt?dl=0>_ε = 1.0 <https://www.dropbox.com/s/s2x7thisiqxz095/cifar_l2_1_0.pt?dl=0>_+--------------+----------------+-----------------+---------------------+---------------------+ | CIFAR10 L2-robust accuracy | +--------------+----------------+-----------------+---------------------+---------------------+ | | ε-train | +--------------+----------------+-----------------+---------------------+---------------------+ | ε-test | 0.0 | 0.25 | 0.5 | 1.0 | +==============+================+=================+=====================+=====================+ | 0.0 | 95.25% / - | 92.77% / - | 90.83% / - | 81.62% / - | +--------------+----------------+-----------------+---------------------+---------------------+ | 0.25 | 8.66% / 7.34% | 81.21% / 81.19% | 82.34% / 82.31% | 75.53% / 75.53% | +--------------+----------------+-----------------+---------------------+---------------------+ | 0.5 | 0.28% / 0.14% | 62.30% / 62.13% | 70.17% / 70.11% | 68.63% / 68.61% | +--------------+----------------+-----------------+---------------------+---------------------+ | 1.0 | 0.00% / 0.00% | 21.18% / 20.66% | 40.47% / 40.22% | 52.72% / 52.61% | +--------------+----------------+-----------------+---------------------+---------------------+ | 2.0 | 0.00% / 0.00% | 0.58% / 0.46% | 5.23% / 4.97% | 18.59% / 18.05% | +--------------+----------------+-----------------+---------------------+---------------------+
CIFAR10 Linf-노름(ResNet50):
ε = 8/255 <https://www.dropbox.com/s/c9qlt1lbdnu9tlo/cifar_linf_8.pt?dl=0>_+--------------+-----------------+---------------------+ | CIFAR10 Linf-robust accuracy | +--------------+-----------------+---------------------+ | | ε-train | +--------------+-----------------+---------------------+ | ε-test | 0 / 255 | 8 / 255 | +==============+=================+=====================+ | 0 / 255 | 95.25% / - | 87.03% / - | +--------------+-----------------+---------------------+ | 8 / 255 | 0.00% / 0.00% | 53.49% / 53.29% | +--------------+-----------------+---------------------+ | 16 / 255 | 0.00% / 0.00% | 18.13% / 17.62% | +--------------+-----------------+---------------------+
ImageNet L2-노름(ResNet50):
ε = 3.0 <https://www.dropbox.com/s/knf4uimlqsi1yz8/imagenet_l2_3_0.pt?dl=0>_+--------------+-----------------+---------------------+ | ImageNet L2-robust accuracy | +--------------+-----------------+---------------------+ | | ε-train | +--------------+-----------------+---------------------+ | ε-test | 0.0 | 3.0 | +==============+=================+=====================+ | 0.0 | 76.13% / - | 57.90% / - | +--------------+-----------------+---------------------+ | 0.5 | 3.35% / 2.98% | 54.42% / 54.42% | +--------------+-----------------+---------------------+ | 1.0 | 0.44% / 0.37% | 50.67% / 50.67% | +--------------+-----------------+---------------------+ | 2.0 | 0.16% / 0.14% | 43.04% / 43.02% | +--------------+-----------------+---------------------+ | 3.0 | 0.13% / 0.12% | 35.16% / 35.09% | +--------------+-----------------+---------------------+
ImageNet Linf-노름(ResNet50):
ε = 4 / 255 <https://www.dropbox.com/s/axfuary2w1cnyrg/imagenet_linf_4.pt?dl=0>_ε = 8 / 255 <https://www.dropbox.com/s/yxn15a9zklz3s8q/imagenet_linf_8.pt?dl=0>_+--------------+-----------------+---------------------+---------------------+ | ImageNet Linf-robust accuracy | +--------------+-----------------+---------------------+---------------------+ | | ε-train | +--------------+-----------------+---------------------+---------------------+ | ε-test | 0.0 | 4 / 255 | 8 / 255 | +==============+=================+=====================+=====================+ | 0 / 255 | 76.13% / - | 62.42% / - | 47.91% / - | +--------------+-----------------+---------------------+---------------------+ | 4 / 255 | 0.04% / 0.03% | 33.58% / 33.38% | 33.06% / 33.03% | +--------------+-----------------+---------------------+---------------------+ | 8 / 255 | 0.01% / 0.01% | 13.13% / 12.73% | 19.63% / 19.52% | +--------------+-----------------+---------------------+---------------------+ | 16 / 255 | 0.01% / 0.01% | 1.53% / 1.37% | 5.00% / 4.82% | +--------------+-----------------+---------------------+---------------------+
이 라이브러리를 연구에 사용한다면 다음과 같이 인용해 주세요:
.. code-block:: bibtex
@misc{robustness, title={Robustness (Python Library)}, author={Logan Engstrom and Andrew Ilyas and Hadi Salman and Shibani Santurkar and Dimitris Tsipras}, year={2019}, url={https://github.com/MadryLab/robustness} }
(패키지를 사용해 보았고 유용하다고 느꼈나요? 알려주세요!).
Andrew Ilyas <https://twitter.com/andrew_ilyas>_Logan Engstrom <https://twitter.com/logan_engstrom>_Shibani Santurkar <https://twitter.com/ShibaniSan>_Dimitris Tsipras <https://twitter.com/tsiprasd>_Hadi Salman <https://twitter.com/hadisalmanX>_기여자/커미터 '''''''''''''''''''''''
여기 <https://github.com/MadryLab/robustness/pulse>_를 참조하세요.