{"id":13689541,"url":"https://github.com/sksq96/pytorch-summary","last_synced_at":"2025-05-13T21:07:29.967Z","repository":{"id":38194629,"uuid":"130704865","full_name":"sksq96/pytorch-summary","owner":"sksq96","description":"Model summary in PyTorch similar to `model.summary()` in Keras","archived":false,"fork":false,"pushed_at":"2024-03-02T15:10:25.000Z","size":44,"stargazers_count":4038,"open_issues_count":139,"forks_count":415,"subscribers_count":35,"default_branch":"master","last_synced_at":"2025-04-28T13:59:17.729Z","etag":null,"topics":["deep-learning","keras","pytorch","summary"],"latest_commit_sha":null,"homepage":null,"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/sksq96.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-04-23T13:58:04.000Z","updated_at":"2025-04-23T05:38:51.000Z","dependencies_parsed_at":"2022-07-14T03:50:31.676Z","dependency_job_id":"a1c404e3-279a-4f2b-b17f-277aff43279c","html_url":"https://github.com/sksq96/pytorch-summary","commit_stats":{"total_commits":46,"total_committers":12,"mean_commits":"3.8333333333333335","dds":0.4565217391304348,"last_synced_commit":"345d898d84507b848e92dab4629e03405e19afce"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sksq96%2Fpytorch-summary","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sksq96%2Fpytorch-summary/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sksq96%2Fpytorch-summary/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sksq96%2Fpytorch-summary/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sksq96","download_url":"https://codeload.github.com/sksq96/pytorch-summary/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254028815,"owners_count":22002279,"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":["deep-learning","keras","pytorch","summary"],"created_at":"2024-08-02T15:01:51.901Z","updated_at":"2025-05-13T21:07:24.957Z","avatar_url":"https://github.com/sksq96.png","language":"Python","funding_links":[],"categories":["Python","Pytorch \u0026 related libraries｜Pytorch \u0026 相关库","Pytorch \u0026 related libraries","Pytorch实用程序","实用工具","Model Analyzer"],"sub_categories":["Other libraries｜其他库:","Other libraries:","**[Tutorials/Blogs]**"],"readme":"## Use the new and updated [torchinfo](https://github.com/TylerYep/torchinfo).\n\n## Keras style `model.summary()` in PyTorch\n[![PyPI version](https://badge.fury.io/py/torchsummary.svg)](https://badge.fury.io/py/torchsummary)\n\nKeras has a neat API to view the visualization of the model which is very helpful while debugging your network. Here is a barebone code to try and mimic the same in PyTorch. The aim is to provide information complementary to, what is not provided by `print(your_model)` in PyTorch.\n\n### Usage\n\n- `pip install torchsummary` or \n- `git clone https://github.com/sksq96/pytorch-summary`\n\n```python\nfrom torchsummary import summary\nsummary(your_model, input_size=(channels, H, W))\n```\n\n- Note that the `input_size` is required to make a forward pass through the network.\n\n### Examples\n\n#### CNN for MNIST\n\n\n```python\nimport torch\nimport torch.nn as nn\nimport torch.nn.functional as F\nfrom torchsummary import summary\n\nclass Net(nn.Module):\n    def __init__(self):\n        super(Net, self).__init__()\n        self.conv1 = nn.Conv2d(1, 10, kernel_size=5)\n        self.conv2 = nn.Conv2d(10, 20, kernel_size=5)\n        self.conv2_drop = nn.Dropout2d()\n        self.fc1 = nn.Linear(320, 50)\n        self.fc2 = nn.Linear(50, 10)\n\n    def forward(self, x):\n        x = F.relu(F.max_pool2d(self.conv1(x), 2))\n        x = F.relu(F.max_pool2d(self.conv2_drop(self.conv2(x)), 2))\n        x = x.view(-1, 320)\n        x = F.relu(self.fc1(x))\n        x = F.dropout(x, training=self.training)\n        x = self.fc2(x)\n        return F.log_softmax(x, dim=1)\n\ndevice = torch.device(\"cuda\" if torch.cuda.is_available() else \"cpu\") # PyTorch v0.4.0\nmodel = Net().to(device)\n\nsummary(model, (1, 28, 28))\n```\n\n\n```\n----------------------------------------------------------------\n        Layer (type)               Output Shape         Param #\n================================================================\n            Conv2d-1           [-1, 10, 24, 24]             260\n            Conv2d-2             [-1, 20, 8, 8]           5,020\n         Dropout2d-3             [-1, 20, 8, 8]               0\n            Linear-4                   [-1, 50]          16,050\n            Linear-5                   [-1, 10]             510\n================================================================\nTotal params: 21,840\nTrainable params: 21,840\nNon-trainable params: 0\n----------------------------------------------------------------\nInput size (MB): 0.00\nForward/backward pass size (MB): 0.06\nParams size (MB): 0.08\nEstimated Total Size (MB): 0.15\n----------------------------------------------------------------\n```\n\n\n#### VGG16\n\n\n```python\nimport torch\nfrom torchvision import models\nfrom torchsummary import summary\n\ndevice = torch.device('cuda' if torch.cuda.is_available() else 'cpu')\nvgg = models.vgg16().to(device)\n\nsummary(vgg, (3, 224, 224))\n```\n\n\n```\n----------------------------------------------------------------\n        Layer (type)               Output Shape         Param #\n================================================================\n            Conv2d-1         [-1, 64, 224, 224]           1,792\n              ReLU-2         [-1, 64, 224, 224]               0\n            Conv2d-3         [-1, 64, 224, 224]          36,928\n              ReLU-4         [-1, 64, 224, 224]               0\n         MaxPool2d-5         [-1, 64, 112, 112]               0\n            Conv2d-6        [-1, 128, 112, 112]          73,856\n              ReLU-7        [-1, 128, 112, 112]               0\n            Conv2d-8        [-1, 128, 112, 112]         147,584\n              ReLU-9        [-1, 128, 112, 112]               0\n        MaxPool2d-10          [-1, 128, 56, 56]               0\n           Conv2d-11          [-1, 256, 56, 56]         295,168\n             ReLU-12          [-1, 256, 56, 56]               0\n           Conv2d-13          [-1, 256, 56, 56]         590,080\n             ReLU-14          [-1, 256, 56, 56]               0\n           Conv2d-15          [-1, 256, 56, 56]         590,080\n             ReLU-16          [-1, 256, 56, 56]               0\n        MaxPool2d-17          [-1, 256, 28, 28]               0\n           Conv2d-18          [-1, 512, 28, 28]       1,180,160\n             ReLU-19          [-1, 512, 28, 28]               0\n           Conv2d-20          [-1, 512, 28, 28]       2,359,808\n             ReLU-21          [-1, 512, 28, 28]               0\n           Conv2d-22          [-1, 512, 28, 28]       2,359,808\n             ReLU-23          [-1, 512, 28, 28]               0\n        MaxPool2d-24          [-1, 512, 14, 14]               0\n           Conv2d-25          [-1, 512, 14, 14]       2,359,808\n             ReLU-26          [-1, 512, 14, 14]               0\n           Conv2d-27          [-1, 512, 14, 14]       2,359,808\n             ReLU-28          [-1, 512, 14, 14]               0\n           Conv2d-29          [-1, 512, 14, 14]       2,359,808\n             ReLU-30          [-1, 512, 14, 14]               0\n        MaxPool2d-31            [-1, 512, 7, 7]               0\n           Linear-32                 [-1, 4096]     102,764,544\n             ReLU-33                 [-1, 4096]               0\n          Dropout-34                 [-1, 4096]               0\n           Linear-35                 [-1, 4096]      16,781,312\n             ReLU-36                 [-1, 4096]               0\n          Dropout-37                 [-1, 4096]               0\n           Linear-38                 [-1, 1000]       4,097,000\n================================================================\nTotal params: 138,357,544\nTrainable params: 138,357,544\nNon-trainable params: 0\n----------------------------------------------------------------\nInput size (MB): 0.57\nForward/backward pass size (MB): 218.59\nParams size (MB): 527.79\nEstimated Total Size (MB): 746.96\n----------------------------------------------------------------\n```\n\n\n#### Multiple Inputs\n\n\n```python\nimport torch\nimport torch.nn as nn\nfrom torchsummary import summary\n\nclass SimpleConv(nn.Module):\n    def __init__(self):\n        super(SimpleConv, self).__init__()\n        self.features = nn.Sequential(\n            nn.Conv2d(1, 1, kernel_size=3, stride=1, padding=1),\n            nn.ReLU(),\n        )\n\n    def forward(self, x, y):\n        x1 = self.features(x)\n        x2 = self.features(y)\n        return x1, x2\n    \ndevice = torch.device(\"cuda\" if torch.cuda.is_available() else \"cpu\")\nmodel = SimpleConv().to(device)\n\nsummary(model, [(1, 16, 16), (1, 28, 28)])\n```\n\n\n```\n----------------------------------------------------------------\n        Layer (type)               Output Shape         Param #\n================================================================\n            Conv2d-1            [-1, 1, 16, 16]              10\n              ReLU-2            [-1, 1, 16, 16]               0\n            Conv2d-3            [-1, 1, 28, 28]              10\n              ReLU-4            [-1, 1, 28, 28]               0\n================================================================\nTotal params: 20\nTrainable params: 20\nNon-trainable params: 0\n----------------------------------------------------------------\nInput size (MB): 0.77\nForward/backward pass size (MB): 0.02\nParams size (MB): 0.00\nEstimated Total Size (MB): 0.78\n----------------------------------------------------------------\n```\n\n\n\n### References\n\n- The idea for this package sparked from [this PyTorch issue](https://github.com/pytorch/pytorch/issues/2001).\n- Thanks to @ncullen93 and @HTLife. \n- For Model Size Estimation @jacobkimmel ([details here](https://github.com/sksq96/pytorch-summary/pull/21))\n\n### License\n\n`pytorch-summary` is MIT-licensed.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsksq96%2Fpytorch-summary","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsksq96%2Fpytorch-summary","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsksq96%2Fpytorch-summary/lists"}