Giter Club home page Giter Club logo

frequency-long-tailed-investigation's Introduction

Environments

  • pytorch
  • numpy
  • autoattack

Visualization of analytical experiments

  • The Visualize.ipynb file contains the model's under-fitting Behavior visualization and sensitivity analysis experimental code for high-frequency components.
  • We provide the data files required for visualization in the link, including input gradients under standard training and sampling results of the model loss space.

How to use Balance Spectrum Sampling(BaSS)strategy

We provide two methods of using BaSS in the data preprocessing stage:

  • for CIFAR10 or CIFAR100 dataset
train_set = torchvision.datasets.CIFAR10(root='/data/cifar', train=True, download=True)
test_set = torchvision.datasets.CIFAR10(root='/data/cifar', train=False, download=True)

print("CIFAR-B dataset :)")

train_set.data = get_BaSS_dataset(train_set.data.copy())
test_set.data = get_BaSS_dataset(test_set.data.copy())

We provide the algorithm details of the get_BaSS_dataset() function in the BaSS_cifar.py file

  • for ImageNet dataset
TRAIN_TRANSFORMS_IMAGENET = transforms.Compose([
        transforms.Resize((128,128)),

        ## applying BaSS 
        FreqLog(),
        ##

        transforms.RandomHorizontalFlip(),
        transforms.ColorJitter(
            brightness=0.1,
            contrast=0.1,
            saturation=0.1
        ),
        transforms.ToTensor(),
        Lighting(0.05, IMAGENET_PCA['eigval'], 
                      IMAGENET_PCA['eigvec'])
    ])

TEST_TRANSFORMS_IMAGENET = transforms.Compose([
        transforms.Resize((128,128)),

        ## applying BaSS
        FreqLog(),
        ##

        transforms.ToTensor(),
    ])

We provide the algorithm details of the FreqLog() function in the BaSS_imagegnet.py file

Examples of BaSS Working in Conjunction with Adversarial Training

Our adversarial training framework is based on Bag of Tricks for Adversarial Training (ICLR 2021, code) and MART(ICLR 2020, code).

Training

We only modified the data processing part based on the original code framework. For detailed code description, please refer to the readme file in the original repo. In order to train quickly, we edited the easy_train.py file to include the training script.

cd Bag-of-Tricks-for-AT
python easy_train.py

cd MART
python easy_train.py

We set the --f-train switch in the training script whether to use BaSS, for example

## standard training
script1 = 'CUDA_VISIBLE_DEVICES=0 python train.py --model resnet --dataset cifar10'

## training with BaSS
script2 = 'CUDA_VISIBLE_DEVICES=1 python train.py --model resnet --dataset cifar10 --f-train'

Evaluation

Our evaluation results are based on Clean acc, PGD(CE loss,CW loss),Autoattack.

cd Bag-of-Tricks-for-AT
python eval_cifar.py --out-dir 'path_to_the_model' --ATmethods 'TRADES' --f-test

cd MART
python test.py --dataset cifar10 --model resnet --f-test

frequency-long-tailed-investigation's People

Contributors

zhiyugege avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Forkers

smoothjing

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.