Giter VIP home page Giter VIP logo

bag-of-tricks's Introduction

Bag of tricks

An easy-to-reuse code for bag-of-tricks in PyTorch.

Reuse hints

Reuse the codes in utils/trick and follow main.py to modify your code.

For example,

$ git clone https://github.com/siahuat0727/bag-of-tricks
$ cp -r bag-of-tricks/utils path/to/your/repo

then slightly modify your code.

Just a kindly reminder here. For detail, please have a look at the simple and clean demo code main.py instead of the hints below.

1. Cosine learning rate

Use torch.optim.lr_scheduler.CosineAnnealingLR and .step() every training batch.

2. Warmup learning rate

It's recommended to use torch.optim.lr_scheduler for the remaining lr schedule (after warmup), and pass your original scheduler as the parameter after_scheduler in GradualWarmupScheduler. Remember to initialize your optimizer with the real initial lr (not the lr after warmup).

3. Label smoothing

CrossEntropyLossMaybeSmooth is inherited from CrossEntropyLoss. There is usually no need to calculate the loss when evaluating. If you need to do this, you can call .train() to select the smooth version before training and call .eval() to select the non-smooth version before evaluating.

4. Mixup

Aside from the code, the only thing to mention is that the accuracy shown in the training step is usually lower than the actual training accuracy, since the input is a mixture of two images.

Results - CIFAR10

ResNet18

cosine warmup label smoothing mixup accuracy (90 epochs) accuracy (400 epochs)
93.10 94.05
92.94 94.07
93.18 93.99
93.38 94.30
93.77 95.40
94.63 96.01

To reproduce exactly the same result:

$ python main.py --gpu
$ python main.py --gpu --cosine
$ python main.py --gpu --warmup 5
$ python main.py --gpu --smooth 0.1
$ python main.py --gpu --mixup 0.3
$ python main.py --gpu --warmup 5 --smooth 0.1 --mixup 0.3 --cosine

Please star this project if you find it useful. ^.^

bag-of-tricks's People

Contributors

siahuat0727 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

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.