Giter VIP home page Giter VIP logo

efficientnetv2-pytorch's Introduction

EfficientNetV2-pytorch

Unofficial EfficientNetV2 pytorch implementation repository.

It contains:

Index

  1. Tutorial
  2. Experiment results
  3. Experiment Setup
  4. References

Tutorial

Colab Tutorial

How to load pretrained model?

If you just want to use pretrained model, load model by torch.hub.load

import torch

model = torch.hub.load('hankyul2/EfficientNetV2-pytorch', 'efficientnet_v2_s', pretrained=True, nclass=1000)
print(model)

Available Model Names: efficientnet_v2_{s|m|l}(ImageNet), efficientnet_v2_{s|m|l}_in21k(ImageNet21k)

How to fine-tuning model?

If you want to finetuning on cifar, use this repository.

  1. Clone this repo and install dependency

    git clone https://github.com/hankyul2/EfficientNetV2-pytorch.git
    pip3 install requirements.txt
  2. Train & Test model (see more examples in tmuxp/cifar.yaml)

    python3 main.py fit --config config/efficientnetv2_s/cifar10.yaml --trainer.gpus 2,3,

Experiment Results

Model Name Pretrained Dataset Cifar10 Cifar100
EfficientNetV2-S ImageNet 98.46 (tf.dev, weight) 90.05 (tf.dev, weight)
EfficientNetV2-M ImageNet 98.89 (tf.dev, weight) 91.54 (tf.dev, weight)
EfficientNetV2-L ImageNet 98.80 (tf.dev, weight) 91.88 (tf.dev, weight)
EfficientNetV2-S-in21k ImageNet21k 98.50 (tf.dev, weight) 90.96 (tf.dev, weight)
EfficientNetV2-M-in21k ImageNet21k 98.70 (tf.dev, weight) 92.06 (tf.dev, weight)
EfficientNetV2-L-in21k ImageNet21k 98.78 (tf.dev, weight) 92.08 (tf.dev, weight)
EfficientNetV2-XL-in21k ImageNet21k - -

Note

  1. The results are combination of
    • Half precision
    • Super Convergence(epoch=20)
    • AdamW(weight_decay=0.005)
    • EMA(decay=0.999)
    • cutmix(prob=1.0)
  2. Changes from original paper (CIFAR)
    1. We just run 20 epochs to got above results. If you run more epochs, you can get more higher accuracy.
    2. What we changed from original setup are: optimizer(SGD to AdamW), LR scheduler(cosinelr to onecylelr), augmentation(cutout to cutmix), image size (384 to 224), epoch (105 to 20).
    3. Important hyper-parameter(most important to least important): LR->weigth_decay->ema-decay->cutmix_prob->epoch.
  3. you can get same results by running tmuxp/cifar.yaml

Experiment Setup

  1. Cifar setup

    Category Contents
    Dataset CIFAR10 | CIFAR100
    Batch_size per gpu (s, m, l) = (256, 128, 64)
    Train Augmentation image_size = 224, horizontal flip, random_crop (pad=4), CutMix(prob=1.0)
    Test Augmentation image_size = 224, center_crop
    Model EfficientNetV2 s | m | l (pretrained on in1k or in21k)
    Regularization Dropout=0.0, Stochastic_path=0.2, BatchNorm
    Optimizer AdamW(weight_decay=0.005)
    Criterion Label Smoothing (CrossEntropyLoss)
    LR Scheduler LR: (s, m, l) = (0.001, 0.0005, 0.0003), LR scheduler: OneCycle Learning Rate(epoch=20)
    GPUs & ETC 16 precision
    EMA(decay=0.999, 0.9993, 0.9995)
    S - 2 * 3090 (batch size 512)
    M - 2 * 3090 (batch size 256)
    L - 2 * 3090 (batch size 128)

References

EfficientNetV2

efficientnetv2-pytorch's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

efficientnetv2-pytorch's Issues

/usr/lib/python3.7/site-packages/torch/jit/_trace.py:754: UserWarning: The input to trace is already a ScriptModule, tracing it is a no-op. Returning the object as is.

import torch
from PIL import Image

img = Image.open('hen.jpg')
model = torch.hub.load('hankyul2/EfficientNetV2-pytorch', 'efficientnet_v2_s', pretrained=True, nclass=1000)

import matplotlib.pyplot as plt
from torchvision import transforms

transform = transforms.Compose([
transforms.ToTensor(),
transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])
])
x = transform(img).unsqueeze(0)
model.eval()
trace_model = torch.jit.trace(model, x)
torch.jit.trace(trace_model, "./efficientnet_v2_s.pt")
print("Successfully save traced model")

torch jit trace出现问题

Experiment 6: Run EfficientNet on Cifar

Run EfficientNet on cifar10/100

  • Model: EfficientNet-S, M, L, XL

  • Dataset: Cifar10

  • Prepare cifar setup

  • Prepare ImageNet Pretraining setup

  • Run Model on Cifar10

  • Run Model on Cifar100

Feat: Implement EfficientNet_V2

Implement EfficientNet_V2

  • Add Cifar DataModule
  • Add EfficientNet_V2
  • Add load_from_numpy
  • Add Progressive Learning System
  • Add AutoAug
  • Add Mixup

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.