Skip to main content

A very lightweight and minimalistic output shape examiner of layers and models.

Project description

output-shape

PyPI version

A very lightweight and minimalistic output shape examiner of layers and models.

** Currently working for PyTorch models only. Keras / Jax soon! **

Installation

pip install output-shape

Usage

Decorate the forward method with @output_shape, then use either option:

import torch
from output_shape import output_shape, debug_shapes

class Model(torch.nn.Module):
    def __init__(self, debug=False):
        super().__init__()
        self.debug = debug
        ...

    @output_shape
    def forward(self, x):
        ...

# Option 1: Context manager
model = Model()
with debug_shapes():
    model(torch.randn(2, 1, 128, 128))

# Option 2: Instance flag
model = Model(debug=True)
model(torch.randn(2, 1, 128, 128))
Input                           torch.Size([2, 1, 128, 128])
Conv2d                          torch.Size([2, 768, 8, 8])
PatchEmbed                      torch.Size([2, 64, 768])
LayerNorm                       torch.Size([2, 13, 768])
Linear                          torch.Size([2, 13, 2304])
Linear                          torch.Size([2, 13, 768])
Dropout                         torch.Size([2, 13, 768])
Attention                       torch.Size([2, 13, 768])
PreNorm                         torch.Size([2, 13, 768])
LayerNorm                       torch.Size([2, 13, 768])
Linear                          torch.Size([2, 13, 3072])
GELU                            torch.Size([2, 13, 3072])
Dropout                         torch.Size([2, 13, 3072])
Linear                          torch.Size([2, 13, 768])
Dropout                         torch.Size([2, 13, 768])
FeedForward                     torch.Size([2, 13, 768])
PreNorm                         torch.Size([2, 13, 768])
Transformer                     torch.Size([2, 13, 768])
LayerNorm                       torch.Size([2, 13, 768])
Linear                       

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

output_shape-0.0.2-py3-none-any.whl (3.3 kB view details)

Uploaded Python 3

File details

Details for the file output_shape-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: output_shape-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 3.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.18

File hashes

Hashes for output_shape-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 ec75ef514ee6ca0f14494423f9160912117b5cf1af47ae9e6cee9f286eef1d93
MD5 ba64c39aaae9286e15e1d413caf320ca
BLAKE2b-256 b9e6e90a17c76b6396977d5dfb0df6cc4836e1d04bafec75bb21132d844cb834

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page