+
    åûj(   ã                  ó   € R t ^ RIHt ^ RIHtHt ^ RIt^ RIHu H	t
 ^ RIHt ^ RIHt ^ RIHt R.t]P                   ! 4       RR R	 ll4       t ! R
 R]P$                  4      t ! R R]P$                  4      t ! R R]P$                  4      tR# )a-  Residual-in-Residual Dense Block (RRDB) generator used by ESRGAN and Real-ESRGAN.

Adapted from BasicSR (https://github.com/XPixelGroup/BasicSR), Copyright 2018-2022 BasicSR Authors,
Apache-2.0. Modified: type hints, docstrings and minor structural adaptation; the vendored
``pixel_unshuffle`` helper is expressed as :func:`torch.nn.functional.pixel_unshuffle`
(byte-identical); :class:`RRDBNet` rejects a ``scale`` outside ``{1, 2, 4}`` with a ``ValueError``
where upstream silently upsamples by 4. The arithmetic is unchanged.

The module and parameter names are kept identical to upstream so that the published Real-ESRGAN
checkpoints load with ``strict=True``.

References:
    Wang et al., "ESRGAN: Enhanced Super-Resolution Generative Adversarial Networks", ECCVW 2018.
    https://arxiv.org/abs/1809.00219
)Úannotations)ÚIterableÚUnionN)Únn)Úinit)Ú
_BatchNormÚRRDBNetc               ó(   € V ^8„  d   QhRRRRRRRR/# )é   Úmodule_listz%Union[Iterable[nn.Module], nn.Module]ÚscaleÚfloatÚ	bias_fillÚreturnÚNone© )Úformats   "ÚQC:\Ai_Coding\apps\studio\ComfyUI\.venv\Lib\site-packages\kornia\models\rrdbnet.pyÚ__annotate__r   0   s,   € ÷ 1ñ 1Ø6ð1Ø?Dð1ØW\ð1à	ñ1ó    c                óÚ  € \        V \        P                  4      '       d   V .M
\        V 4      pV EF5  pVP	                  4        EF  p\        V\        P
                  \        P                  34      '       d{   \        P                  ! VP                  4       VP                  ;P                  V,          un
        VP                  e(   VP                  P                  P                  V4       K¬  K®  \        V\        4      '       g   KÆ  \        P                  ! VP                  ^4       VP                  f   K÷  VP                  P                  P                  V4       EK  	  EK8  	  R# )zÆInitialize network weights.

Args:
    module_list: Modules to be initialized.
    scale: Scale initialized weights, especially for residual blocks.
    bias_fill: The value to fill the bias with.

N)Ú
isinstancer   ÚModuleÚlistÚmodulesÚConv2dÚLinearr   Úkaiming_normal_ÚweightÚdataÚbiasÚfill_r   Ú	constant_)r   r   r   r   ÚmoduleÚms   &&&   r   Ú_default_init_weightsr%   /   sß   € ô  *¨+´r·y±y×AÒAˆ{‰mÄtÈKÓGX€GÜˆØ—‘×!ˆAÜ˜!œbŸi™i¬¯©Ð3×4Ò4Ü×$Ò$ Q§X¡XÔ.Ø—‘—’ Õ&•Ø—6‘6Ò%Ø—F‘F—K‘K×%Ñ% iÖ0ñ &ä˜Aœz×*Ô*Ü—’˜qŸx™x¨Ô+Ø—6‘6Ô%Ø—F‘F—K‘K×%Ñ% i×0ô "ó r   c                  óB   a € ] tR t^ItRtRR V 3R llltR R ltRtV ;t# )ÚResidualDenseBlockz¯Residual Dense Block, used inside the :class:`RRDB` block of ESRGAN.

Args:
    num_feat: Channel number of intermediate features.
    num_grow_ch: Channels for each growth.

c               ó$   € V ^8„  d   QhRRRRRR/# ©r
   Únum_featÚintÚnum_grow_chr   r   r   )r   s   "r   r   ÚResidualDenseBlock.__annotate__R   s&   € ÷ añ a ð a¸ð aÀTñ ar   c                	óx  <€ \         SV `  4        \        P                  ! W^^^4      V n        \        P                  ! W,           V^^^4      V n        \        P                  ! V^V,          ,           V^^^4      V n        \        P                  ! V^V,          ,           V^^^4      V n        \        P                  ! V^V,          ,           V^^^4      V n        \        P                  ! RRR7      V n
        \        V P                  V P
                  V P                  V P                  V P                  .R4       R# )é   çš™™™™™É?T©Únegative_slopeÚinplacegš™™™™™¹?N)ÚsuperÚ__init__r   r   Úconv1Úconv2Úconv3Úconv4Úconv5Ú	LeakyReLUÚlrelur%   ©Úselfr*   r,   Ú	__class__s   &&&€r   r5   ÚResidualDenseBlock.__init__R   sà   ø€ Ü‰ÑÔÜ—Y’Y˜x°a¸¸AÓ>ˆŒ
Ü—Y’Y˜xÕ5°{ÀAÀqÈ!ÓLˆŒ
Ü—Y’Y˜x¨!¨k­/Õ9¸;ÈÈ1ÈaÓPˆŒ
Ü—Y’Y˜x¨!¨k­/Õ9¸;ÈÈ1ÈaÓPˆŒ
Ü—Y’Y˜x¨!¨k­/Õ9¸8ÀQÈÈ1ÓMˆŒ
ä—\’\°¸dÔCˆŒ
ô 	˜tŸz™z¨4¯:©:°t·z±zÀ4Ç:Á:ÈtÏzÉzÐZÐ\_Ö`r   c               ó    € V ^8„  d   QhRRRR/# ©r
   Úxztorch.Tensorr   r   )r   s   "r   r   r-   _   s   € ÷ ñ ˜ð ¨,ñ r   c           
     óü  € V P                  V P                  V4      4      pV P                  V P                  \        P                  ! W3^4      4      4      pV P                  V P                  \        P                  ! WV3^4      4      4      pV P                  V P                  \        P                  ! WW43^4      4      4      pV P                  \        P                  ! WW4V3^4      4      pVR,          V,           # )z7Run the dense block on ``x`` of shape ``(B, C, H, W)``.r0   )r<   r6   r7   ÚtorchÚcatr8   r9   r:   )r>   rC   Úx1Úx2Úx3Úx4Úx5s   &&     r   ÚforwardÚResidualDenseBlock.forward_   s¶   € à�Z‰Z˜Ÿ
™
 1›Ó&ˆØ�Z‰Z˜Ÿ
™
¤5§9¢9¨a¨W°aÓ#8Ó9Ó:ˆØ�Z‰Z˜Ÿ
™
¤5§9¢9¨a°R¨[¸!Ó#<Ó=Ó>ˆØ�Z‰Z˜Ÿ
™
¤5§9¢9¨a°R¨_¸aÓ#@ÓAÓBˆØ�Z‰ZœŸ	š	 1¨"°"Ð"5°qÓ9Ó:ˆà�C�x˜!�|Ðr   )r6   r7   r8   r9   r:   r<   )é@   é    ©	Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r5   rL   Ú__static_attributes__Ú__classcell__©r?   s   @r   r'   r'   I   s   ø† ñ÷aò a÷ó r   r'   c                  óB   a € ] tR t^jtRtRR V 3R llltR R ltRtV ;t# )ÚRRDBz¨Residual in Residual Dense Block, used in RRDB-Net of ESRGAN.

Args:
    num_feat: Channel number of intermediate features.
    num_grow_ch: Channels for each growth.

c               ó$   € V ^8„  d   QhRRRRRR/# r)   r   )r   s   "r   r   ÚRRDB.__annotate__s   s!   € ÷ >ñ > ð >°3ð >Àñ >r   c                	ó„   <€ \         SV `  4        \        W4      V n        \        W4      V n        \        W4      V n        R # )N)r4   r5   r'   Úrdb1Úrdb2Úrdb3r=   s   &&&€r   r5   ÚRRDB.__init__s   s2   ø€ Ü‰ÑÔÜ& xÓ=ˆŒ	Ü& xÓ=ˆŒ	Ü& xÓ=ˆŽ	r   c               ó    € V ^8„  d   QhRRRR/# rB   r   )r   s   "r   r   r\   y   s   € ÷ ñ ˜ð ¨,ñ r   c                óˆ   € V P                  V4      pV P                  V4      pV P                  V4      pVR,          V,           # )zFRun the three stacked dense blocks on ``x`` of shape ``(B, C, H, W)``.r0   ©r^   r_   r`   )r>   rC   Úouts   && r   rL   ÚRRDB.forwardy   s7   € à�i‰i˜‹lˆØ�i‰i˜‹nˆØ�i‰i˜‹nˆà�S�y˜1�}Ðr   rd   )rO   rP   rX   s   @r   rZ   rZ   j   s   ø† ñ÷>ò >÷ó r   rZ   c                  óB   a € ] tR t^‚tRtRR V 3R llltR R ltRtV ;t# )r   až  Network consisting of Residual in Residual Dense Blocks, as used in ESRGAN and Real-ESRGAN.

ESRGAN is extended here for scale x2 and scale x1. For those scales the input is first
pixel-unshuffled -- the inverse of a pixel shuffle -- to reduce the spatial size and enlarge the
channel size before it is fed into the main ESRGAN architecture, so the network always upsamples
by a factor of 4 internally.

Args:
    num_in_ch: Channel number of inputs.
    num_out_ch: Channel number of outputs.
    scale: Upsampling factor. One of ``1``, ``2`` or ``4``.
    num_feat: Channel number of intermediate features.
    num_block: Block number in the trunk network.
    num_grow_ch: Channels for each growth.

Shape:
    - Input: :math:`(B, C_{in}, H, W)`. For ``scale=2`` both spatial sizes must be divisible by
      2, and for ``scale=1`` by 4.
    - Output: :math:`(B, C_{out}, H \cdot scale, W \cdot scale)`.

Raises:
    ValueError: If ``scale`` is not ``1``, ``2`` or ``4``.

Example:
    >>> import torch
    >>> model = RRDBNet(num_in_ch=3, num_out_ch=3, scale=4, num_feat=8, num_block=1, num_grow_ch=4)
    >>> model(torch.rand(1, 3, 8, 8)).shape
    torch.Size([1, 3, 32, 32])

c               ó4   € V ^8„  d   QhRRRRRRRRRRRRRR	/# )
r
   Ú	num_in_chr+   Ú
num_out_chr   r*   Ú	num_blockr,   r   r   r   )r   s   "r   r   ÚRRDBNet.__annotate__¢   sY   € ÷ Dñ DàðDð ðDð ð	Dð
 ðDð ðDð ðDð 
ñDr   c           
     	óÀ  <€ \         SV `  4        VR9  d   \        RV 24      hW0n        V^8X  d   V^,          pMV^8X  d
   V^,          p\        P
                  ! W^^^4      V n        \        P                  ! \        V4       Uu. uF  p\        WFR7      NK  	  up!  V n
        \        P
                  ! WD^^^4      V n        \        P
                  ! WD^^^4      V n        \        P
                  ! WD^^^4      V n        \        P
                  ! WD^^^4      V n        \        P
                  ! WB^^^4      V n        \        P                   ! RRR7      V n        R# u upi )é   zscale must be 1, 2 or 4, got )r*   r,   r0   Tr1   N)rn   r
   é   )r4   r5   Ú
ValueErrorr   r   r   Ú
conv_firstÚ
SequentialÚrangerZ   ÚbodyÚ	conv_bodyÚconv_up1Úconv_up2Úconv_hrÚ	conv_lastr;   r<   )	r>   ri   rj   r   r*   rk   r,   Ú_r?   s	   &&&&&&& €r   r5   ÚRRDBNet.__init__¢   s  ø€ ô 	‰ÑÔØ˜	Ô!ô Ð<¸U¸GÐDÓEÐEØŒ
Ø�AŒ:Ø! A�‰IØ�aŒZØ! B�ˆIÜŸ)š) I¸¸A¸qÓAˆŒÜ—M’MÔ^cÐdmÔ^nÓ#oÑ^nÐYZ¤D°(×$TÑ^nÑ#oÑpˆŒ	ÜŸš 8°q¸!¸QÓ?ˆŒäŸ	š	 (°a¸¸AÓ>ˆŒÜŸ	š	 (°a¸¸AÓ>ˆŒÜ—y’y °Q¸¸1Ó=ˆŒÜŸš 8¸¸A¸qÓAˆŒä—\’\°¸dÔCˆŽ
ùò $ps   ÂEc               ó    € V ^8„  d   QhRRRR/# rB   r   )r   s   "r   r   rl   À   s   € ÷ >ñ >˜ð >¨,ñ >r   c           
     óZ  € V P                   ^8X  d   \        P                  ! V^R7      pM,V P                   ^8X  d   \        P                  ! V^R7      pMTpV P                  V4      pV P	                  V P                  V4      4      pW#,           pV P                  V P                  \        P                  ! V^RR7      4      4      pV P                  V P                  \        P                  ! V^RR7      4      4      pV P                  V P                  V P                  V4      4      4      # )zISuper-resolve ``x`` of shape :math:`(B, C_{in}, H, W)` by ``self.scale``.)Údownscale_factorÚnearest)Úscale_factorÚmode)r   ÚFÚpixel_unshufflerq   ru   rt   r<   rv   Úinterpolaterw   ry   rx   )r>   rC   ÚfeatÚ	body_feats   &&  r   rL   ÚRRDBNet.forwardÀ   sØ   € à�:‰:˜Œ?Ü×$Ò$ Q¸Ô;‰DØ�Z‰Z˜1Œ_Ü×$Ò$ Q¸Ô;‰DàˆDØ�‰˜tÓ$ˆØ—N‘N 4§9¡9¨T£?Ó3ˆ	ØÕˆà�z‰z˜$Ÿ-™-¬¯ª°dÈÐQZÔ([Ó\Ó]ˆØ�z‰z˜$Ÿ-™-¬¯ª°dÈÐQZÔ([Ó\Ó]ˆØ�~‰~˜dŸj™j¨¯©°dÓ);Ó<Ó=Ð=r   )	rt   ru   rq   rx   ry   rv   rw   r<   r   )ro   rN   é   rO   rP   rX   s   @r   r   r   ‚   s   ø† ñ÷>Dò D÷<>ó >r   )g      ð?g        )rU   Ú
__future__r   Útypingr   r   rE   Útorch.nn.functionalr   Ú
functionalr‚   Útorch.nnr   Útorch.nn.modules.batchnormr   Ú__all__Úno_gradr%   r   r'   rZ   r   r   r   r   Ú<module>r‘      sx   ðñ$õ  #ç "ã ß Ð Ý Ý Ý 1àˆ+€ð ‡‚ƒö1ó ð1ô2˜Ÿ™ô ôBˆ2�9‰9ô ô0L>ˆb�i‰iö L>r   