{"id":13564793,"url":"https://github.com/Lyken17/pytorch-OpCounter","last_synced_at":"2025-04-03T21:31:45.318Z","repository":{"id":37663532,"uuid":"119014048","full_name":"Lyken17/pytorch-OpCounter","owner":"Lyken17","description":"Count the MACs / FLOPs of your PyTorch model.","archived":false,"fork":false,"pushed_at":"2024-07-08T06:44:15.000Z","size":177,"stargazers_count":4974,"open_issues_count":84,"forks_count":531,"subscribers_count":29,"default_branch":"master","last_synced_at":"2025-04-01T16:13:30.434Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Lyken17.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-01-26T06:20:22.000Z","updated_at":"2025-03-31T02:14:58.000Z","dependencies_parsed_at":"2022-07-14T08:18:12.626Z","dependency_job_id":"c197a5d2-2ab0-42aa-85da-ac29c01f83de","html_url":"https://github.com/Lyken17/pytorch-OpCounter","commit_stats":{"total_commits":159,"total_committers":24,"mean_commits":6.625,"dds":0.6729559748427674,"last_synced_commit":"43c064afb71383501e41eaef9e8c8407265cf77f"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Lyken17%2Fpytorch-OpCounter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Lyken17%2Fpytorch-OpCounter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Lyken17%2Fpytorch-OpCounter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Lyken17%2Fpytorch-OpCounter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Lyken17","download_url":"https://codeload.github.com/Lyken17/pytorch-OpCounter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247083693,"owners_count":20880893,"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":[],"created_at":"2024-08-01T13:01:36.022Z","updated_at":"2025-04-03T21:31:45.299Z","avatar_url":"https://github.com/Lyken17.png","language":"Python","funding_links":[],"categories":["Python","Pytorch \u0026 related libraries｜Pytorch \u0026 相关库","Pytorch \u0026 related libraries","实用工具","Model Analyzer"],"sub_categories":["Other libraries｜其他库:","Other libraries:","**[Tutorials/Blogs]**"],"readme":"# THOP: PyTorch-OpCounter\n\n## How to install \n    \n`pip install thop` (now continously intergrated on [Github actions](https://github.com/features/actions))\n\nOR\n\n`pip install --upgrade git+https://github.com/Lyken17/pytorch-OpCounter.git`\n    \n## How to use \n* Basic usage \n    ```python\n    from torchvision.models import resnet50\n    from thop import profile\n    model = resnet50()\n    input = torch.randn(1, 3, 224, 224)\n    macs, params = profile(model, inputs=(input, ))\n    ```    \n\n* Define the rule for 3rd party module.\n    ```python\n    class YourModule(nn.Module):\n        # your definition\n    def count_your_model(model, x, y):\n        # your rule here\n    \n    input = torch.randn(1, 3, 224, 224)\n    macs, params = profile(model, inputs=(input, ), \n                            custom_ops={YourModule: count_your_model})\n    ```\n    \n* Improve the output readability\n\n    Call `thop.clever_format` to give a better format of the output.\n    ```python\n    from thop import clever_format\n    macs, params = clever_format([macs, params], \"%.3f\")\n    ```    \n    \n## Results of Recent Models\n\nThe implementation are adapted from `torchvision`. Following results can be obtained using [benchmark/evaluate_famous_models.py](benchmark/evaluate_famous_models.py).\n\n\u003cp align=\"center\"\u003e\n\u003ctable\u003e\n\u003ctr\u003e\n\u003ctd\u003e\n\nModel | Params(M) | MACs(G)\n---|---|---\nalexnet | 61.10 | 0.77\nvgg11 | 132.86 | 7.74\nvgg11_bn | 132.87 | 7.77\nvgg13 | 133.05 | 11.44\nvgg13_bn | 133.05 | 11.49\nvgg16 | 138.36 | 15.61\nvgg16_bn | 138.37 | 15.66\nvgg19 | 143.67 | 19.77\nvgg19_bn | 143.68 | 19.83\nresnet18 | 11.69 | 1.82\nresnet34 | 21.80 | 3.68\nresnet50 | 25.56 | 4.14\nresnet101 | 44.55 | 7.87\nresnet152 | 60.19 | 11.61\nwide_resnet101_2 | 126.89 | 22.84\nwide_resnet50_2 | 68.88 | 11.46\n\n\u003c/td\u003e\n\u003ctd\u003e\n\nModel | Params(M) | MACs(G)\n---|---|---\nresnext50_32x4d | 25.03 | 4.29\nresnext101_32x8d | 88.79 | 16.54\ndensenet121 | 7.98 | 2.90\ndensenet161 | 28.68 | 7.85\ndensenet169 | 14.15 | 3.44\ndensenet201 | 20.01 | 4.39\nsqueezenet1_0 | 1.25 | 0.82\nsqueezenet1_1 | 1.24 | 0.35\nmnasnet0_5 | 2.22 | 0.14\nmnasnet0_75 | 3.17 | 0.24\nmnasnet1_0 | 4.38 | 0.34\nmnasnet1_3 | 6.28 | 0.53\nmobilenet_v2 | 3.50 | 0.33\nshufflenet_v2_x0_5 | 1.37 | 0.05\nshufflenet_v2_x1_0 | 2.28 | 0.15\nshufflenet_v2_x1_5 | 3.50 | 0.31\nshufflenet_v2_x2_0 | 7.39 | 0.60\ninception_v3 | 27.16 | 5.75\n\n\u003c/td\u003e\n\u003c/tr\u003e\n\u003c/p\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FLyken17%2Fpytorch-OpCounter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FLyken17%2Fpytorch-OpCounter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FLyken17%2Fpytorch-OpCounter/lists"}