/usr/local/lib64/python3.6/site-packages/torch/nn/modules/__pycache__
Edit: /usr/local/lib64/python3.6/site-packages/torch/nn/modules/__pycache__/flatten.cpython-36.pyc (5813B)
3
ûEgÈ ã @ sX d dl mZ ddlmZmZ ddlmZ ddlmZ G dd„ deƒZ G dd „ d eƒZ
d
S )é )ÚModuleé )ÚTupleÚUnion)ÚTensor)Ú_sizec s\ e Zd ZU dZddgZeedeeddœ‡ fdd„
Ze e d œd
d„Z
edœd
d„Z‡ Z
S )ÚFlattena
Flattens a contiguous range of dims into a tensor. For use with :class:`~nn.Sequential`.
Shape:
- Input: :math:`(*, S_{\text{start}},..., S_{i}, ..., S_{\text{end}}, *)`,'
where :math:`S_{i}` is the size at dimension :math:`i` and :math:`*` means any
number of dimensions including none.
- Output: :math:`(*, \prod_{i=\text{start}}^{\text{end}} S_{i}, *)`.
Args:
start_dim: first dim to flatten (default = 1).
end_dim: last dim to flatten (default = -1).
Examples::
>>> input = torch.randn(32, 1, 5, 5)
>>> m = nn.Sequential(
>>> nn.Conv2d(1, 32, 5, 1, 1),
>>> nn.Flatten()
>>> )
>>> output = m(input)
>>> output.size()
torch.Size([32, 288])
Ú start_dimÚend_dimr N)r r
Úreturnc s t t| ƒjƒ || _|| _d S )N)Úsuperr Ú__init__r r
)Úselfr r
)Ú __class__© úD/usr/local/lib64/python3.6/site-packages/torch/nn/modules/flatten.pyr
$ s zFlatten.__init__)Úinputr c C s |j | j| jƒS )N)Úflattenr r
)r r r r r Úforward) s zFlatten.forward)r c C s dj | j| jƒS )Nzstart_dim={}, end_dim={})Úformatr r
)r r r r Ú
extra_repr, s zFlatten.extra_repréÿÿÿÿ)r r )Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú
__constants__Úintr r
r
r r Ústrr Ú
__classcell__r r )r r r s
r c sš e Zd ZU dZeeeef ZddgZe eef
e eef e eef e eef ddœ‡ fdd„Z
dd „ Zd
d„ Zeedœd
d„Zedœdd„Z‡ ZS )Ú Unflattena
Unflattens a tensor dim expanding it to a desired shape. For use with :class:`~nn.Sequential`.
* :attr:`dim` specifies the dimension of the input tensor to be unflattened, and it can
be either `int` or `str` when `Tensor` or `NamedTensor` is used, respectively.
* :attr:`unflattened_size` is the new shape of the unflattened dimension of the tensor and it can be
a `tuple` of ints or a `list` of ints or `torch.Size` for `Tensor` input; a `NamedShape`
(tuple of `(name, size)` tuples) for `NamedTensor` input.
Shape:
- Input: :math:`(*, S_{\text{dim}}, *)`, where :math:`S_{\text{dim}}` is the size at
dimension :attr:`dim` and :math:`*` means any number of dimensions including none.
- Output: :math:`(*, U_1, ..., U_n, *)`, where :math:`U` = :attr:`unflattened_size` and
:math:`\prod_{i=1}^n U_i = S_{\text{dim}}`.
Args:
dim (Union[int, str]): Dimension to be unflattened
unflattened_size (Union[torch.Size, Tuple, List, NamedShape]): New shape of the unflattened dimension
Examples:
>>> input = torch.randn(2, 50)
>>> # With tuple of ints
>>> m = nn.Sequential(
>>> nn.Linear(50, 50),
>>> nn.Unflatten(1, (2, 5, 5))
>>> )
>>> output = m(input)
>>> output.size()
torch.Size([2, 2, 5, 5])
>>> # With torch.Size
>>> m = nn.Sequential(
>>> nn.Linear(50, 50),
>>> nn.Unflatten(1, torch.Size([2, 5, 5]))
>>> )
>>> output = m(input)
>>> output.size()
torch.Size([2, 2, 5, 5])
>>> # With namedshape (tuple of tuples)
>>> input = torch.randn(2, 50, names=('N', 'features'))
>>> unflatten = nn.Unflatten('features', (('C', 2), ('H', 5), ('W', 5)))
>>> output = unflatten(input)
>>> output.size()
torch.Size([2, 2, 5, 5])
ÚdimÚunflattened_sizeN)r! r" r c sR t t| ƒjƒ t|tƒr$| j|ƒ nt|tƒr:| j|ƒ ntdƒ‚|| _ || _
d S )Nz'invalid argument type for dim parameter)r r r
Ú
isinstancer Ú_require_tuple_intr Ú_require_tuple_tupleÚ TypeErrorr! r" )r r! r" )r r r r
f s
zUnflatten.__init__c C sd t |tƒrHx8t|ƒD ],\}}t |tƒstddjt|ƒj|ƒ ƒ‚qW d S tddjt|ƒjƒ ƒ‚d S )Nz*unflattened_size must be tuple of tuples, z&but found element of type {} at pos {}z,unflattened_size must be a tuple of tuples, zbut found type {})r# ÚtupleÚ enumerater&