• Stars
    star
    4,849
  • Rank 8,674 (Top 0.2 %)
  • Language
    Python
  • License
    MIT License
  • Created almost 7 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Count the MACs / FLOPs of your PyTorch model.

THOP: PyTorch-OpCounter

How to install

pip install thop (now continously intergrated on Github actions)

OR

pip install --upgrade git+https://github.com/Lyken17/pytorch-OpCounter.git

How to use

  • Basic usage

    from torchvision.models import resnet50
    from thop import profile
    model = resnet50()
    input = torch.randn(1, 3, 224, 224)
    macs, params = profile(model, inputs=(input, ))
  • Define the rule for 3rd party module.

    class YourModule(nn.Module):
        # your definition
    def count_your_model(model, x, y):
        # your rule here
    
    input = torch.randn(1, 3, 224, 224)
    macs, params = profile(model, inputs=(input, ), 
                            custom_ops={YourModule: count_your_model})
  • Improve the output readability

    Call thop.clever_format to give a better format of the output.

    from thop import clever_format
    macs, params = clever_format([macs, params], "%.3f")

Results of Recent Models

The implementation are adapted from torchvision. Following results can be obtained using benchmark/evaluate_famous_models.py.

Model Params(M) MACs(G)
alexnet 61.10 0.77
vgg11 132.86 7.74
vgg11_bn 132.87 7.77
vgg13 133.05 11.44
vgg13_bn 133.05 11.49
vgg16 138.36 15.61
vgg16_bn 138.37 15.66
vgg19 143.67 19.77
vgg19_bn 143.68 19.83
resnet18 11.69 1.82
resnet34 21.80 3.68
resnet50 25.56 4.14
resnet101 44.55 7.87
resnet152 60.19 11.61
wide_resnet101_2 126.89 22.84
wide_resnet50_2 68.88 11.46
Model Params(M) MACs(G)
resnext50_32x4d 25.03 4.29
resnext101_32x8d 88.79 16.54
densenet121 7.98 2.90
densenet161 28.68 7.85
densenet169 14.15 3.44
densenet201 20.01 4.39
squeezenet1_0 1.25 0.82
squeezenet1_1 1.24 0.35
mnasnet0_5 2.22 0.14
mnasnet0_75 3.17 0.24
mnasnet1_0 4.38 0.34
mnasnet1_3 6.28 0.53
mobilenet_v2 3.50 0.33
shufflenet_v2_x0_5 1.37 0.05
shufflenet_v2_x1_0 2.28 0.15
shufflenet_v2_x1_5 3.50 0.31
shufflenet_v2_x2_0 7.39 0.60
inception_v3 27.16 5.75

More Repositories

1

Efficient-PyTorch

My best practice of training large dataset using PyTorch.
Python
1,081
star
2

pytorch-memonger

Sublinear memory optimization for deep learning. https://arxiv.org/abs/1604.06174
Python
587
star
3

SparseNet

[ECCV 2018] Sparsely Aggreagated Convolutional Networks https://arxiv.org/abs/1801.05895
Python
125
star
4

arXiv-stats

Python
50
star
5

hf-torrent

Python
37
star
6

mxbox

Simple, efficient and flexible vision toolbox for mxnet framework.
Python
31
star
7

Bayesian-Compression-for-Deep-Learning

Remplementation of paper https://arxiv.org/abs/1705.08665
Python
28
star
8

PyTorch-Template

A template for PyTorch projects.
Python
22
star
9

Colorize-Your-World

Let there be color!
Jupyter Notebook
19
star
10

Machine-Learning-for-Image-Colorization

(Torch + Tensorflow) A deep magic brings color to your monochrome image!
MATLAB
12
star
11

GroupNorm.pytorch

PyTorch implementation of Group Normalization https://arxiv.org/abs/1803.08494
Python
11
star
12

Colorizing-Color-Images

[HVEI 2018] Colorizing Color Images
Jupyter Notebook
11
star
13

Project-Page-Render

HTML
10
star
14

Echoo

Let your program echo to you.
Python
8
star
15

arch-viz

Python
5
star
16

hf-torrent-store

5
star
17

Deep-Learning-Live

From linear regression to multi-layer perceptron, an introductive tutorial for deep learning beginners.
4
star
18

MNasNet-TensorFlow

Implementation of MnasNet: Platform-Aware Neural Architecture Search for Mobile
Python
4
star
19

tvm-notes

Python
4
star
20

PyTorch-via-PyTorch

C++
4
star
21

FlashATM

3
star
22

HW-for-COMP

HTML
3
star
23

edge-cloud-train

Python
3
star
24

ffmpeg-cuda-docker

A docker container to launch GPU accelerated FFmpeg
Dockerfile
3
star
25

pi-tools

A repo includes some useful tools for raspberry pi farm setup. https://hub.docker.com/repository/docker/lyken/pi-tools
Dockerfile
2
star
26

EIE-pytorch

PyTorch implementation for EIE https://arxiv.org/abs/1602.01528
Jupyter Notebook
2
star
27

Colorize.PyTorch

Python
2
star
28

torch-mps-benchmark

Python
1
star
29

sample-video

1
star
30

micro23

1
star
31

GPU-Speed-Benchmark

Python
1
star
32

tvm-issue-07-12

Python
1
star
33

Docker-Horovod

Dockerfile
1
star
34

Deep-Learning-Framework-Popularity

Python
1
star
35

pythonLearn

Python
1
star
36

BeihangData

Python
1
star
37

tiny-whisper

Python
1
star
38

Neurips19-Statistics

1
star
39

gluon-multiple-gpu

Python
1
star
40

tvm-hack

Python
1
star
41

lith

Ligeng's extensions for PyTorch
Python
1
star
42

ubuntun-research

Common scripts I've used for setting up my ubuntu server
Shell
1
star
43

wandb-example

Python
1
star