Git Product home page Git Product logo

fast_is_better_than_free_imagenet's Introduction

Fast Adversarial Training

This is a supplemental material containing the code to run Fast is better than free: revisiting adversarial training, submitted to ICLR 2020.

The framework used is a modified version of the Free Adversarial Training repository, which in turn was adapted from the official PyTorch repository.

Installation

  1. Install PyTorch.
  2. Install the required python packages. All packages can be installed by running the following command:
pip install -r requirements.txt
  1. Download and prepare the ImageNet dataset. You can use this script, provided by the PyTorch repository, to move the validation subset to the labeled subfolders.
  2. Prepare resized versions of the ImageNet dataset, you can use resize.py provided in this repository.
  3. Install Apex to use half precision speedup.

Training a model

Scripts to robustly train an ImageNet classifier for epsilon radii of 2/255 and 4/255 are provided in run_fast_2px.sh and run_fast_4px.sh. These run the main code module main_free.py using the configurations provided in the configs/ folder. To run the 50 step PGD adversary with 10 restarts, we also provide run_eval.sh. All parameters can be modified by adjusting the configuration files in the configs/ folder.

Model weights

We also provide the model weights after training with these scripts, which can be found in this Google drive folder. To use these with the provided evaluation script, either adjust the path to the model weights in the run_eval.sh script or rename the provided model weights accordingly.

fast_is_better_than_free_imagenet's People

Contributors

anonymous-sushi-armadillo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

fast_is_better_than_free_imagenet's Issues

The pre-trained model you released is not robust

I downloaded the model weight you released in Google drive folder and found that it is not robust.

CUDA_VISIBLE_DEVICES=0,1,2,3 python3 main_fast.py ../../1_Dataset/ImageNet/ --config ./configs/configs_fast_2px_evaluate.yml --output_prefix eval_2px --resume ./checkpoint/imagenet_model_weights_2px.pth.tar --evaluate --restarts 1

output

/home/2_class_level/ImageNet/utils.py:81: YAMLLoadWarning: calling yaml.load() without Loader=... is deprecated, as the default Loader is unsafe. Please read https://msg.pyyaml.org/load for full details.
  config = EasyDict(yaml.load(f))
INFO:root:***************************** LOGISTICS *****************************
INFO:root:Experiment Date: 2020-08-09 08:21
INFO:root:Output Name: eval_2px_step2_eps2_repeat1
INFO:root:User: XX
INFO:root:***************************** ARGUMENTS *****************************
INFO:root:TRAIN: {'arch': 'resnet50', 'lr': 0.1, 'momentum': 0.9, 'weight_decay': 0.0001, 'print_freq': 10, 'mean': [0.485, 0.456, 0.406], 'std': [0.229, 0.224, 0.225], 'start_epoch': 12, 'epochs': 15, 'lr_epochs': [12, 15], 'lr_values': [0.004, 0.0004], 'half': True, 'random_init': True}
INFO:root:ADV: {'clip_eps': 2.0, 'fgsm_step': 2.0, 'n_repeats': 1, 'pgd_attack': [(50, 0.00392156862)]}
INFO:root:DATA: {'workers': 4, 'max_color_value': 255.0, 'img_size': 0, 'batch_size': 128, 'crop_size': 288}
INFO:root:data: ../../1_Dataset/ImageNet/
INFO:root:output_prefix: eval_2px
INFO:root:config: ./configs/configs_fast_2px_evaluate.yml
INFO:root:resume: ./checkpoint/imagenet_model_weights_2px.pth.tar
INFO:root:evaluate: True
INFO:root:pretrained: False
INFO:root:restarts: 1
INFO:root:output_name: eval_2px_step2_eps2_repeat1
INFO:root:**********************************************************************
INFO:root:=> creating model 'resnet50'
INFO:root:=> loading checkpoint './checkpoint/imagenet_model_weights_2px.pth.tar'
INFO:root:configs.TRAIN.start_epoch = 15
INFO:root:best_prec1 = 60.89999771118164
INFO:root:=> loaded checkpoint './checkpoint/imagenet_model_weights_2px.pth.tar' (epoch 15)
INFO:root:*********************** Performing PGD Attacks ***********************
INFO:root:******* PGD eps: 2.0, K: 50, step: 0.00392156862, restarts: 1 *******
PGD Test: [0/391]       Time 28.806 (28.806)    Loss 16.8124 (16.8124)  Prec@1 0.000 (0.000)    Prec@5 0.000 (0.000)
PGD Test: [10/391]      Time 12.807 (14.247)    Loss 20.1095 (18.0751)  Prec@1 0.000 (0.000)    Prec@5 0.000 (0.000)
PGD Test: [20/391]      Time 12.812 (13.567)    Loss 21.4244 (18.4928)  Prec@1 0.000 (0.000)    Prec@5 0.000 (0.000)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.