{"id":20268961,"url":"https://github.com/1adrianb/pytorch-estimate-flops","last_synced_at":"2025-04-05T02:12:57.731Z","repository":{"id":44917118,"uuid":"169795977","full_name":"1adrianb/pytorch-estimate-flops","owner":"1adrianb","description":"Estimate/count FLOPS for a given neural network using pytorch","archived":false,"fork":false,"pushed_at":"2022-05-20T23:36:38.000Z","size":45,"stargazers_count":303,"open_issues_count":6,"forks_count":22,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-03-29T01:13:45.298Z","etag":null,"topics":["convolutional-neural-networks","deep-learning","flops","pytorch","pytorch-estimate-flops"],"latest_commit_sha":null,"homepage":"https://www.adrianbulat.com","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/1adrianb.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-02-08T20:40:01.000Z","updated_at":"2025-03-11T06:29:55.000Z","dependencies_parsed_at":"2022-09-05T17:42:21.265Z","dependency_job_id":null,"html_url":"https://github.com/1adrianb/pytorch-estimate-flops","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/1adrianb%2Fpytorch-estimate-flops","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/1adrianb%2Fpytorch-estimate-flops/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/1adrianb%2Fpytorch-estimate-flops/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/1adrianb%2Fpytorch-estimate-flops/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/1adrianb","download_url":"https://codeload.github.com/1adrianb/pytorch-estimate-flops/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247276189,"owners_count":20912288,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["convolutional-neural-networks","deep-learning","flops","pytorch","pytorch-estimate-flops"],"created_at":"2024-11-14T12:22:01.409Z","updated_at":"2025-04-05T02:12:57.715Z","avatar_url":"https://github.com/1adrianb.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![License](https://img.shields.io/badge/License-BSD%203--Clause-blue.svg)](https://opensource.org/licenses/BSD-3-Clause)  [![Test Pytorch Flops Counter](https://github.com/1adrianb/pytorch-estimate-flops/workflows/Test%20Pytorch%20Flops%20Counter/badge.svg)](https://travis-ci.com/1adrianb/pytorch-estimate-flops)\n[![PyPI](https://img.shields.io/pypi/v/pthflops.svg?style=flat)](https://pypi.org/project/pthflops/)\n\n# pytorch-estimate-flops\n\nSimple pytorch utility that estimates the number of FLOPs for a given network. For now only some basic operations are supported (basically the ones I needed for my models). More will be added soon.\n\nAll contributions are welcomed.\n\n## Installation\n\nYou can install the model using pip:\n\n```bash\npip install pthflops\n```\nor directly from the github repository:\n```bash\ngit clone https://github.com/1adrianb/pytorch-estimate-flops \u0026\u0026 cd pytorch-estimate-flops\npython setup.py install\n```\n\nNote: pytorch 1.8 or newer is recommended.\n\n## Example\n\n```python\nimport torch\nfrom torchvision.models import resnet18\n\nfrom pthflops import count_ops\n\n# Create a network and a corresponding input\ndevice = 'cuda:0'\nmodel = resnet18().to(device)\ninp = torch.rand(1,3,224,224).to(device)\n\n# Count the number of FLOPs\ncount_ops(model, inp)\n```\n\nIgnoring certain layers:\n\n```python\nimport torch\nfrom torch import nn\nfrom pthflops import count_ops\n\nclass CustomLayer(nn.Module):\n    def __init__(self):\n        super(CustomLayer, self).__init__()\n        self.conv1 = nn.Conv2d(5, 5, 1, 1, 0)\n        # ... other layers present inside will also be ignored\n\n    def forward(self, x):\n        return self.conv1(x)\n\n# Create a network and a corresponding input\ninp = torch.rand(1,5,7,7)\nnet = nn.Sequential(\n    nn.Conv2d(5, 5, 1, 1, 0),\n    nn.ReLU(inplace=True),\n    CustomLayer()\n)\n\n# Count the number of FLOPs, jit mode:\ncount_ops(net, inp, ignore_layers=['CustomLayer'])\n\n# Note: if you are using python 1.8 or newer with fx instead of jit, the naming convention changed. As such, you will have to pass ['_2_conv1']\n# Please check your model definition to account for this.\n# Count the number of FLOPs, fx mode:\ncount_ops(net, inp, ignore_layers=['_2_conv1'])\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F1adrianb%2Fpytorch-estimate-flops","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F1adrianb%2Fpytorch-estimate-flops","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F1adrianb%2Fpytorch-estimate-flops/lists"}