PyTorch Tensor Shape Calculator
Calculate output shapes for 14 layer types. Chain layers together, debug shape errors, and explore architecture presets. Works with PyTorch and TensorFlow.
Frequently Asked Questions
How do I calculate Conv2d output shape?
The Conv2d output shape formula is: H_out = floor((H_in + 2*padding - dilation*(kernel_size-1) - 1) / stride) + 1. The same formula applies to width. For example, with input (1, 3, 224, 224), kernel_size=3, padding=1, stride=1: output height = floor((224 + 2 - 3) / 1) + 1 = 224. Use the calculator above to compute this instantly for any configuration.
Why does PyTorch say mat1 and mat2 shapes cannot be multiplied?
This error means the number of columns in the first matrix doesn't match the number of rows in the second. In PyTorch, this usually happens when a Linear layer's in_features doesn't match the actual input size. For example, if your flatten produces 512 features but Linear expects 256, you'll see this error. Fix: set in_features to match your actual flattened size, or use the Chain Mode above to trace shapes through your network.
What is the output shape of a Linear layer?
A PyTorch nn.Linear(in_features, out_features) layer transforms the last dimension of the input tensor. If input is [batch, features], output is [batch, out_features]. If input is [batch, seq, features], output is [batch, seq, out_features]. Only the last dimension changes to out_features.
How do I fix tensor size mismatch in PyTorch?
Tensor size mismatches happen when two tensors in an operation have incompatible shapes. Steps to fix: 1) Print tensor shapes with tensor.shape at each layer. 2) Use the Chain Mode above to trace shapes through your network. 3) Common fixes include adjusting padding in Conv layers, changing in_features in Linear layers, or adding a Flatten layer before fully connected layers.
What does RuntimeError: Expected input batch_size mean?
This error means your input tensor and target tensor have different batch sizes. For example, if your model outputs predictions for 32 samples but your labels only have 16 entries. Fix: ensure your data loader returns matching batch sizes for inputs and targets. Check for accidental reshaping that changes the batch dimension.
Does HeyTensor support TensorFlow layers?
Yes. While the layer naming follows PyTorch conventions, the shape formulas are identical across frameworks. Conv2D, Dense (Linear), LSTM, and pooling layers use the same mathematical formulas in both PyTorch and TensorFlow. Enter your TensorFlow layer parameters and the output shapes will be correct.
How HeyTensor Works
HeyTensor is a free, browser-based tensor shape calculator built for deep learning practitioners who need to quickly determine output dimensions for neural network layers. Instead of manually applying formulas or inserting print statements into your code, you enter the input shape and layer parameters, and HeyTensor computes the exact output shape instantly. The calculator supports 14 layer types across both PyTorch and TensorFlow: Conv2d, Conv1d, Linear, LSTM, GRU, MultiheadAttention, BatchNorm, MaxPool2d, AvgPool2d, Flatten, Reshape, Dropout, Transpose, and Concatenate.
The most powerful feature is Chain Mode, which lets you stack layers sequentially and see the output shape at every step of your network. If shapes become incompatible between layers — the most common source of PyTorch RuntimeErrors — the mismatch is highlighted immediately. This lets you fix architecture issues before writing any code, saving the frustrating cycle of running a training script, hitting a shape error, guessing the fix, and running again. The Paste Error mode goes further: paste a PyTorch error message like "mat1 and mat2 shapes cannot be multiplied (64x512 and 256x10)" and HeyTensor extracts the dimensions and suggests which parameter to change.
Architecture Presets let you load complete network configurations with one click. Available presets include LeNet-5, a simple CNN classifier, a ResNet residual block, a Transformer encoder layer, and an LSTM classifier. Each preset shows shape propagation through every layer, serving as both a learning tool and a starting point for your own designs.
Features
HeyTensor provides a single-layer calculator for instant shape computation, a chain mode for tracing shapes through multi-layer architectures, a paste-error debugger that parses PyTorch RuntimeErrors and suggests fixes, architecture presets for common network designs, support for 14 PyTorch and TensorFlow layer types, and detailed formula display showing exactly how each output dimension is calculated. All computations run entirely in your browser with no server communication.
Who Uses This
HeyTensor is designed for ML engineers debugging shape mismatches during model development, students learning deep learning architecture design, researchers prototyping new layer configurations, and anyone working with PyTorch or TensorFlow who wants to verify tensor dimensions before running code. If you work with the underlying matrix math behind neural networks, ML3X provides a visual matrix calculator with step-by-step solutions. For developers needing general-purpose encoding tools, KappaKit offers Base64, JWT, hash, and UUID utilities in a similar single-page format. Model security analysis and input validation tools are available at LockML.
Privacy
All tensor shape calculations run locally in your browser. No model architectures, error messages, or layer parameters are sent to any server. The source code is fully open on GitHub. There are no cookies, no analytics, and no tracking.
Contact
HeyTensor is built and maintained by Michael Lip. For questions or feedback, email [email protected] or visit the project on GitHub.