{"id":15418850,"url":"https://github.com/gsauc3/pytorch-model-details","last_synced_at":"2026-04-25T21:31:56.038Z","repository":{"id":54343197,"uuid":"522184945","full_name":"GSAUC3/pytorch-model-details","owner":"GSAUC3","description":"Package to visualize all the layer parameters of a deep learning model. ","archived":false,"fork":false,"pushed_at":"2022-09-03T18:09:10.000Z","size":51,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-31T06:19:43.492Z","etag":null,"topics":["cnn-model","deep-learning","deep-neural-networks","model-summary","pytorch","summary"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/pytorchsummary/","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/GSAUC3.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"license.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-08-07T10:45:51.000Z","updated_at":"2023-12-03T08:50:34.000Z","dependencies_parsed_at":"2022-08-13T12:40:31.749Z","dependency_job_id":null,"html_url":"https://github.com/GSAUC3/pytorch-model-details","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GSAUC3%2Fpytorch-model-details","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GSAUC3%2Fpytorch-model-details/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GSAUC3%2Fpytorch-model-details/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GSAUC3%2Fpytorch-model-details/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/GSAUC3","download_url":"https://codeload.github.com/GSAUC3/pytorch-model-details/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239801646,"owners_count":19699380,"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":["cnn-model","deep-learning","deep-neural-networks","model-summary","pytorch","summary"],"created_at":"2024-10-01T17:22:49.733Z","updated_at":"2026-02-09T15:30:18.442Z","avatar_url":"https://github.com/GSAUC3.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PyTorch Model Parameters Summary\n\n#### Install using pip\n```\npip install pytorchsummary\n```\n## WORKS ON CNNs and MLPs\n\nNOTE: `summary()` function returns a Tuple like `(Total_trainable_params, Total_parameters, Total_non_trainable_params)`\n\n## Example 1\n\n```python\nfrom torch import nn\nfrom pytorchsummary import summary\n\nclass CNNET(nn.Module):\n    def __init__(self):\n        super(CNNET,self).__init__()\n\n        self.layer = nn.Sequential(\n            nn.Conv2d(3,16,5), # 28-5+1\n            nn.ReLU(), #24\n            nn.MaxPool2d(2,2), # 12\n\n            nn.Conv2d(16,32,3), # 12+1-3\n            nn.ReLU(), # 10\n            nn.MaxPool2d(2,2), # 5\n            \n\n            nn.Conv2d(32,64,5), # 11-3+1\n            nn.ReLU(),\n\n            nn.Conv2d(64,10,1)   \n        )\n    \n    def forward(self,x):\n        x = self.layer(x)\n        return x\n\nm = CNNET()\nsummary((3,128,128),m) \n```\n\n### Output\n```               Layer\tOutput Shape        \t    Kernal Shape    \t#params             \t#(weights + bias)   \trequires_grad\n------------------------------------------------------------------------------------------------------------------------------------------------------\n            Conv2d-1\t[1, 16, 124, 124]   \t   [16, 3, 5, 5]    \t1216                \t(1200 + 16)         \tTrue True \n              ReLU-2\t[1, 16, 124, 124]   \t                    \t                    \t                    \t          \n         MaxPool2d-3\t[1, 16, 62, 62]     \t                    \t                    \t                    \t          \n            Conv2d-4\t[1, 32, 60, 60]     \t   [32, 16, 3, 3]   \t4640                \t(4608 + 32)         \tTrue True \n              ReLU-5\t[1, 32, 60, 60]     \t                    \t                    \t                    \t          \n         MaxPool2d-6\t[1, 32, 30, 30]     \t                    \t                    \t                    \t          \n            Conv2d-7\t[1, 64, 26, 26]     \t   [64, 32, 5, 5]   \t51264               \t(51200 + 64)        \tTrue True \n              ReLU-8\t[1, 64, 26, 26]     \t                    \t                    \t                    \t          \n            Conv2d-9\t[1, 10, 26, 26]     \t   [10, 64, 1, 1]   \t650                 \t(640 + 10)          \tTrue True \n______________________________________________________________________________________________________________________________________________________\n\nTotal parameters 57,770\nTotal Non-Trainable parameters 0\nTotal Trainable parameters 57,770\n(57770, 57770, 0)\n```\n\n```python\nfor i,j in enumerate(m.parameters()):\n    if i==2:\n        break\n    j.requires_grad=False \nsummary((3,128,128),m,border=True) \n\n```\n```\n              Layer\tOutput Shape        \t    Kernal Shape    \t#params             \t#(weights + bias)   \trequires_grad\n------------------------------------------------------------------------------------------------------------------------------------------------------\n            Conv2d-1\t[1, 16, 124, 124]   \t   [16, 3, 5, 5]    \t1216                \t(1200 + 16)         \tFalse False\n______________________________________________________________________________________________________________________________________________________\n              ReLU-2\t[1, 16, 124, 124]   \t                    \t                    \t                    \t          \n______________________________________________________________________________________________________________________________________________________\n         MaxPool2d-3\t[1, 16, 62, 62]     \t                    \t                    \t                    \t          \n______________________________________________________________________________________________________________________________________________________\n            Conv2d-4\t[1, 32, 60, 60]     \t   [32, 16, 3, 3]   \t4640                \t(4608 + 32)         \tTrue True \n______________________________________________________________________________________________________________________________________________________\n              ReLU-5\t[1, 32, 60, 60]     \t                    \t                    \t                    \t          \n______________________________________________________________________________________________________________________________________________________\n         MaxPool2d-6\t[1, 32, 30, 30]     \t                    \t                    \t                    \t          \n______________________________________________________________________________________________________________________________________________________\n            Conv2d-7\t[1, 64, 26, 26]     \t   [64, 32, 5, 5]   \t51264               \t(51200 + 64)        \tTrue True \n______________________________________________________________________________________________________________________________________________________\n              ReLU-8\t[1, 64, 26, 26]     \t                    \t                    \t                    \t          \n______________________________________________________________________________________________________________________________________________________\n            Conv2d-9\t[1, 10, 26, 26]     \t   [10, 64, 1, 1]   \t650                 \t(640 + 10)          \tTrue True \n______________________________________________________________________________________________________________________________________________________\n______________________________________________________________________________________________________________________________________________________\n\nTotal parameters 57,770\nTotal Non-Trainable parameters 1,216\nTotal Trainable parameters 56,554\n(56554, 57770, 1216)\n```\n\n\n\n## Example 2\n```python\nfrom torchvision import models\nfrom pytorchsummary import summary\n\nm = models.alexnet(False)\nsummary((3,224,224),m)\n# this function returns the total number of \n# parameters (int) in a model\n```\n### ouput\n```\n               Layer\tOutput Shape        \t    Kernal Shape    \t#params             \t#(weights + bias)   \trequires_grad\n------------------------------------------------------------------------------------------------------------------------------------------------------\n            Conv2d-1\t[1, 64, 55, 55]     \t  [64, 3, 11, 11]   \t23296               \t(23232 + 64)        \tTrue True \n              ReLU-2\t[1, 64, 55, 55]     \t                    \t                    \t                    \t          \n         MaxPool2d-3\t[1, 64, 27, 27]     \t                    \t                    \t                    \t          \n            Conv2d-4\t[1, 192, 27, 27]    \t  [192, 64, 5, 5]   \t307392              \t(307200 + 192)      \tTrue True \n              ReLU-5\t[1, 192, 27, 27]    \t                    \t                    \t                    \t          \n         MaxPool2d-6\t[1, 192, 13, 13]    \t                    \t                    \t                    \t          \n            Conv2d-7\t[1, 384, 13, 13]    \t  [384, 192, 3, 3]  \t663936              \t(663552 + 384)      \tTrue True \n              ReLU-8\t[1, 384, 13, 13]    \t                    \t                    \t                    \t          \n            Conv2d-9\t[1, 256, 13, 13]    \t  [256, 384, 3, 3]  \t884992              \t(884736 + 256)      \tTrue True \n             ReLU-10\t[1, 256, 13, 13]    \t                    \t                    \t                    \t          \n           Conv2d-11\t[1, 256, 13, 13]    \t  [256, 256, 3, 3]  \t590080              \t(589824 + 256)      \tTrue True \n             ReLU-12\t[1, 256, 13, 13]    \t                    \t                    \t                    \t          \n        MaxPool2d-13\t[1, 256, 6, 6]      \t                    \t                    \t                    \t          \nAdaptiveAvgPool2d-14\t[1, 256, 6, 6]      \t                    \t                    \t                    \t          \n          Dropout-15\t[1, 9216]           \t                    \t                    \t                    \t          \n           Linear-16\t[1, 4096]           \t    [4096, 9216]    \t37752832            \t(37748736 + 4096)   \tTrue True \n             ReLU-17\t[1, 4096]           \t                    \t                    \t                    \t          \n          Dropout-18\t[1, 4096]           \t                    \t                    \t                    \t          \n           Linear-19\t[1, 4096]           \t    [4096, 4096]    \t16781312            \t(16777216 + 4096)   \tTrue True \n             ReLU-20\t[1, 4096]           \t                    \t                    \t                    \t          \n           Linear-21\t[1, 1000]           \t    [1000, 4096]    \t4097000             \t(4096000 + 1000)    \tTrue True \n______________________________________________________________________________________________________________________________________________________\n\nTotal parameters 61,100,840\nTotal Non-Trainable parameters 0\nTotal Trainable parameters 61,100,840\n(61100840, 61100840, 0)\n```\n\n### Calculating the number of specific layer, or layer frequencies\n```python\nfrom pytorchsummary import get_num_layers\nprint(get_num_layers(m)) # alexnet model \n```\nOutput:\n```\n{'Conv2d': 5,\n 'ReLU': 7,\n 'MaxPool2d': 3,\n 'AdaptiveAvgPool2d': 1,\n 'Dropout': 2,\n 'Linear': 3}\n ```\n\n\n# Example For MLPs\n\n```python\n\nfrom pytorchsummary import summary\nfrom torch import nn\n\nclass Net(nn.Module):\n  def __init__(self):\n    super(Net,self).__init__()\n    self.l = nn.Sequential(\n        nn.Linear(18,16),\n        nn.ReLU(),\n        nn.Linear(16,8),\n        nn.ReLU(),\n        nn.Linear(8,4)\n    )\n  def forward(self,x):\n    return self.l(x)\n  \nmodel = Net()\nsummary((18,),model) \n\n```\n`summary()` function takes inputsize as a tuple so\n**if len(input_size)==1**\nyou have to use `,` like this\n`((input_size,))`\n\nOtherwise it will throw an error\n\n### output\n```\n               Layer\tOutput Shape        \t    Kernal Shape    \t#params             \t#(weights + bias)   \trequires_grad\n------------------------------------------------------------------------------------------------------------------------------------------------------\n            Linear-1\t[1, 16]             \t      [16, 18]      \t304                 \t(288 + 16)          \tTrue True \n              ReLU-2\t[1, 16]             \t                    \t                    \t                    \t          \n            Linear-3\t[1, 8]              \t      [8, 16]       \t136                 \t(128 + 8)           \tTrue True \n              ReLU-4\t[1, 8]              \t                    \t                    \t                    \t          \n            Linear-5\t[1, 4]              \t       [4, 8]       \t36                  \t(32 + 4)            \tTrue True \n______________________________________________________________________________________________________________________________________________________\n\nTotal parameters 476\nTotal Non-Trainable parameters 0\nTotal Trainable parameters 476\n(476, 476, 0)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgsauc3%2Fpytorch-model-details","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgsauc3%2Fpytorch-model-details","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgsauc3%2Fpytorch-model-details/lists"}