https://github.com/juliagusak/flopco-pytorch
FLOPs and other statistics COunter for Pytorch neural networks
https://github.com/juliagusak/flopco-pytorch
cnn flops macs neural-networks pytorch
Last synced: about 1 year ago
JSON representation
FLOPs and other statistics COunter for Pytorch neural networks
- Host: GitHub
- URL: https://github.com/juliagusak/flopco-pytorch
- Owner: juliagusak
- License: mit
- Created: 2019-10-10T18:14:50.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2021-05-27T11:09:41.000Z (about 5 years ago)
- Last Synced: 2025-04-12T11:17:54.593Z (about 1 year ago)
- Topics: cnn, flops, macs, neural-networks, pytorch
- Language: Python
- Size: 30.3 KB
- Stars: 23
- Watchers: 2
- Forks: 10
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
FlopCo
=====
FlopCo is a Python library that aims to make FLOPs and MACs counting simple and accessible for Pytorch neural networks.
Moreover FlopCo allows to collect other useful model statistics, such as number of parameters, shapes of layer inputs/outputs, etc.
Requirements
-----
- numpy
- pytorch
Installation
-----
```pip install flopco-pytorch ```
Quick start
-----
```python
from flopco import FlopCo
from torchvision.models import resnet50
device = 'cuda'
model = resnet50().to(device)
# Estimate model statistics by making one forward pass througth the model,
# for the input image of size 3 x 224 x 224
stats = FlopCo(model, img_size = (1, 3, 224, 224), device = device)
print(stats.total_macs, stats.relative_flops)
```
List of estimated statistics includes:
- total number of FLOPs/MACs/parameters
- number of FLOPs/MACs/parameters for each layer
- relative number of FLOPs/MACs/parameters for each layer
- input/output shapes for each layer
By default for statistics counting nn.Conv2d and nn.Linear layers are used.
To include more layer types in computation, pass ```instances``` to the constructor
```python
stats = FlopCo(model,
img_size = (1, 3, 224, 224),
device = device,
instances = [nn.Conv2d, nn.Linear,\
nn.BatchNorm2d, nn.ReLU,\
nn.MaxPool2d, nn.AvgPool2d,\
nn.Softmax]
)
```
License
-----
Project is distributed under [MIT License](https://github.com/juliagusak/flopco-pytorch/blob/master/LICENSE.txt)