
    ёi&                        S SK Jr  S SKJr  SSKJr  SSKJr  \(       a  S SKJ	r	  S SK
Jr  / r " S	 S
\5      r " S S\5      r " S S\5      rg)    )annotations)TYPE_CHECKING   )
functional   )Layer)Tensor)DataLayout2Dc                  Z   ^  \ rS rSrSr  S       SU 4S jjjrS	S jrS
S jrSrU =r	$ )PixelShuffle   aX  

Rearranges elements in a tensor of shape :math:`[N, C, H, W]`
to a tensor of shape :math:`[N, C/upscale_factor^2, H*upscale_factor, W*upscale_factor]`,
or from shape :math:`[N, H, W, C]` to :math:`[N, H*upscale_factor, W*upscale_factor, C/upscale_factor^2]`.
This is useful for implementing efficient sub-pixel convolution
with a stride of 1/upscale_factor.
Please refer to the paper: `Real-Time Single Image and Video Super-Resolution
Using an Efficient Sub-Pixel Convolutional Neural Network <https://arxiv.org/abs/1609.05158v2>`_ .
by Shi et. al (2016) for more details.

Parameters:

    upscale_factor(int): factor to increase spatial resolution.
    data_format (str, optional): The data format of the input and output data. An optional string from: `'NCHW'``, ``'NHWC'``. When it is ``'NCHW'``, the data is stored in the order of: [batch_size, input_channels, input_height, input_width]. Default: ``'NCHW'``.
    name (str|None, optional): Name for the operation (optional, default is None). For more information, please refer to :ref:`api_guide_Name`.

Shape:
    - x: 4-D tensor with shape of :math:`(N, C, H, W)` or :math:`(N, H, W, C)`.
    - out: 4-D tensor with shape of :math:`(N, C/upscale_factor^2, H*upscale_factor, W*upscale_factor)` or :math:`(N, H*upscale_factor, W*upscale_factor, C/upscale_factor^2)`.


Examples:
    .. code-block:: pycon

        >>> import paddle
        >>> import paddle.nn as nn

        >>> x = paddle.randn(shape=[2, 9, 4, 4])
        >>> pixel_shuffle = nn.PixelShuffle(3)
        >>> out = pixel_shuffle(x)
        >>> print(out.shape)
        paddle.Size([2, 1, 12, 12])

c                   > [         TU ]  5         [        U[        5      (       d  [	        S5      eUS;  a  [        SU 35      eXl        X l        X0l        g )Nzupscale factor must be int typeNCHWNHWC@Data format should be 'NCHW' or 'NHWC'.But receive data format: )	super__init__
isinstanceint	TypeError
ValueError_upscale_factor_data_format_name)selfupscale_factordata_formatname	__class__s       V/var/www/html/banglarbhumi/venv/lib/python3.13/site-packages/paddle/nn/layer/vision.pyr   PixelShuffle.__init__B   sa     	.#..=>>..,,7=: 
  .'
    c                n    [         R                  " XR                  U R                  U R                  5      $ N)r   pixel_shuffler   r   r   r   xs     r!   forwardPixelShuffle.forwardW   s,    ''##T%6%6


 	
r#   c                    SU R                    3nU R                  S:w  a  USU R                   3-  nU R                  b  USU R                   3-  nU$ )Nzupscale_factor=r   , data_format=, name=)r   r   r   r   main_strs     r!   
extra_reprPixelShuffle.extra_repr\   s_    $T%9%9$:;&.):):(;<<H::!'$**..Hr#   )r   r   r   r   N)r   r   r   r
   r   
str | NonereturnNoner(   r	   r4   r	   r4   str
__name__
__module____qualname____firstlineno____doc__r   r)   r0   __static_attributes____classcell__r    s   @r!   r   r      sP    "N %+	 " 	
 
 *

 r#   r   c                  Z   ^  \ rS rSrSr  S       SU 4S jjjrS	S jrS
S jrSrU =r	$ )PixelUnshufflee   a&  
Rearranges elements in a tensor of shape :math:`[N, C, H, W]`
to a tensor of shape :math:`[N, r^2C, H/r, W/r]`, or from shape
:math:`[N, H, W, C]` to :math:`[N, H/r, W/r, r^2C]`, where :math:`r` is the
downscale factor. This operation is the reversion of PixelShuffle operation.
Please refer to the paper: `Real-Time Single Image and Video Super-Resolution
Using an Efficient Sub-Pixel Convolutional Neural Network <https://arxiv.org/abs/1609.05158v2>`_ .
by Shi et. al (2016) for more details.

Parameters:
    downscale_factor (int): Factor to decrease spatial resolution.
    data_format (str, optional): The data format of the input and output data. An optional string of ``'NCHW'`` or ``'NHWC'``. When it is ``'NCHW'``, the data is stored in the order of [batch_size, input_channels, input_height, input_width]. Default: ``'NCHW'``.
    name (str|None, optional): Name for the operation (optional, default is None). Normally there is no need for user to set this property. For more information, please refer to :ref:`api_guide_Name`.

Shape:
    - **x**: 4-D tensor with shape of :math:`[N, C, H, W]` or :math:`[N, C, H, W]`.
    - **out**: 4-D tensor with shape of :math:`[N, r^2C, H/r, W/r]` or :math:`[N, H/r, W/r, r^2C]`, where :math:`r` is :attr:`downscale_factor`.

Examples:
    .. code-block:: pycon

        >>> import paddle
        >>> import paddle.nn as nn

        >>> x = paddle.randn([2, 1, 12, 12])
        >>> pixel_unshuffle = nn.PixelUnshuffle(3)
        >>> out = pixel_unshuffle(x)
        >>> print(out.shape)
        paddle.Size([2, 9, 4, 4])

c                   > [         TU ]  5         [        U[        5      (       d  [	        S5      eUS::  a  [        S5      eUS;  a  [        SU 35      eXl        X l        X0l        g )Nz!Downscale factor must be int typer   z!Downscale factor must be positiver   r   )	r   r   r   r   r   r   _downscale_factorr   r   )r   downscale_factorr   r   r    s       r!   r   PixelUnshuffle.__init__   sv     	*C00?@@q @AA..,,7=: 
 "2'
r#   c                n    [         R                  " XR                  U R                  U R                  5      $ r%   )r   pixel_unshufflerF   r   r   r'   s     r!   r)   PixelUnshuffle.forward   s,    ))%%t'8'8$**
 	
r#   c                    SU R                    3nU R                  S:w  a  USU R                   3-  nU R                  b  USU R                   3-  nU$ )Nzdownscale_factor=r   r,   r-   )rF   r   r   r.   s     r!   r0   PixelUnshuffle.extra_repr   s_    &t'='=&>?&.):):(;<<H::!'$**..Hr#   )r   rF   r   r2   )rG   r   r   r
   r   r3   r4   r5   r6   r7   r9   rA   s   @r!   rC   rC   e   sP    F %+	 " 	
 
 0

 r#   rC   c                  Z   ^  \ rS rSrSr  S       SU 4S jjjrS	S jrS
S jrSrU =r	$ )ChannelShuffle   a  
Can divide channels in a tensor of shape [N, C, H, W] or [N, H, W, C] into g groups,
getting a tensor with the shape of [N, g, C/g, H, W] or [N, H, W, g, C/g], and transposes them
as [N, C/g, g, H, W] or [N, H, W, g, C/g], then rearranges them to original tensor shape. This
operation can improve the interaction between channels, using features efficiently. Please
refer to the paper: `ShuffleNet: An Extremely Efficient
Convolutional Neural Network for Mobile Devices <https://arxiv.org/abs/1707.01083>`_ .
by Zhang et. al (2017) for more details.

Parameters:
    groups (int): Number of groups to divide channels in.
    data_format (str, optional): The data format of the input and output data. An optional string of NCHW or NHWC. The default is NCHW. When it is NCHW, the data is stored in the order of [batch_size, input_channels, input_height, input_width].
    name (str|None, optional): Name for the operation (optional, default is None). Normally there is no need for user to set this property. For more information, please refer to :ref:`api_guide_Name`.

Shape:
    - **x**: 4-D tensor with shape of [N, C, H, W] or [N, H, W, C].
    - **out**: 4-D tensor with shape and dtype same as x.

Examples:
    .. code-block:: python

        >>> import paddle
        >>> import paddle.nn as nn
        >>> x = paddle.arange(0, 0.6, 0.1, 'float32')
        >>> x = paddle.reshape(x, [1, 6, 1, 1])
        >>> print(x)
        Tensor(shape=[1, 6, 1, 1], dtype=float32, place=Place(cpu), stop_gradient=True,
        [[[[0.        ]],
          [[0.10000000]],
          [[0.20000000]],
          [[0.30000001]],
          [[0.40000001]],
          [[0.50000000]]]])
        >>> channel_shuffle = nn.ChannelShuffle(3)
        >>> y = channel_shuffle(x)
        >>> print(y)
        Tensor(shape=[1, 6, 1, 1], dtype=float32, place=Place(cpu), stop_gradient=True,
        [[[[0.        ]],
          [[0.20000000]],
          [[0.40000001]],
          [[0.10000000]],
          [[0.30000001]],
          [[0.50000000]]]])
c                   > [         TU ]  5         [        U[        5      (       d  [	        S5      eUS::  a  [        S5      eUS;  a  [        SU 35      eXl        X l        X0l        g )Nzgroups must be int typer   zgroups must be positiver   r   )	r   r   r   r   r   r   _groupsr   r   )r   groupsr   r   r    s       r!   r   ChannelShuffle.__init__   ss     	&#&&566Q;677..,,7=: 
 '
r#   c                n    [         R                  " XR                  U R                  U R                  5      $ r%   )r   channel_shufflerR   r   r   r'   s     r!   r)   ChannelShuffle.forward   s*    ))||T..


 	
r#   c                    SU R                    3nU R                  S:w  a  USU R                   3-  nU R                  b  USU R                   3-  nU$ )Nzgroups=r   r,   r-   )rR   r   r   r.   s     r!   r0   ChannelShuffle.extra_repr   s\    T\\N+&.):):(;<<H::!'$**..Hr#   )r   rR   r   r2   )rS   r   r   r
   r   r3   r4   r5   r6   r7   r9   rA   s   @r!   rO   rO      sP    +` %+	 " 	
 
 0

 r#   rO   N)
__future__r   typingr    r   layersr   paddler	   paddle._typingr
   __all__r   rC   rO    r#   r!   <module>rb      sM    #    +
E5 EPDU DNQU Qr#   