Table of Contents
Shortcuts

# Flatten

class torch.nn.Flatten(start_dim=1, end_dim=- 1)

  Flattens a contiguous range of dims into a tensor. For use with `Sequential`. See `torch.flatten()` for details.

  Shape:

    - Input: (∗,S start,...,S i,...,S end,∗)(*, S_{\text{start}},..., S_{i}, ..., S_{\text{end}}, *)(∗,S start​,...,S i​,...,S end​,∗),’ where S i S_{i}S i​ is the size at dimension i i i and ∗*∗ means any number of dimensions including none.

    - Output: (∗,∏i=start end S i,∗)(*, \prod_{i=\text{start}}^{\text{end}} S_{i}, *)(∗,∏i=start end​S i​,∗).

  Parameters:

    - start_dim (int) – first dim to flatten (default = 1).

    - end_dim (int) – last dim to flatten (default = -1).

  Examples::

        >>> input = torch.randn(32, 1, 5, 5)
        >>> # With default parameters
        >>> m = nn.Flatten()
        >>> output = m(input)
        >>> output.size()
        torch.Size([32, 25])
        >>> # With non-default parameters
        >>> m = nn.Flatten(0, 2)
        >>> output = m(input)
        >>> output.size()
        torch.Size([160, 5])

## Docs

Access comprehensive developer documentation for PyTorch

View Docs

## Tutorials

Get in-depth tutorials for beginners and advanced developers

View Tutorials

## Resources

Find development resources and get your questions answered

View Resources

To analyze traffic and optimize your experience, we serve cookies on this site. By clicking or navigating, you agree to allow our usage of cookies. As the current maintainers of this site, Facebook’s Cookies Policy applies. Learn more, including about available controls: Cookies Policy.