
    ёi,                    ~    S SK Jr  S SKrS SKrS SKJrJr  SSKJrJ	r	J
r
  SSKJrJrJr  SSKJr  / r " S	 S
\5      rg)    )annotationsN)_C_opspir   )core	frameworkunique_name)_current_expected_placein_dygraph_modein_pir_mode   )Initializerc                  J   ^  \ rS rSrSrSU 4S jjr S     SS jjrSrU =r$ )	Bilinear!   a  
This initializer can be used in transposed convolution operator to
act as upsampling. Users can upsample a feature map with shape of
(B, C, H, W) by any integer factor.

Returns:
    Bilinear initializer instance objects.

Examples:

    .. code-block:: python

        >>> import math

        >>> import paddle
        >>> import paddle.nn as nn
        >>> from paddle.regularizer import L2Decay

        >>> factor = 2
        >>> C = 2
        >>> B = 8
        >>> H = W = 32
        >>> w_attr = paddle.ParamAttr(learning_rate=0.,
        ...                           regularizer=L2Decay(0.),
        ...                           initializer=nn.initializer.Bilinear())
        >>> data = paddle.rand([B, 3, H, W], dtype='float32')
        >>> conv_up = nn.Conv2DTranspose(3,
        ...                              out_channels=C,
        ...                              kernel_size=2 * factor - factor % 2,
        ...                              padding=int(
        ...                                  math.ceil((factor - 1) / 2.)),
        ...                              stride=factor,
        ...                              weight_attr=w_attr,
        ...                              bias_attr=False)
        >>> x = conv_up(data)

Where, `out_channels=C` and `groups=C` means this is channel-wise transposed
convolution. The filter shape will be (C, 1, K, K) where K is `kernel_size`,
This initializer will set a (K, K) interpolation kernel for every channel
of the filter identically. The resulting shape of the output feature map
will be (B, C, factor * H, factor * W). Note that the learning rate and the
weight decay are set to 0 in order to keep coefficient values of bilinear
interpolation unchanged during training.

c                "   > [         TU ]  5         g)z$Constructor for BilinearInitializer.N)super__init__)self	__class__s    ^/var/www/html/banglarbhumi/venv/lib/python3.13/site-packages/paddle/nn/initializer/bilinear.pyr   Bilinear.__init__P   s        c           
     4   [        U[        R                  5      (       a  UR                  5       (       a   S5       eU R	                  U5      n[        U[        R
                  [        R                  R                  45      (       d  [        S5      e[        U[        R                  [        R                  45      (       d  [        S5      eUR                  n[        U5      S:w  a  [        S5      eUS   US   :w  a  [        S5      e[        R                  " [        R                  " UR                  5      S	S
9nUS   n[        R                   " US-  5      nSU-  S-
  US-  -
  SU-  -  n[#        [        R                  " U5      5       H7  nX-  n	X-  U-  n
S[%        X-  U-
  5      -
  S[%        X-  U-
  5      -
  -  XH'   M9     [        R&                  " XC5      nUR(                  [        R*                  R,                  R.                  [        R*                  R,                  R0                  [        R*                  R,                  R2                  4;   a  [        R*                  R,                  R4                  nUR7                  [8        R:                  " SR=                  SUR>                  S/5      5      UR                  U[        R*                  R,                  R@                  SS9nOUR(                  [        RB                  RD                  [        RB                  RF                  [        RB                  RH                  4;   a  [        RB                  RJ                  nUnOUR(                  nUnU[        R*                  R,                  R4                  [        RB                  RJ                  4;   a(  SnURL                   Vs/ s H  n[O        U5      PM     nnO[Q        SUR(                   35      e[        R                  " U5      S:  a  [        S5      e[S        5       (       a  [T        RV                  " U[Y        U5      UU[[        5       5        UR(                  [        R*                  R,                  R.                  [        R*                  R,                  R0                  [        R*                  R,                  R2                  4;   a2  [T        R\                  " XR(                  5      nUR_                  U5        gUR_                  U5        g[a        5       (       a  [T        Rb                  " [Y        U5      UU[[        5       5      nUR(                  [        RB                  RD                  [        RB                  RF                  [        RB                  RH                  4;   a   [T        R\                  " XR(                  5      nU$ URe                  SSU/0SUS[Y        U5      X0S9nUR(                  [        R*                  R,                  R.                  [        R*                  R,                  R0                  [        R*                  R,                  R2                  4;   a-  URe                  SSU0SU0UR(                  UR(                  S.S9  UUl3        U$ s  snf ) a'  Initialize the input tensor with Bilinear initialization.

Args:
    var(Tensor): Tensor that needs to be initialized.
    block(Block|None, optional): The block in which initialization ops
           should be added. Used in static graph only, default None.

Returns:
    The initialization op
zECurrently, Bilinear initializer not support lazy init for dist param.z9var must be framework.Variable or pir.core.ParameterMeta.z+block must be framework.Block or pir.Block.   zthe length of shape must be 4.   r   z#shape[2] must be equal to shape[3].float32)dtypeg       @r   .bilinear_inittmpF)nameshaper   typepersistablevalueszUnsupported dtype i   zThe size of input is too big. Nassign_valueOutr   r#   )r$   outputsattrscastX)in_dtype	out_dtype)r$   inputsr)   r*   )4
isinstancer   EagerParamBaseis_dist_check_blockVariabler   r   ParameterMeta
ValueErrorBlockr#   lennpzerosprodceilrangeabsreshaper   VarDescVarTypeFP16BF16FP64FP32
create_varr	   generatejoinr"   DENSE_TENSORDataTypeFLOAT16BFLOAT16FLOAT64FLOAT32flatfloat	TypeErrorr   r   assign_value_listr
   r+   _share_underline_tensor_tor   r'   	append_opop)r   varblockr#   weightsizefcixyr.   out_var
value_namevr&   var_tmprV   s                     r   forwardBilinear.forwardT   s-    sI4455#++--	
 T	
 

 !!%(#	 2 2CHH4J4JKLLK  %)//399!=>>JKK		u:?=>>8uQxBCC"''#)),I>QxGGD3JUQYQ37+rwwu~&AAT!AS^+C	N0BCFI ' F* 99LL  %%LL  %%LL  %%
 

 ,,11I&& ))HHosxx?@ ii\\))66! ' G YYMM!!MM""MM!!
 

 --IG		IG--22DMM4I4IJJ!J(.41eAhF4F0<==775>K'=>>  U') yy$$))$$))$$)) 
 !++gyy92237  2237]]))U')	G yy%%&&%% 
 !++gyy9N#	*YT%[ ! B yy$$))$$))$$)) 
 >"CL'.}}399M	    CFI 5s   Z )returnNone)N)rW   zpaddle.TensorrX   zpir.Block | Nonerg   zpaddle.Tensor | None)	__name__
__module____qualname____firstlineno____doc__r   rd   __static_attributes____classcell__)r   s   @r   r   r   !   s;    ,\
 =AJ J)9J	J Jr   r   )
__future__r   numpyr9   paddler   r   baser   r   r	   base.frameworkr
   r   r   initializerr   __all__r   rf   r   r   <module>rw      s;    #    0 0 
 %
}{ }r   