EfficientNetV2 implementation using PyTorch

Overview

EfficientNetV2-S implementation using PyTorch

Train Steps

  • Configure imagenet path by changing data_dir in train.py
  • python main.py --benchmark for model information
  • python -m torch.distributed.launch --nproc_per_node=$ main.py --train for training model, $ is number of GPUs
  • python main.py --test for testing

Note

  • The model achieved 82.7 top-1 after 150 epochs
Number of parameters: 23941296
Time per operator type:
        778.049 ms.    70.6258%. Conv
        255.227 ms.    23.1677%. Sigmoid
          56.91 ms.    5.16589%. Mul
         6.1573 ms.   0.558916%. Add
        4.69289 ms.   0.425987%. ReduceMean
       0.613303 ms.  0.0556713%. FC
        1101.65 ms in Total
FLOP per operator type:
         17.277 GFLOP.    99.7074%. Conv
      0.0419251 GFLOP.   0.241954%. Mul
     0.00519322 GFLOP.  0.0299706%. Add
       0.003585 GFLOP.  0.0206894%. FC
        17.3277 GFLOP in Total
Feature Memory Read per operator type:
        295.875 MB.    50.5134%. Mul
        241.136 MB.     41.168%. Conv
        41.5457 MB.     7.0929%. Add
        7.17917 MB.    1.22567%. FC
        585.737 MB in Total
Feature Memory Written per operator type:
          167.7 MB.    49.2361%. Mul
        152.127 MB.    44.6639%. Conv
        20.7729 MB.    6.09882%. Add
          0.004 MB. 0.00117438%. FC
        340.605 MB in Total
Parameter Memory per operator type:
        87.8034 MB.    92.4486%. Conv
          7.172 MB.    7.55143%. FC
              0 MB.          0%. Add
              0 MB.          0%. Mul
        94.9754 MB in Total
You might also like...
A PyTorch implementation of the paper Mixup: Beyond Empirical Risk Minimization in PyTorch
A PyTorch implementation of the paper Mixup: Beyond Empirical Risk Minimization in PyTorch

Mixup: Beyond Empirical Risk Minimization in PyTorch This is an unofficial PyTorch implementation of mixup: Beyond Empirical Risk Minimization. The co

A pytorch implementation of  Pytorch-Sketch-RNN
A pytorch implementation of Pytorch-Sketch-RNN

Pytorch-Sketch-RNN A pytorch implementation of https://arxiv.org/abs/1704.03477 In order to draw other things than cats, you will find more drawing da

PyTorch implementation of Advantage async actor-critic Algorithms (A3C) in PyTorch
PyTorch implementation of Advantage async actor-critic Algorithms (A3C) in PyTorch

Advantage async actor-critic Algorithms (A3C) in PyTorch @inproceedings{mnih2016asynchronous, title={Asynchronous methods for deep reinforcement lea

Pytorch-diffusion - A basic PyTorch implementation of 'Denoising Diffusion Probabilistic Models'
Pytorch-diffusion - A basic PyTorch implementation of 'Denoising Diffusion Probabilistic Models'

PyTorch implementation of 'Denoising Diffusion Probabilistic Models' This reposi

RetinaNet-PyTorch - A RetinaNet Pytorch Implementation on remote sensing images and has the similar mAP result with RetinaNet in MMdetection RETRO-pytorch - Implementation of RETRO, Deepmind's Retrieval based Attention net, in Pytorch
RETRO-pytorch - Implementation of RETRO, Deepmind's Retrieval based Attention net, in Pytorch

RETRO - Pytorch (wip) Implementation of RETRO, Deepmind's Retrieval based Attent

HashNeRF-pytorch - Pure PyTorch Implementation of NVIDIA paper on Instant Training of Neural Graphics primitives
HashNeRF-pytorch - Pure PyTorch Implementation of NVIDIA paper on Instant Training of Neural Graphics primitives

HashNeRF-pytorch Instant-NGP recently introduced a Multi-resolution Hash Encodin

[PyTorch] Official implementation of CVPR2021 paper
[PyTorch] Official implementation of CVPR2021 paper "PointDSC: Robust Point Cloud Registration using Deep Spatial Consistency". https://arxiv.org/abs/2103.05465

PointDSC repository PyTorch implementation of PointDSC for CVPR'2021 paper "PointDSC: Robust Point Cloud Registration using Deep Spatial Consistency",

Non-Official Pytorch implementation of
Non-Official Pytorch implementation of "Face Identity Disentanglement via Latent Space Mapping" https://arxiv.org/abs/2005.07728 Using StyleGAN2 instead of StyleGAN

Face Identity Disentanglement via Latent Space Mapping - Implement in pytorch with StyleGAN 2 Description Pytorch implementation of the paper Face Ide

Comments
  • wonder how you get the model metric

    wonder how you get the model metric

    Very impressive project ! As your readme motioned. How the metric get by the code.

    Number of parameters: 23941296
    Time per operator type:
            778.049 ms.    70.6258%. Conv
            255.227 ms.    23.1677%. Sigmoid
              56.91 ms.    5.16589%. Mul
             6.1573 ms.   0.558916%. Add
            4.69289 ms.   0.425987%. ReduceMean
           0.613303 ms.  0.0556713%. FC
            1101.65 ms in Total
    FLOP per operator type:
             17.277 GFLOP.    99.7074%. Conv
          0.0419251 GFLOP.   0.241954%. Mul
         0.00519322 GFLOP.  0.0299706%. Add
           0.003585 GFLOP.  0.0206894%. FC
            17.3277 GFLOP in Total
    Feature Memory Read per operator type:
            295.875 MB.    50.5134%. Mul
            241.136 MB.     41.168%. Conv
            41.5457 MB.     7.0929%. Add
            7.17917 MB.    1.22567%. FC
            585.737 MB in Total
    Feature Memory Written per operator type:
              167.7 MB.    49.2361%. Mul
            152.127 MB.    44.6639%. Conv
            20.7729 MB.    6.09882%. Add
              0.004 MB. 0.00117438%. FC
            340.605 MB in Total
    Parameter Memory per operator type:
            87.8034 MB.    92.4486%. Conv
              7.172 MB.    7.55143%. FC
                  0 MB.          0%. Add
                  0 MB.          0%. Mul
            94.9754 MB in Total
    
    opened by xiaoerlaigeid 2
  • 'DropPath' object has no attribute 'scale_by_keep'

    'DropPath' object has no attribute 'scale_by_keep'

    HARDWARE

    • Ubuntu 18.04
    • Torch 1.7.0a0+7036e91
    • Torch vision 0.8.0a0

    Hi, @jahongir7174 Thank you for your awesome work.

    I tried to run a test on your pre-trained model. However, It seems that the pre-trained model gives me an error. Could you please help me to solve this problem?

    Number of parameters: 21458488
         acc@1     acc@5:   0%|                                                                                                                                                          | 0/48 [00:00<?, ?it/s]
    Traceback (most recent call last):
      File "main.py", line 227, in <module>
        main()
      File "main.py", line 223, in main
        test()
      File "main.py", line 171, in test
        loss, acc1, acc5 = batch(images, target, model, criterion)
      File "main.py", line 43, in batch
        output = model(images)
      File "/opt/conda/lib/python3.6/site-packages/torch/nn/modules/module.py", line 727, in _call_impl
        result = self.forward(*input, **kwargs)
      File "/ws/EfficientNetV2/nets/nn.py", line 164, in forward
        x = self.p1(x)
      File "/opt/conda/lib/python3.6/site-packages/torch/nn/modules/module.py", line 727, in _call_impl
        result = self.forward(*input, **kwargs)
      File "/opt/conda/lib/python3.6/site-packages/torch/nn/modules/container.py", line 117, in forward
        input = module(input)
      File "/opt/conda/lib/python3.6/site-packages/torch/nn/modules/module.py", line 727, in _call_impl
        result = self.forward(*input, **kwargs)
      File "/ws/EfficientNetV2/nets/nn.py", line 69, in forward
        return x + self.res(x) if self.add else self.res(x)
      File "/opt/conda/lib/python3.6/site-packages/torch/nn/modules/module.py", line 727, in _call_impl
        result = self.forward(*input, **kwargs)
      File "/opt/conda/lib/python3.6/site-packages/torch/nn/modules/container.py", line 117, in forward
        input = module(input)
      File "/opt/conda/lib/python3.6/site-packages/torch/nn/modules/module.py", line 727, in _call_impl
        result = self.forward(*input, **kwargs)
      File "/opt/conda/lib/python3.6/site-packages/timm/models/layers/drop.py", line 164, in forward
        return drop_path(x, self.drop_prob, self.training, self.scale_by_keep)
      File "/opt/conda/lib/python3.6/site-packages/torch/nn/modules/module.py", line 779, in __getattr__
        type(self).__name__, name))
    torch.nn.modules.module.ModuleAttributeError: 'DropPath' object has no attribute 'scale_by_keep'
    

    I also create a script to test your model on a single image, got the same problem too.

    import torch
    from torchvision import transforms
    from PIL import Image
    
    
    model = torch.load('weights/best.pt', map_location='cuda')['model'].float()
    with torch.no_grad():
        model.eval()  
    
    image = Image.open("/ws/dataset/hamxe_dataset/data_fake/data_Fake/data/mau/bike/EtzcWfSbQS.jpg")
    normalize = transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
    
    transform_norm = transforms.Compose([transforms.Resize(384),
                                              transforms.CenterCrop(384),
                                              transforms.ToTensor(), normalize])
    img_normalized = transform_norm(image).float()
    img_normalized = img_normalized.unsqueeze_(0)
    img_normalized = img_normalized.cuda()
    
    with torch.cuda.amp.autocast():
        output = model(img_normalized)
    
    print(output)
    
    opened by HoangTienDuc 1
  • Possibility of forking and add arguments

    Possibility of forking and add arguments

    Hi, thanks for your wonderful code, may I ask if I can have your permission to fork you code and add arguments for your training, that would improve on how easy it is to use the script?

    A few additional questions?

    • Do I have to specify number of classes I need to train
    • Have you compared your result with timm library yet?
    opened by AnhMinhTran 1
  • Above your nn.py have some problems.

    Above your nn.py have some problems.

    In your python file nets/nn.py. I think your class SE for realize SE(squeeze and Excitation).Why your init() haven't avgpool for squeeze,And self.se use conv2d. did not nn.linear(). Looking forward to your reply.

    opened by JH95-ai 1
Owner
Jahongir Yunusov
Jahongir Yunusov
A PyTorch implementation of EfficientNet and EfficientNetV2 (coming soon!)

EfficientNet PyTorch Quickstart Install with pip install efficientnet_pytorch and load a pretrained EfficientNet with: from efficientnet_pytorch impor

Luke Melas-Kyriazi 7.2k Jan 6, 2023
EfficientNetv2 TensorRT int8

EfficientNetv2_TensorRT_int8 EfficientNetv2模型实现来自https://github.com/d-li14/efficientnetv2.pytorch 环境配置 ubuntu:18.04 cuda:11.0 cudnn:8.0 tensorrt:7

null 34 Apr 24, 2022
Objective of the repository is to learn and build machine learning models using Pytorch. 30DaysofML Using Pytorch

30 Days Of Machine Learning Using Pytorch Objective of the repository is to learn and build machine learning models using Pytorch. List of Algorithms

Mayur 119 Nov 24, 2022
RealFormer-Pytorch Implementation of RealFormer using pytorch

RealFormer-Pytorch Implementation of RealFormer using pytorch. Includes comparison with classical Transformer on image classification task (ViT) wrt C

Simo Ryu 90 Dec 8, 2022
ALBERT-pytorch-implementation - ALBERT pytorch implementation

ALBERT-pytorch-implementation developing... 모델의 개념이해를 돕기 위한 구현물로 현재 변수명을 상세히 적었고

BG Kim 3 Oct 6, 2022
Amazon Forest Computer Vision: Satellite Image tagging code using PyTorch / Keras with lots of PyTorch tricks

Amazon Forest Computer Vision Satellite Image tagging code using PyTorch / Keras Here is a sample of images we had to work with Source: https://www.ka

Mamy Ratsimbazafy 360 Dec 10, 2022
Amazon Forest Computer Vision: Satellite Image tagging code using PyTorch / Keras with lots of PyTorch tricks

Amazon Forest Computer Vision Satellite Image tagging code using PyTorch / Keras Here is a sample of images we had to work with Source: https://www.ka

Mamy Ratsimbazafy 359 Jan 5, 2023
A bunch of random PyTorch models using PyTorch's C++ frontend

PyTorch Deep Learning Models using the C++ frontend Gettting started Clone the repo 1. https://github.com/mrdvince/pytorchcpp 2. cd fashionmnist or

Vince 0 Jul 13, 2021
ChatBot-Pytorch - A GPT-2 ChatBot implemented using Pytorch and Huggingface-transformers

ChatBot-Pytorch A GPT-2 ChatBot implemented using Pytorch and Huggingface-transf

ParZival 42 Dec 9, 2022
An essential implementation of BYOL in PyTorch + PyTorch Lightning

Essential BYOL A simple and complete implementation of Bootstrap your own latent: A new approach to self-supervised Learning in PyTorch + PyTorch Ligh

Enrico Fini 48 Sep 27, 2022