Coder Social home page Coder Social logo

jiaowoguanren0615 / deit-pytorch Goto Github PK

View Code? Open in Web Editor NEW
3.0 1.0 0.0 59 KB

This is a warehouse for DeiT-pytorch-model, can be used to train your image dataset

License: MIT License

Python 100.00%
cait deit image-classification pytorch resmlp deep-learning image-recognition patch-convet

deit-pytorch's Introduction

Deit-Pytorch

This is the DeiT model code warehouse, which mainly includes models: DeiT, DeiTV2, ResMLP, CaiT, patchconvnet-models. The code is mainly derived from the official source code of facebookresearch, and has been modified based on it. Now it can be applied to your own image classification datasets.

Precautions

<1>Before you use the code to train your own data set, please first enter the train_gpu.py file and modify the data_root, batch_size and nb_classes parameters. If you want to draw the confusion matrix and ROC curve, you only need to remove the comments of Plot_ROC and Predictor at the end of the code. The comment of the function is enough, and the third parameter can be changed to the path of your own model weights file(.pth).

<2>If you want to use another model, import it in the train_gpu.py file, then find the following code and replace the name of model function.

model = deit_tiny_patch16_224(pretrained=False,
                              num_classes=args.nb_classes,
                              drop_rate=args.drop,
                              drop_path_rate=args.drop_path,
                              img_size=args.input_size
                              )

Train this model

train model with single-machine single-card:

python train_gpu.py

train model with single-machine multi-card:

torchrun --nproc_per_node=8 train_gpu.py

train model with single-machine multi-card:

(using a specified part of the cards: for example, I want to use the second and fourth cards)

CUDA_VISIBLE_DEVICES=1,3 torchrun --nproc_per_node=2 train_gpu.py

train model with multi-machine multi-card:

(For the specific number of GPUs on each machine, modify the value of --nproc_per_node. If you want to specify a certain card, just add CUDA_VISIBLE_DEVICES= to specify the index number of the card before each command. The principle is the same as single-machine multi-card training)

On the first machine: python -m torch.distributed.launch --nproc_per_node=1 --nnodes=2 --node_rank=0 --master_addr=<Master node IP address> --master_port=<Master node port number> train_gpu.py

On the second machine: python -m torch.distributed.launch --nproc_per_node=1 --nnodes=2 --node_rank=1 --master_addr=<Master node IP address> --master_port=<Master node port number> train_gpu.py

Paper

@InProceedings{pmlr-v139-touvron21a,
  title =     {Training data-efficient image transformers &amp; distillation through attention},
  author =    {Touvron, Hugo and Cord, Matthieu and Douze, Matthijs and Massa, Francisco and Sablayrolles, Alexandre and Jegou, Herve},
  booktitle = {International Conference on Machine Learning},
  pages =     {10347--10357},
  year =      {2021},
  volume =    {139},
  month =     {July}
}

deit-pytorch's People

Contributors

jiaowoguanren0615 avatar

Stargazers

 avatar  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.