Code Monkey home page Code Monkey logo

pytorch-vision-transformers-cifar10's Introduction

PYTORCH VISION TRANSFORMERS

Pytorch implementation of Vision transformer from An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale. Trainable on CIFAR10 only (for now).

Based on Pytorch Lightning.

SUMMARY

Last Commit Changes Log

  • Initial Commit

Installation

(Back to top)

Clone repo:

git clone https://github.com/the-dharma-bum/Pytorch-Vision-Transformers-CIFAR10

Install dependancies by running:

pip install -r requirements.txt

Usage

(Back to top)

All hyperparameters can be configured in config.py One can setup a training config inside this file and then simply run:

python main.py

This command accepts a huge number of parameters. Run

python main.py -h

to see them all, or refer to documentation de Pytorch Lightning.

Some usefull parameters:

  • --gpus n: launch training on n gpus
  • --distributed_backend ddp : use DistributedDataParallel as multi gpus training backend.
  • --fast_dev_run True : launch a training loop (train, eval, test) on a single batch. Use it to debug.

If fast_dev_run doesn't suit your debugging need (for instance if you wanna see what's happening between two epochs), you can use:

  • --limit_train_batches i --limit_val_batches j --max_epochs k

    i,j,k being of course three integers of your choice.

Fastai Integration

(Back to top)

It's very easy to integrate a Lighning code into the Fastai training environnement.

One must define

  • a model (see model.py):
import config as cfg
from model import LightningModel

model = LightningModel(cfg.TrainConfig())
  • a datamodule:
from pl_bolts.datamodules import CIFAR10DataModule

dm = CIFAR10DataModule(args, kwargs)

Using this datamodule, two fastai DataLoaders can be defined like this:

from fastai.vision.all import DataLoaders

data = Dataloaders(dm.train_dataloader(), dm.val_dataloader()).cuda()

Then a Learner can be defined and used like a standart Fastai code, for instance:

learn = Learner(data, model, loss_func=F.cross_entropy, opt_func=Adam, metrics=accuracy)
learn.fit_one_cycle(1, 0.001)

This makes every fastai training fonctionalites availables (callbacks, transforms, visualizations ...).

pytorch-vision-transformers-cifar10's People

Contributors

listindexoutofrange avatar

Watchers

 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.