A tool to layer-wise count the MACs and parameters of PyTorch model.
Project description
PyTorch-layerwise-OpCounter
A tool for profile the MACs, parameters, input_shape, output_shape et.al of each layer in Pytorch model. Forked from Lyken17/pytorch-OpCounter which is not supporting layer-wise profile and I will follow it.
How to install
pip install torchlop
OR
pip install --upgrade git+https://github.com/hahnyuan/pytorch-layerwise-OpCounter.git
How to use
-
Basic usage
from torchvision.models import resnet50 from torchlop import profile model = resnet50() input = torch.randn(1, 3, 224, 224) macs, params, layer_infos = profile(model, inputs=(input, ))
-
The layer_infos is a dict that contains the infos for each layer of the pytorch model.
- The key is the name of the layer
- 'type': the class name of the layer
- 'in_size': input size
- 'out_size': output size
- 'ops': operations (MACs)
- 'params': parameters
-
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, layer_infos = profile(model, inputs=(input, ), custom_ops={YourModule: count_your_model})
-
Write the layerwise profile information into a csv file
from torchvision.models import resnet50 from torchlop import profile from torchlop.rst_process import write_csv model = resnet50() input = torch.randn(1, 3, 224, 224) macs, params, layer_infos = profile(model, inputs=(input, )) csv_file='profile.csv' write_csv(csv_file,layer_infos)
Results of Recent Models
The implementation are adapted from torchvision
. Following results can be obtained using benchmark/evaluate_famours_models.py.
|
|
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file torchlop-0.2.tar.gz
.
File metadata
- Download URL: torchlop-0.2.tar.gz
- Upload date:
- Size: 6.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.30.0 CPython/3.6.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0085d9dba04486c882d6c5f49763d8305da99c848e1da344222f951576da84bf |
|
MD5 | 451aedbdc305859ecbd588570557ab79 |
|
BLAKE2b-256 | d328c4d91262e9c7625b494f9f4264f082e088c064ec399953cd1a6a317425bb |
File details
Details for the file torchlop-0.2-py3-none-any.whl
.
File metadata
- Download URL: torchlop-0.2-py3-none-any.whl
- Upload date:
- Size: 8.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.30.0 CPython/3.6.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8eb2c716842b6ff9c0855be8670927428d002dabe0252dec600319c46583c5b8 |
|
MD5 | f984afb22b9935f3e299f57a8bcd2413 |
|
BLAKE2b-256 | e11b8699dd865d0c3cddace92724371036982da42b4bffb5919f4235c85453a0 |