torch-summary


Nametorch-summary JSON
Version 1.4.5 PyPI version JSON
download
home_pagehttps://github.com/tyleryep/torchinfo
SummaryModel summary in PyTorch, based off of the original torchsummary.
upload_time2020-12-24 05:00:32
maintainer
docs_urlNone
authorTyler Yep @tyleryep
requires_python>=3.6
licenseMIT
keywords torch pytorch torchsummary torch-summary summary keras deep-learning ml torchinfo torch-info visualize model statistics layer
VCS
bugtrack_url
requirements torch torchvision numpy
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # torchinfo
[![Python 3.6+](https://img.shields.io/badge/python-3.6+-blue.svg)](https://www.python.org/downloads/release/python-360/)
[![PyPI version](https://badge.fury.io/py/torch-summary.svg)](https://badge.fury.io/py/torch-summary)
[![Build Status](https://travis-ci.org/TylerYep/torch-summary.svg?branch=master)](https://travis-ci.org/TylerYep/torch-summary)
[![GitHub license](https://img.shields.io/github/license/TylerYep/torch-summary)](https://github.com/TylerYep/torch-summary/blob/master/LICENSE)
[![codecov](https://codecov.io/gh/TylerYep/torch-summary/branch/master/graph/badge.svg)](https://codecov.io/gh/TylerYep/torch-summary)
[![Downloads](https://pepy.tech/badge/torch-summary)](https://pepy.tech/project/torch-summary)

### Announcement: We have moved to `torchinfo`!
`torch-summary` has been renamed to `torchinfo`! Nearly all of the functionality is the same, but the new name will allow us to develop and experiment with additional new features. All links now redirect to `torchinfo`, so please leave an issue there if you have any questions.

The `torch-summary` package will continue to exist for the foreseeable future, so please feel free to pin your desired version (`1.4.3` for Python 3.5, `1.4.4+` for everything else), or try out `torchinfo`. Thanks!

## torch-summary

Torch-summary provides information complementary to what is provided by `print(your_model)` in PyTorch, similar to Tensorflow's `model.summary()` API to view the visualization of the model, which is helpful while debugging your network. In this project, we implement a similar functionality in PyTorch and create a clean, simple interface to use in your projects.

This is a completely rewritten version of the original torchsummary and torchsummaryX projects by @sksq96 and @nmhkahn. This project addresses all of the issues and pull requests left on the original projects by introducing a completely new API.

# Usage
`pip install torch-summary`

# How To Use
```python
from torchsummary import summary

model = ConvNet()
summary(model, (1, 28, 28))
```
```
==========================================================================================
Layer (type:depth-idx)                   Output Shape              Param #
==========================================================================================
├─Conv2d: 1-1                            [-1, 10, 24, 24]          260
├─Conv2d: 1-2                            [-1, 20, 8, 8]            5,020
├─Dropout2d: 1-3                         [-1, 20, 8, 8]            --
├─Linear: 1-4                            [-1, 50]                  16,050
├─Linear: 1-5                            [-1, 10]                  510
==========================================================================================
Total params: 21,840
Trainable params: 21,840
Non-trainable params: 0
==========================================================================================
Input size (MB): 0.00
Forward/backward pass size (MB): 0.05
Params size (MB): 0.08
Estimated Total Size (MB): 0.14
==========================================================================================
```

**This version now supports:**
- RNNs, LSTMs, and other recursive layers
- Sequentials & Module Lists
- Branching output used to explore model layers using specified depths
- Returns ModelStatistics object containing all summary data fields
- Configurable columns

**Other new features:**
- Verbose mode to show weights and bias layers
- Accepts either input data or simply the input shape!
- Customizable widths and batch dimension
- Comprehensive unit/output testing, linting, and code coverage testing


# Documentation
```python
"""
Summarize the given PyTorch model. Summarized information includes:
    1) Layer names,
    2) input/output shapes,
    3) kernel shape,
    4) # of parameters,
    5) # of operations (Mult-Adds)

Args:
    model (nn.Module):
            PyTorch model to summarize. The model should be fully in either train()
            or eval() mode. If layers are not all in the same mode, running summary
            may have side effects on batchnorm or dropout statistics. If you
            encounter an issue with this, please open a GitHub issue.

    input_data (Sequence of Sizes or Tensors):
            Example input tensor of the model (dtypes inferred from model input).
            - OR -
            Shape of input data as a List/Tuple/torch.Size
            (dtypes must match model input, default is FloatTensors).
            You should NOT include batch size in the tuple.
            - OR -
            If input_data is not provided, no forward pass through the network is
            performed, and the provided model information is limited to layer names.
            Default: None

    batch_dim (int):
            Batch_dimension of input data. If batch_dim is None, the input data
            is assumed to contain the batch dimension.
            WARNING: in a future version, the default will change to None.
            Default: 0

    branching (bool):
            Whether to use the branching layout for the printed output.
            Default: True

    col_names (Iterable[str]):
            Specify which columns to show in the output. Currently supported:
            ("input_size", "output_size", "num_params", "kernel_size", "mult_adds")
            If input_data is not provided, only "num_params" is used.
            Default: ("output_size", "num_params")

    col_width (int):
            Width of each column.
            Default: 25

    depth (int):
            Number of nested layers to traverse (e.g. Sequentials).
            Default: 3

    device (torch.Device):
            Uses this torch device for model and input_data.
            If not specified, uses result of torch.cuda.is_available().
            Default: None

    dtypes (List[torch.dtype]):
            For multiple inputs, specify the size of both inputs, and
            also specify the types of each parameter here.
            Default: None

    verbose (int):
            0 (quiet): No output
            1 (default): Print model summary
            2 (verbose): Show weight and bias layers in full detail
            Default: 1

    *args, **kwargs:
            Other arguments used in `model.forward` function.

Return:
    ModelStatistics object
            See torchsummary/model_statistics.py for more information.
"""
```

# Examples
## Get Model Summary as String
```python
from torchsummary import summary

model_stats = summary(your_model, (3, 28, 28), verbose=0)
summary_str = str(model_stats)
# summary_str contains the string representation of the summary. See below for examples.
```

## ResNet
```python
import torchvision

model = torchvision.models.resnet50()
summary(model, (3, 224, 224), depth=3)
```
```
==========================================================================================
Layer (type:depth-idx)                   Output Shape              Param #
==========================================================================================
├─Conv2d: 1-1                            [-1, 64, 112, 112]        9,408
├─BatchNorm2d: 1-2                       [-1, 64, 112, 112]        128
├─ReLU: 1-3                              [-1, 64, 112, 112]        --
├─MaxPool2d: 1-4                         [-1, 64, 56, 56]          --
├─Sequential: 1-5                        [-1, 256, 56, 56]         --
|    └─Bottleneck: 2-1                   [-1, 256, 56, 56]         --
|    |    └─Conv2d: 3-1                  [-1, 64, 56, 56]          4,096
|    |    └─BatchNorm2d: 3-2             [-1, 64, 56, 56]          128
|    |    └─ReLU: 3-3                    [-1, 64, 56, 56]          --
|    |    └─Conv2d: 3-4                  [-1, 64, 56, 56]          36,864
|    |    └─BatchNorm2d: 3-5             [-1, 64, 56, 56]          128
|    |    └─ReLU: 3-6                    [-1, 64, 56, 56]          --
|    |    └─Conv2d: 3-7                  [-1, 256, 56, 56]         16,384
|    |    └─BatchNorm2d: 3-8             [-1, 256, 56, 56]         512
|    |    └─Sequential: 3-9              [-1, 256, 56, 56]         --
|    |    └─ReLU: 3-10                   [-1, 256, 56, 56]         --

  ...
  ...
  ...

├─AdaptiveAvgPool2d: 1-9                 [-1, 2048, 1, 1]          --
├─Linear: 1-10                           [-1, 1000]                2,049,000
==========================================================================================
Total params: 60,192,808
Trainable params: 60,192,808
Non-trainable params: 0
Total mult-adds (G): 11.63
==========================================================================================
Input size (MB): 0.57
Forward/backward pass size (MB): 344.16
Params size (MB): 229.62
Estimated Total Size (MB): 574.35
==========================================================================================
```

## Multiple Inputs w/ Different Data Types
```python
class MultipleInputNetDifferentDtypes(nn.Module):
    def __init__(self):
        super().__init__()
        self.fc1a = nn.Linear(300, 50)
        self.fc1b = nn.Linear(50, 10)

        self.fc2a = nn.Linear(300, 50)
        self.fc2b = nn.Linear(50, 10)

    def forward(self, x1, x2):
        x1 = F.relu(self.fc1a(x1))
        x1 = self.fc1b(x1)
        x2 = x2.type(torch.float)
        x2 = F.relu(self.fc2a(x2))
        x2 = self.fc2b(x2)
        x = torch.cat((x1, x2), 0)
        return F.log_softmax(x, dim=1)

summary(model, [(1, 300), (1, 300)], dtypes=[torch.float, torch.long])
```
Alternatively, you can also pass in the input_data itself, and
torchsummary will automatically infer the data types.

```python
input_data = torch.randn(1, 300)
other_input_data = torch.randn(1, 300).long()
model = MultipleInputNetDifferentDtypes()

summary(model, input_data, other_input_data, ...)
```

## Explore Different Configurations
```python
class LSTMNet(nn.Module):
    """ Batch-first LSTM model. """
    def __init__(self, vocab_size=20, embed_dim=300, hidden_dim=512, num_layers=2):
        super().__init__()
        self.hidden_dim = hidden_dim
        self.embedding = nn.Embedding(vocab_size, embed_dim)
        self.encoder = nn.LSTM(embed_dim, hidden_dim, num_layers=num_layers, batch_first=True)
        self.decoder = nn.Linear(hidden_dim, vocab_size)

    def forward(self, x):
        embed = self.embedding(x)
        out, hidden = self.encoder(embed)
        out = self.decoder(out)
        out = out.view(-1, out.size(2))
        return out, hidden

summary(
    LSTMNet(),
    (100,),
    dtypes=[torch.long],
    branching=False,
    verbose=2,
    col_width=16,
    col_names=["kernel_size", "output_size", "num_params", "mult_adds"],
)
```
```
========================================================================================================================
Layer (type:depth-idx)                   Kernel Shape         Output Shape         Param #              Mult-Adds
========================================================================================================================
Embedding: 1-1                           [300, 20]            [-1, 100, 300]       6,000                6,000
LSTM: 1-2                                --                   [-1, 100, 512]        3,768,320            3,760,128
  weight_ih_l0                           [2048, 300]
  weight_hh_l0                           [2048, 512]
  weight_ih_l1                           [2048, 512]
  weight_hh_l1                           [2048, 512]
Linear: 1-3                              [512, 20]            [-1, 100, 20]        10,260               10,240
========================================================================================================================
Total params: 3,784,580
Trainable params: 3,784,580
Non-trainable params: 0
Total mult-adds (M): 3.78
========================================================================================================================
Input size (MB): 0.00
Forward/backward pass size (MB): 1.03
Params size (MB): 14.44
Estimated Total Size (MB): 15.46
========================================================================================================================
```

## Sequentials & ModuleLists
```python
class ContainerModule(nn.Module):
    """ Model using ModuleList. """

    def __init__(self):
        super().__init__()
        self._layers = nn.ModuleList()
        self._layers.append(nn.Linear(5, 5))
        self._layers.append(ContainerChildModule())
        self._layers.append(nn.Linear(5, 5))

    def forward(self, x):
        for layer in self._layers:
            x = layer(x)
        return x


class ContainerChildModule(nn.Module):
    """ Model using Sequential in different ways. """

    def __init__(self):
        super().__init__()
        self._sequential = nn.Sequential(nn.Linear(5, 5), nn.Linear(5, 5))
        self._between = nn.Linear(5, 5)

    def forward(self, x):
        out = self._sequential(x)
        out = self._between(out)
        for l in self._sequential:
            out = l(out)

        out = self._sequential(x)
        for l in self._sequential:
            out = l(out)
        return out

summary(ContainerModule(), (5,))
```
```
==========================================================================================
Layer (type:depth-idx)                   Output Shape              Param #
==========================================================================================
├─ModuleList: 1                          []                        --
|    └─Linear: 2-1                       [-1, 5]                   30
|    └─ContainerChildModule: 2-2         [-1, 5]                   --
|    |    └─Sequential: 3-1              [-1, 5]                   --
|    |    |    └─Linear: 4-1             [-1, 5]                   30
|    |    |    └─Linear: 4-2             [-1, 5]                   30
|    |    └─Linear: 3-2                  [-1, 5]                   30
|    |    └─Sequential: 3                []                        --
|    |    |    └─Linear: 4-3             [-1, 5]                   (recursive)
|    |    |    └─Linear: 4-4             [-1, 5]                   (recursive)
|    |    └─Sequential: 3-3              [-1, 5]                   (recursive)
|    |    |    └─Linear: 4-5             [-1, 5]                   (recursive)
|    |    |    └─Linear: 4-6             [-1, 5]                   (recursive)
|    |    |    └─Linear: 4-7             [-1, 5]                   (recursive)
|    |    |    └─Linear: 4-8             [-1, 5]                   (recursive)
|    └─Linear: 2-3                       [-1, 5]                   30
==========================================================================================
Total params: 150
Trainable params: 150
Non-trainable params: 0
Total mult-adds (M): 0.00
==========================================================================================
Input size (MB): 0.00
Forward/backward pass size (MB): 0.00
Params size (MB): 0.00
Estimated Total Size (MB): 0.00
==========================================================================================
```

# Other Examples
```
================================================================
        Layer (type)               Output Shape         Param #
================================================================
            Conv2d-1            [-1, 1, 16, 16]              10
              ReLU-2            [-1, 1, 16, 16]               0
            Conv2d-3            [-1, 1, 28, 28]              10
              ReLU-4            [-1, 1, 28, 28]               0
================================================================
Total params: 20
Trainable params: 20
Non-trainable params: 0
================================================================
Input size (MB): 0.77
Forward/backward pass size (MB): 0.02
Params size (MB): 0.00
Estimated Total Size (MB): 0.78
================================================================
```

# Future Plans
- Change project name to `torchinfo`. The API will eventually mature to the point that this project deserves its own name.
- Support all types of inputs - showing tuples and dict inputs cleanly rather than only using the first tensor in the list.
- Default `batch_dim` to `None` rather than `0`. Users must specify the batch size in the input shape, or pass in `batch_dim=0` in order to ignore it.
- FunctionalNet unused; figure out a way to hook into functional layers.

# Contributing
All issues and pull requests are much appreciated! If you are wondering how to build the project:

- torch-summary is actively developed using the lastest version of Python.
    - Changes should be backward compatible with Python 3.6, but this is subject to change in the future.
    - Run `pip install -r requirements-dev.txt`. We use the latest versions of all dev packages.
    - First, be sure to run `./scripts/install-hooks`
    - To run all tests and use auto-formatting tools, check out `scripts/run-tests`.
    - To only run unit tests, run `pytest`.

# References
- Thanks to @sksq96, @nmhkahn, and @sangyx for providing the original code this project was based off of.
- For Model Size Estimation @jacobkimmel ([details here](https://github.com/sksq96/pytorch-summary/pull/21))



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/tyleryep/torchinfo",
    "name": "torch-summary",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": "",
    "keywords": "torch pytorch torchsummary torch-summary summary keras deep-learning ml torchinfo torch-info visualize model statistics layer",
    "author": "Tyler Yep @tyleryep",
    "author_email": "tyep10@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/ff/2f/57cb3b23bccae7fc639ab7ff8bb78c80f03e8c0a144bbc69bfd26b0757f7/torch_summary-1.4.5.tar.gz",
    "platform": "",
    "description": "# torchinfo\n[![Python 3.6+](https://img.shields.io/badge/python-3.6+-blue.svg)](https://www.python.org/downloads/release/python-360/)\n[![PyPI version](https://badge.fury.io/py/torch-summary.svg)](https://badge.fury.io/py/torch-summary)\n[![Build Status](https://travis-ci.org/TylerYep/torch-summary.svg?branch=master)](https://travis-ci.org/TylerYep/torch-summary)\n[![GitHub license](https://img.shields.io/github/license/TylerYep/torch-summary)](https://github.com/TylerYep/torch-summary/blob/master/LICENSE)\n[![codecov](https://codecov.io/gh/TylerYep/torch-summary/branch/master/graph/badge.svg)](https://codecov.io/gh/TylerYep/torch-summary)\n[![Downloads](https://pepy.tech/badge/torch-summary)](https://pepy.tech/project/torch-summary)\n\n### Announcement: We have moved to `torchinfo`!\n`torch-summary` has been renamed to `torchinfo`! Nearly all of the functionality is the same, but the new name will allow us to develop and experiment with additional new features. All links now redirect to `torchinfo`, so please leave an issue there if you have any questions.\n\nThe `torch-summary` package will continue to exist for the foreseeable future, so please feel free to pin your desired version (`1.4.3` for Python 3.5, `1.4.4+` for everything else), or try out `torchinfo`. Thanks!\n\n## torch-summary\n\nTorch-summary provides information complementary to what is provided by `print(your_model)` in PyTorch, similar to Tensorflow's `model.summary()` API to view the visualization of the model, which is helpful while debugging your network. In this project, we implement a similar functionality in PyTorch and create a clean, simple interface to use in your projects.\n\nThis is a completely rewritten version of the original torchsummary and torchsummaryX projects by @sksq96 and @nmhkahn. This project addresses all of the issues and pull requests left on the original projects by introducing a completely new API.\n\n# Usage\n`pip install torch-summary`\n\n# How To Use\n```python\nfrom torchsummary import summary\n\nmodel = ConvNet()\nsummary(model, (1, 28, 28))\n```\n```\n==========================================================================================\nLayer (type:depth-idx)                   Output Shape              Param #\n==========================================================================================\n\u251c\u2500Conv2d: 1-1                            [-1, 10, 24, 24]          260\n\u251c\u2500Conv2d: 1-2                            [-1, 20, 8, 8]            5,020\n\u251c\u2500Dropout2d: 1-3                         [-1, 20, 8, 8]            --\n\u251c\u2500Linear: 1-4                            [-1, 50]                  16,050\n\u251c\u2500Linear: 1-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.05\nParams size (MB): 0.08\nEstimated Total Size (MB): 0.14\n==========================================================================================\n```\n\n**This version now supports:**\n- RNNs, LSTMs, and other recursive layers\n- Sequentials & Module Lists\n- Branching output used to explore model layers using specified depths\n- Returns ModelStatistics object containing all summary data fields\n- Configurable columns\n\n**Other new features:**\n- Verbose mode to show weights and bias layers\n- Accepts either input data or simply the input shape!\n- Customizable widths and batch dimension\n- Comprehensive unit/output testing, linting, and code coverage testing\n\n\n# Documentation\n```python\n\"\"\"\nSummarize the given PyTorch model. Summarized information includes:\n    1) Layer names,\n    2) input/output shapes,\n    3) kernel shape,\n    4) # of parameters,\n    5) # of operations (Mult-Adds)\n\nArgs:\n    model (nn.Module):\n            PyTorch model to summarize. The model should be fully in either train()\n            or eval() mode. If layers are not all in the same mode, running summary\n            may have side effects on batchnorm or dropout statistics. If you\n            encounter an issue with this, please open a GitHub issue.\n\n    input_data (Sequence of Sizes or Tensors):\n            Example input tensor of the model (dtypes inferred from model input).\n            - OR -\n            Shape of input data as a List/Tuple/torch.Size\n            (dtypes must match model input, default is FloatTensors).\n            You should NOT include batch size in the tuple.\n            - OR -\n            If input_data is not provided, no forward pass through the network is\n            performed, and the provided model information is limited to layer names.\n            Default: None\n\n    batch_dim (int):\n            Batch_dimension of input data. If batch_dim is None, the input data\n            is assumed to contain the batch dimension.\n            WARNING: in a future version, the default will change to None.\n            Default: 0\n\n    branching (bool):\n            Whether to use the branching layout for the printed output.\n            Default: True\n\n    col_names (Iterable[str]):\n            Specify which columns to show in the output. Currently supported:\n            (\"input_size\", \"output_size\", \"num_params\", \"kernel_size\", \"mult_adds\")\n            If input_data is not provided, only \"num_params\" is used.\n            Default: (\"output_size\", \"num_params\")\n\n    col_width (int):\n            Width of each column.\n            Default: 25\n\n    depth (int):\n            Number of nested layers to traverse (e.g. Sequentials).\n            Default: 3\n\n    device (torch.Device):\n            Uses this torch device for model and input_data.\n            If not specified, uses result of torch.cuda.is_available().\n            Default: None\n\n    dtypes (List[torch.dtype]):\n            For multiple inputs, specify the size of both inputs, and\n            also specify the types of each parameter here.\n            Default: None\n\n    verbose (int):\n            0 (quiet): No output\n            1 (default): Print model summary\n            2 (verbose): Show weight and bias layers in full detail\n            Default: 1\n\n    *args, **kwargs:\n            Other arguments used in `model.forward` function.\n\nReturn:\n    ModelStatistics object\n            See torchsummary/model_statistics.py for more information.\n\"\"\"\n```\n\n# Examples\n## Get Model Summary as String\n```python\nfrom torchsummary import summary\n\nmodel_stats = summary(your_model, (3, 28, 28), verbose=0)\nsummary_str = str(model_stats)\n# summary_str contains the string representation of the summary. See below for examples.\n```\n\n## ResNet\n```python\nimport torchvision\n\nmodel = torchvision.models.resnet50()\nsummary(model, (3, 224, 224), depth=3)\n```\n```\n==========================================================================================\nLayer (type:depth-idx)                   Output Shape              Param #\n==========================================================================================\n\u251c\u2500Conv2d: 1-1                            [-1, 64, 112, 112]        9,408\n\u251c\u2500BatchNorm2d: 1-2                       [-1, 64, 112, 112]        128\n\u251c\u2500ReLU: 1-3                              [-1, 64, 112, 112]        --\n\u251c\u2500MaxPool2d: 1-4                         [-1, 64, 56, 56]          --\n\u251c\u2500Sequential: 1-5                        [-1, 256, 56, 56]         --\n|    \u2514\u2500Bottleneck: 2-1                   [-1, 256, 56, 56]         --\n|    |    \u2514\u2500Conv2d: 3-1                  [-1, 64, 56, 56]          4,096\n|    |    \u2514\u2500BatchNorm2d: 3-2             [-1, 64, 56, 56]          128\n|    |    \u2514\u2500ReLU: 3-3                    [-1, 64, 56, 56]          --\n|    |    \u2514\u2500Conv2d: 3-4                  [-1, 64, 56, 56]          36,864\n|    |    \u2514\u2500BatchNorm2d: 3-5             [-1, 64, 56, 56]          128\n|    |    \u2514\u2500ReLU: 3-6                    [-1, 64, 56, 56]          --\n|    |    \u2514\u2500Conv2d: 3-7                  [-1, 256, 56, 56]         16,384\n|    |    \u2514\u2500BatchNorm2d: 3-8             [-1, 256, 56, 56]         512\n|    |    \u2514\u2500Sequential: 3-9              [-1, 256, 56, 56]         --\n|    |    \u2514\u2500ReLU: 3-10                   [-1, 256, 56, 56]         --\n\n  ...\n  ...\n  ...\n\n\u251c\u2500AdaptiveAvgPool2d: 1-9                 [-1, 2048, 1, 1]          --\n\u251c\u2500Linear: 1-10                           [-1, 1000]                2,049,000\n==========================================================================================\nTotal params: 60,192,808\nTrainable params: 60,192,808\nNon-trainable params: 0\nTotal mult-adds (G): 11.63\n==========================================================================================\nInput size (MB): 0.57\nForward/backward pass size (MB): 344.16\nParams size (MB): 229.62\nEstimated Total Size (MB): 574.35\n==========================================================================================\n```\n\n## Multiple Inputs w/ Different Data Types\n```python\nclass MultipleInputNetDifferentDtypes(nn.Module):\n    def __init__(self):\n        super().__init__()\n        self.fc1a = nn.Linear(300, 50)\n        self.fc1b = nn.Linear(50, 10)\n\n        self.fc2a = nn.Linear(300, 50)\n        self.fc2b = nn.Linear(50, 10)\n\n    def forward(self, x1, x2):\n        x1 = F.relu(self.fc1a(x1))\n        x1 = self.fc1b(x1)\n        x2 = x2.type(torch.float)\n        x2 = F.relu(self.fc2a(x2))\n        x2 = self.fc2b(x2)\n        x = torch.cat((x1, x2), 0)\n        return F.log_softmax(x, dim=1)\n\nsummary(model, [(1, 300), (1, 300)], dtypes=[torch.float, torch.long])\n```\nAlternatively, you can also pass in the input_data itself, and\ntorchsummary will automatically infer the data types.\n\n```python\ninput_data = torch.randn(1, 300)\nother_input_data = torch.randn(1, 300).long()\nmodel = MultipleInputNetDifferentDtypes()\n\nsummary(model, input_data, other_input_data, ...)\n```\n\n## Explore Different Configurations\n```python\nclass LSTMNet(nn.Module):\n    \"\"\" Batch-first LSTM model. \"\"\"\n    def __init__(self, vocab_size=20, embed_dim=300, hidden_dim=512, num_layers=2):\n        super().__init__()\n        self.hidden_dim = hidden_dim\n        self.embedding = nn.Embedding(vocab_size, embed_dim)\n        self.encoder = nn.LSTM(embed_dim, hidden_dim, num_layers=num_layers, batch_first=True)\n        self.decoder = nn.Linear(hidden_dim, vocab_size)\n\n    def forward(self, x):\n        embed = self.embedding(x)\n        out, hidden = self.encoder(embed)\n        out = self.decoder(out)\n        out = out.view(-1, out.size(2))\n        return out, hidden\n\nsummary(\n    LSTMNet(),\n    (100,),\n    dtypes=[torch.long],\n    branching=False,\n    verbose=2,\n    col_width=16,\n    col_names=[\"kernel_size\", \"output_size\", \"num_params\", \"mult_adds\"],\n)\n```\n```\n========================================================================================================================\nLayer (type:depth-idx)                   Kernel Shape         Output Shape         Param #              Mult-Adds\n========================================================================================================================\nEmbedding: 1-1                           [300, 20]            [-1, 100, 300]       6,000                6,000\nLSTM: 1-2                                --                   [-1, 100, 512]        3,768,320            3,760,128\n  weight_ih_l0                           [2048, 300]\n  weight_hh_l0                           [2048, 512]\n  weight_ih_l1                           [2048, 512]\n  weight_hh_l1                           [2048, 512]\nLinear: 1-3                              [512, 20]            [-1, 100, 20]        10,260               10,240\n========================================================================================================================\nTotal params: 3,784,580\nTrainable params: 3,784,580\nNon-trainable params: 0\nTotal mult-adds (M): 3.78\n========================================================================================================================\nInput size (MB): 0.00\nForward/backward pass size (MB): 1.03\nParams size (MB): 14.44\nEstimated Total Size (MB): 15.46\n========================================================================================================================\n```\n\n## Sequentials & ModuleLists\n```python\nclass ContainerModule(nn.Module):\n    \"\"\" Model using ModuleList. \"\"\"\n\n    def __init__(self):\n        super().__init__()\n        self._layers = nn.ModuleList()\n        self._layers.append(nn.Linear(5, 5))\n        self._layers.append(ContainerChildModule())\n        self._layers.append(nn.Linear(5, 5))\n\n    def forward(self, x):\n        for layer in self._layers:\n            x = layer(x)\n        return x\n\n\nclass ContainerChildModule(nn.Module):\n    \"\"\" Model using Sequential in different ways. \"\"\"\n\n    def __init__(self):\n        super().__init__()\n        self._sequential = nn.Sequential(nn.Linear(5, 5), nn.Linear(5, 5))\n        self._between = nn.Linear(5, 5)\n\n    def forward(self, x):\n        out = self._sequential(x)\n        out = self._between(out)\n        for l in self._sequential:\n            out = l(out)\n\n        out = self._sequential(x)\n        for l in self._sequential:\n            out = l(out)\n        return out\n\nsummary(ContainerModule(), (5,))\n```\n```\n==========================================================================================\nLayer (type:depth-idx)                   Output Shape              Param #\n==========================================================================================\n\u251c\u2500ModuleList: 1                          []                        --\n|    \u2514\u2500Linear: 2-1                       [-1, 5]                   30\n|    \u2514\u2500ContainerChildModule: 2-2         [-1, 5]                   --\n|    |    \u2514\u2500Sequential: 3-1              [-1, 5]                   --\n|    |    |    \u2514\u2500Linear: 4-1             [-1, 5]                   30\n|    |    |    \u2514\u2500Linear: 4-2             [-1, 5]                   30\n|    |    \u2514\u2500Linear: 3-2                  [-1, 5]                   30\n|    |    \u2514\u2500Sequential: 3                []                        --\n|    |    |    \u2514\u2500Linear: 4-3             [-1, 5]                   (recursive)\n|    |    |    \u2514\u2500Linear: 4-4             [-1, 5]                   (recursive)\n|    |    \u2514\u2500Sequential: 3-3              [-1, 5]                   (recursive)\n|    |    |    \u2514\u2500Linear: 4-5             [-1, 5]                   (recursive)\n|    |    |    \u2514\u2500Linear: 4-6             [-1, 5]                   (recursive)\n|    |    |    \u2514\u2500Linear: 4-7             [-1, 5]                   (recursive)\n|    |    |    \u2514\u2500Linear: 4-8             [-1, 5]                   (recursive)\n|    \u2514\u2500Linear: 2-3                       [-1, 5]                   30\n==========================================================================================\nTotal params: 150\nTrainable params: 150\nNon-trainable params: 0\nTotal mult-adds (M): 0.00\n==========================================================================================\nInput size (MB): 0.00\nForward/backward pass size (MB): 0.00\nParams size (MB): 0.00\nEstimated Total Size (MB): 0.00\n==========================================================================================\n```\n\n# Other Examples\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# Future Plans\n- Change project name to `torchinfo`. The API will eventually mature to the point that this project deserves its own name.\n- Support all types of inputs - showing tuples and dict inputs cleanly rather than only using the first tensor in the list.\n- Default `batch_dim` to `None` rather than `0`. Users must specify the batch size in the input shape, or pass in `batch_dim=0` in order to ignore it.\n- FunctionalNet unused; figure out a way to hook into functional layers.\n\n# Contributing\nAll issues and pull requests are much appreciated! If you are wondering how to build the project:\n\n- torch-summary is actively developed using the lastest version of Python.\n    - Changes should be backward compatible with Python 3.6, but this is subject to change in the future.\n    - Run `pip install -r requirements-dev.txt`. We use the latest versions of all dev packages.\n    - First, be sure to run `./scripts/install-hooks`\n    - To run all tests and use auto-formatting tools, check out `scripts/run-tests`.\n    - To only run unit tests, run `pytest`.\n\n# References\n- Thanks to @sksq96, @nmhkahn, and @sangyx for providing the original code this project was based off of.\n- For Model Size Estimation @jacobkimmel ([details here](https://github.com/sksq96/pytorch-summary/pull/21))\n\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Model summary in PyTorch, based off of the original torchsummary.",
    "version": "1.4.5",
    "project_urls": {
        "Homepage": "https://github.com/tyleryep/torchinfo"
    },
    "split_keywords": [
        "torch",
        "pytorch",
        "torchsummary",
        "torch-summary",
        "summary",
        "keras",
        "deep-learning",
        "ml",
        "torchinfo",
        "torch-info",
        "visualize",
        "model",
        "statistics",
        "layer"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "cadb93d18c84f73b214acfa4d18051d6f4263eee3e044c408928e8abe941a22c",
                "md5": "9833b390fc01c0b4d66e06ee8b059cc5",
                "sha256": "6127efb631f34ba8cbd28e92e8f7ddc2903ea0cbc44c80f15b7363b8f558cd8c"
            },
            "downloads": -1,
            "filename": "torch_summary-1.4.5-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "9833b390fc01c0b4d66e06ee8b059cc5",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 16161,
            "upload_time": "2020-12-24T05:00:30",
            "upload_time_iso_8601": "2020-12-24T05:00:30.969684Z",
            "url": "https://files.pythonhosted.org/packages/ca/db/93d18c84f73b214acfa4d18051d6f4263eee3e044c408928e8abe941a22c/torch_summary-1.4.5-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ff2f57cb3b23bccae7fc639ab7ff8bb78c80f03e8c0a144bbc69bfd26b0757f7",
                "md5": "802f337554955266e7f81d9fdd5ef42d",
                "sha256": "44eac21777dbbda7b8404d57a43c09d83fd9c93d0c1f0c960b5083ccb24d6d21"
            },
            "downloads": -1,
            "filename": "torch_summary-1.4.5.tar.gz",
            "has_sig": false,
            "md5_digest": "802f337554955266e7f81d9fdd5ef42d",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 17228,
            "upload_time": "2020-12-24T05:00:32",
            "upload_time_iso_8601": "2020-12-24T05:00:32.266886Z",
            "url": "https://files.pythonhosted.org/packages/ff/2f/57cb3b23bccae7fc639ab7ff8bb78c80f03e8c0a144bbc69bfd26b0757f7/torch_summary-1.4.5.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2020-12-24 05:00:32",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "tyleryep",
    "github_project": "torchinfo",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [
        {
            "name": "torch",
            "specs": []
        },
        {
            "name": "torchvision",
            "specs": []
        },
        {
            "name": "numpy",
            "specs": []
        }
    ],
    "lcname": "torch-summary"
}
        
Elapsed time: 0.12220s