`torchsummary` provides a Keras-like `model.summary()` functionality for PyTorch models, displaying layer names, output shapes, parameter counts, and trainable parameters. It helps in quickly understanding the architecture and memory footprint of a neural network. The current version is 1.5.1, with releases occurring as needed for bug fixes and minor enhancements rather than a strict schedule.
pip install torchsummaryVerified import paths — ran on the pinned version, not inferred.
This example defines a simple Convolutional Neural Network and uses `torchsummary.summary` to print its architecture, output shapes, and parameter counts. Note the importance of providing a correct `input_size` tuple (excluding batch dimension) and ensuring the model is on the specified device.
Carefully determine the expected input shape for your model's first layer, excluding the batch dimension, and pass it as a tuple to `input_size`.
For models with highly dynamic control flow, consider using alternative tools like `torchinfo` (which uses a different tracing mechanism) or manually inspecting layer outputs.
Convert your `torch.device` object to a string before passing it: `device=str(your_torch_device_object)`.