+
     åûjÎX  ã                   óB  € R t ^ RIHt ^ RIHtHtHtHtHt ^ RI	t	^ RI	H
t
 ^ RIHt ^ RIHt ^ RIHt ^ RIHtHtHtHt ^ R	IHt ^ R
IHtHt ^ RIHt ^ RIHt . ROt^àt RRRRRRRR/t!] ! R R4      4       t" ! R R]]",          ]4      t# ! R R4      t$ ! R R4      t%R# )aq  Upscale RGB images with pretrained super-resolution networks: Real-ESRGAN generators or a small sub-pixel network.

The builders' models return RGB images clamped to :math:`[0, 1]`.

Which class to use:

- Upscale by 4 or 2 without resizing the input first, with Real-ESRGAN weights: :class:`RRDBNetBuilder`.
- Upscale a 224 x 224 resize of every input by 3 with a small network: :class:`SmallSRBuilder`.
- Pick either builder from one dataclass: :class:`SuperResolutionConfig`, passed to
  ``SuperResolution.from_config``.
- Your own super-resolution network with its own pre- and post-processing: :class:`SuperResolution`.
)Ú	dataclass)ÚAnyÚListÚOptionalÚTupleÚUnionN)Únn)Úload_state_dict_from_url)ÚPILImage)Úonnx)ÚONNXExportMixinÚ_has_forward_hooksÚ_preserved_rngÚ_returns_per_image_outputs)Ú	ModelBase)ÚOutputRangePostProcessorÚResizePreProcessor)ÚRRDBNet)ÚSmallSRNetWrapperÚRRDBNetBuilderÚSmallSRBuilderÚSuperResolutionÚSuperResolutionConfigÚRealESRGAN_x4pluszUhttps://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.0/RealESRGAN_x4plus.pthÚRealESRNet_x4pluszUhttps://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.1/RealESRNet_x4plus.pthÚRealESRGAN_x4plus_anime_6Bz`https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.2.4/RealESRGAN_x4plus_anime_6B.pthÚRealESRGAN_x2pluszUhttps://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.1/RealESRGAN_x2plus.pthc                   ó@   a € ] tR t^=t o RtRtRt^tRtV 3R lt	Rt
V tR# )r   a  Choose a super-resolution model by name, to build with SuperResolution.from_config.

``sr = SuperResolution.from_config(SuperResolutionConfig("RealESRGAN_x4plus"))`` builds that model with
:meth:`RRDBNetBuilder.build`; ``"small_sr"``, the default, builds with :meth:`SmallSRBuilder.build`. The fields
are the arguments of those builders: ``upscale_factor`` and ``image_size`` apply only to ``"small_sr"``.

Args:
    model_name: Name of the model variant to build. RRDB variants are
        ``"RealESRGAN_x4plus"``, ``"RealESRNet_x4plus"``,
        ``"RealESRGAN_x4plus_anime_6B"`` and ``"RealESRGAN_x2plus"``, spelled exactly;
        the lightweight variant is ``"small_sr"``, in any case.
    pretrained: If ``True``, load pretrained weights for the selected variant.
    upscale_factor: Integer scale of ``"small_sr"`` (see :meth:`SmallSRBuilder.build`). Ignored by
        the RRDB variants, whose scale is fixed by ``model_name``.
    image_size: The fixed input size of ``"small_sr"`` for ONNX export (see :meth:`SmallSRBuilder.build`).

See Also:
    - :class:`SuperResolution`: the model that :meth:`SuperResolution.from_config` builds from this.
    - :class:`RRDBNetBuilder`: builds the RRDB variants directly.
    - :class:`SmallSRBuilder`: builds ``"small_sr"`` directly.

Úsmall_srTNc                óZ   <€ V ^8„  d   Qh/ S[ ;R&   S[;R&   S[;R&   S[S[,          ;R&   # )é   Ú
model_nameÚ
pretrainedÚupscale_factorÚ
image_size)ÚstrÚboolÚintr   )ÚformatÚ__classdict__s   "€Ú[C:\Ai_Coding\apps\studio\ComfyUI\.venv\Lib\site-packages\kornia\contrib\super_resolution.pyÚ__annotate__Ú"SuperResolutionConfig.__annotate__=   s=   ø‡ ‚ ñ2 Ñ ñ3 ñ4 Ññ5 ñ6 Ññ7 ñ8 ™•Ñ$ò9 ó    © )Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r!   r"   r#   r$   Ú__annotate_func__Ú__static_attributes__Ú__classdictcell__©r)   s   @r*   r   r   =   s'   ø‡ € ñð. !€JØ€JØ€NØ $€J÷9 ƒ r-   c                   ó  a a€ ] tR t^\t oRtRtRV3R lV 3R lllt]V3R lR l4       t]	P                  ! 4       V3R lR l4       tRV3R	 lR
 lltRV3R lR lltRV3R lR lltV3R lR ltV3R lR ltV3R ltRtVtV ;t# )r   a_  Run a super-resolution network on RGB images with its pre- and post-processing.

``sr = SuperResolution(model, pre_processor, post_processor)`` wraps a super-resolution network.
``out = sr(images)`` takes a ``(B, 3, H, W)`` tensor or a list of ``(3, H, W)`` images, runs
``pre_processor``, ``model`` and ``post_processor`` in turn, and returns what the post-processor returns. For the
pretrained models, use :class:`RRDBNetBuilder`, :class:`SmallSRBuilder` or :meth:`from_config`.

See Also:
    - :class:`RRDBNetBuilder`: Real-ESRGAN weights, x4 or x2, without resizing the input first.
    - :class:`SmallSRBuilder`: a small network that upscales a 224 x 224 resize by 3.
    - :class:`SuperResolutionConfig`: picks either builder by name, for :meth:`from_config`.
    - :func:`~kornia.geometry.transform.resize`: interpolation to any size, without a network.

Úsuper_resolutionc          
      ó‚   <€ V ^8„  d   QhRS[ P                  RS[ P                  RS[ P                  RS[S[,          RR/# )r    ÚmodelÚpre_processorÚpost_processorÚnameÚreturnN)r   ÚModuler   r%   )r(   r)   s   "€r*   r+   ÚSuperResolution.__annotate__q   sM   ø€ ÷ &ñ &á�y‰yð&ñ —y‘yð&ñ Ÿ	™	ð	&ñ
 ‘s�mð&ð 
ñ&r-   c                ó¤   <€ \         SV `  4        VP                  4       V n        W n        W0n        Ve   W@n        RV n        RV n        RV n	        R# )a  Initialize SuperResolution.

Args:
    model: The super-resolution network.
    pre_processor: Pre-processing module applied to the input images.
    post_processor: Post-processing module applied to the network output.
    name: Optional name, used by :meth:`save` for file names.

N)
ÚsuperÚ__init__Úevalr;   r<   r=   r>   Úinput_image_sizeÚoutput_image_sizeÚpseudo_image_size)Úselfr;   r<   r=   r>   Ú	__class__s   &&&&&€r*   rD   ÚSuperResolution.__init__q   sN   ø€ ô  	‰ÑÔØ—Z‘Z“\ˆŒ
Ø*ÔØ,ÔØÒØŒIð !%ˆÔØ!%ˆÔØ!%ˆÖr-   c                ó$   <€ V ^8„  d   QhRS[ RR/# )r    Úconfigr?   r   )r   )r(   r)   s   "€r*   r+   rA   �   s!   ø€ ÷ `ñ `Ñ1ð `Ð6Gñ `r-   c                ót  € V P                   P                  4       R8X  dB   \        P                  V P                   V P                  V P
                  V P                  R7      # V P                   \        9  d   \        RV P                    R24      h\        P                  V P                   V P                  R7      # )a¡  Build a super-resolution model from a configuration object.

Dispatches to :class:`SmallSRBuilder` for the lightweight variant and to
:class:`RRDBNetBuilder` for the RRDB variants.

Args:
    config: Super-resolution configuration. See :class:`SuperResolutionConfig`.

Returns:
    A :class:`SuperResolution` wrapper ready for inference.

Raises:
    ValueError: If ``config.model_name`` is not a supported variant.

r   )r!   r"   r#   r$   úModel z‡ not found. Please choose from 'small_sr', 'RealESRGAN_x4plus', 'RealESRNet_x4plus', 'RealESRGAN_x4plus_anime_6B', 'RealESRGAN_x2plus'.)r!   r"   )
r!   Úlowerr   Úbuildr"   r#   r$   Ú_URLsÚ
ValueErrorr   )rM   s   &r*   Úfrom_configÚSuperResolution.from_configŽ   s°   € ð" ×Ñ×"Ñ"Ó$¨
Ô2Ü!×'Ñ'Ø!×,Ñ,Ø!×,Ñ,Ø%×4Ñ4Ø!×,Ñ,ð	 (ó ð ð ×Ñ¤EÔ)ÜØ˜×*Ñ*Ð+ð ,'ð 'óð ô
 ×#Ñ#¨v×/@Ñ/@ÈV×M^ÑM^Ð#Ó_Ð_r-   c                óÂ   <€ V ^8„  d   QhRS[ S[P                  S[S[P                  ,          3,          RS[ S[P                  S[S[P                  ,          3,          /# )r    Úimagesr?   )r   ÚtorchÚTensorr   )r(   r)   s   "€r*   r+   rA   ¯   sP   ø€ ÷ /ñ /™e¡E§L¡L±$±u·|±|Õ2DÐ$DÕEð /É%ÑPU×P\ÑP\Ñ^bÑch×coÑcoÕ^pÐPpÕJqñ /r-   c                ó<  € V P                  V4      p\        V\        4      '       d
   V^ ,          MTp\        V\        4      '       d/   V Uu. uF!  q0P	                  VR,          4      ^ ,          NK#  	  ppMV P	                  V4      pV P                  V4      # u upi )aY  Forward pass of the super resolution model.

Args:
    images: If list of RGB images. Each image is a torch.Tensor with shape ``(3, H, W)``.
        If torch.Tensor, a torch.Tensor with shape ``(B, 3, H, W)``.

Returns:
    What the post-processor returns: for the builders' models, see :class:`RRDBNetBuilder` and
    :class:`SmallSRBuilder`.

N)r<   Ú
isinstanceÚtupleÚlistr;   r=   )rI   rW   ÚoutputÚimageÚ
out_imagess   &&   r*   ÚforwardÚSuperResolution.forward®   s†   € ð ×#Ñ# FÓ+ˆä(¨´×7Ò7�˜–¸VˆÜ�fœd×#Ò#ÙBHÓIÁ&¸Ÿ*™* U¨4¥[Ó1°!×4Ð4Á&ˆJÐIˆJàŸ™ FÓ+ˆJØ×"Ñ" :Ó.Ð.ùò Js   Á'Bc                ó>  <€ V ^8„  d   QhRS[ S[P                  S[S[P                  ,          3,          RS[S[ S[P                  S[S[P                  ,          3,          ,          RS[RS[ S[P                  S[S[P                  ,          S[R,          3,          /# )r    rW   Ú	edge_mapsÚoutput_typer?   zImage.Image©r   rX   rY   r   r   r%   )r(   r)   s   "€r*   r+   rA   Ä   s„   ø€ ÷ 9ñ 9á‘e—l‘l¡D©¯©Õ$6Ð6Õ7ð9ñ ™E¡%§,¡,±±U·\±\Õ0BÐ"BÕCÕDð9ñ ð	9ñ
 
‰u�|‰|™T¡%§,¡,Õ/±°mÕ1DÐDÕ	Eñ9r-   c                ó†   € Vf   V P                  V4      p. pV F  pVP                  V4       K  	  V P                  WC4      # )aV  Collect the super-resolved images for display.

Args:
    images: input torch.Tensor.
    edge_maps: super-resolved images; computed with :meth:`forward` when None.
    output_type: ``"torch"`` or ``"pil"``.

Returns:
    A list with one ``(3, H', W')`` image per super-resolved image, or a list of PIL images for
    ``output_type="pil"``.

)ra   ÚappendÚ_tensor_to_type)rI   rW   rd   re   r^   Úedge_maps   &&&&  r*   Ú	visualizeÚSuperResolution.visualizeÄ   sF   € ð$ ÒØŸ™ VÓ,ˆIØˆÛ!ˆHØ�M‰M˜(Ö#ñ "ð ×#Ñ# FÓ8Ð8r-   c          
      óò   <€ V ^8„  d   QhRS[ S[P                  S[S[P                  ,          3,          RS[S[ S[P                  S[S[P                  ,          3,          ,          RS[S[,          RS[RR/# )r    rW   rd   Ú	directoryre   r?   Nrf   )r(   r)   s   "€r*   r+   rA   Þ   st   ø€ ÷ =ñ =á‘e—l‘l¡D©¯©Õ$6Ð6Õ7ð=ñ ™E¡%§,¡,±±U·\±\Õ0BÐ"BÕCÕDð=ñ ™C•=ð	=ñ
 ð=ð 
ñ=r-   c                óv   € V P                  WV4      pV P                  WRR7       V P                  WSRR7       R# )aL  Save the input images and their super-resolved images as PNG files.

Args:
    images: input torch.Tensor.
    edge_maps: super-resolved images; computed with :meth:`forward` when None.
    directory: where to save outputs.
    output_type: "torch" or "pil", passed to :meth:`visualize`; the files hold the same pixels either way.

Ú_src)ÚsuffixÚ_srN)rk   Ú_save_outputs)rI   rW   rd   rn   re   Úoutputss   &&&&& r*   ÚsaveÚSuperResolution.saveÞ   s:   € ð  —.‘. °KÓ@ˆØ×Ñ˜6°VÐÔ<Ø×Ñ˜7°eÐÖ<r-   c                ó‚   <€ V ^8„  d   QhRS[ S[,          RS[RS[RS[ S[S[S[S[3,          ,          ,          RS[RR/# )r    Ú	onnx_nameÚinclude_pre_and_post_processorru   Úadditional_metadataÚkwargsr?   zonnx.ModelProto)r   r%   r&   r   r   r   )r(   r)   s   "€r*   r+   rA   ò   se   ø€ ÷ Iñ Iá™C•=ðIñ )-ðIñ ð	Iñ
 &¡d©5±±c°­?Õ&;Õ<ðIñ ðIð 
ñIr-   c                ó  € Vf   RV P                    R2pV P                  ;'       g    V P                  ;'       g    Rp^^Wf.pRpV'       dR   V P                  4       '       g<   \	        4       ;_uu_ 4        \        V \        P                  ! V4      4      pRRR4       V'       d   ^MRp	V P                  V4      ;_uu_ 4        \        P                  ! V V3RT	^V P                  ;'       g    RV P                  ;'       g    R.RT	^V P                  ;'       g    RV P                  ;'       g    R.RTRV'       d   T MV P                  R	VR
V/VB uuRRR4       #   + '       g   i     LÐ; i  + '       g   i     R# ; i)a	  Export the current super resolution model to an ONNX model file.

Args:
    onnx_name:
        The name of the output ONNX file. If not provided, ``"kornia_<name>.onnx"``, with the model's
        ``name``, for example ``"kornia_small_sr.onnx"``.
    include_pre_and_post_processor:
        Whether to include the pre-processor and post-processor in the exported model.
    save:
        If True, write the model to ``onnx_name``; it is returned either way.
    additional_metadata:
        Additional metadata to add to the ONNX model.
    kwargs: Additional keyword arguments of :func:`torch.onnx.export`.

Returns:
    The exported ONNX model.

Raises:
    ValueError: With the pre- and post-processor, if the output is a list (or tuple) with one image per input
        image and the exported batch is dynamic, from a ``dynamic_axes`` or ``dynamic_shapes`` argument or,
        with the TorchScript exporter, because the list comes only for more than one image.

Note:
    With the pre- and post-processor, an output that is a list with one image per input image, or a tuple as
    long as the batch at two batch sizes, is exported for a batch of one image: the exporters turn such a
    sequence into one graph output per traced image, so a dynamic batch would return the traced batch's
    images at any batch size. The list comes from a post-processor that
    returns one, from the network itself, or from a pre-processor that returns a list of images, which
    :meth:`forward` runs through the network one at a time. Known tensor-output networks (the builders'
    RRDB and SmallSR networks, ``nn.Identity`` and ``nn.Conv2d``) with ``nn.Identity`` or ``ResizePreProcessor``
    before them and ``nn.Identity`` or ``OutputRangePostProcessor`` after them keep a dynamic batch without a
    probe, provided the wrapper and each component retain their known ``forward`` implementations and no
    forward hook applies to them, a global one included. Other combinations are probed on one image at the
    export size in eval mode, without gradients and outside the export. A list result requires a fixed batch;
    a tensor result is checked again on the actual tracing batch before accepting a dynamic graph. A dynamic
    graph with per-image outputs raises a ``ValueError`` after the export, before anything is saved.

NÚkornia_z.onnxi`  Úinput_shapeÚoutput_shapeÚpseudo_shaper;   ru   rz   éÿÿÿÿ)r>   rH   rF   Ú#_returns_one_tensor_without_a_prober   r   rX   ÚrandÚ_onnx_output_kind_keptr   Úto_onnxrG   r;   )
rI   rx   ry   ru   rz   r{   Úpseudo_sizer€   Ú	per_imageÚbatchs
   &&&&&,    r*   r…   ÚSuperResolution.to_onnxò   sn  € ð\ ÒØ! $§)¡) ¨EÐ2ˆIð ×,Ñ,×LÐL°×0EÑ0E×LÐLÈˆØ˜1˜kÐ7ˆð ˆ	ß)°$×2ZÑ2Z×2\Ò2\ô  ×!Õ!Ü6°t¼U¿ZºZÈÓ=UÓV�	÷ "ç‘ Bˆà×(Ñ(¨×3Õ3Ü"×*Ò*ØØñ
ð # A t×'<Ñ'<×'BÐ'BÀÀD×DYÑDY×D_ÐD_Ð]_Ð`ð
ð $ Q¨×(>Ñ(>×(DÐ(DÀ"Àd×F\ÑF\×FbÐFbÐ`bÐcð	
ð
 *ð
÷ =‘dÀ$Ç*Á*ð
ð ð
ð %8ð
ð ñ
÷ 4Ò3÷	 "×!ú÷ 4×3Ð3ús0   Á6!EÃ>E2ÄE2ÄE2Ä1E2Ä?E2ÅE/	Å2F	c                ó    <€ V ^8„  d   QhRS[ /# )r    r?   )r&   )r(   r)   s   "€r*   r+   rA   =  s   ø€ ÷ 
ñ 
±Tñ 
r-   c                óÞ  € \        V P                  RR4      p\        \        V P                  RR4      RR4      p\        \        V P                  RR4      RR4      p\        \        V P                  RR4      RR4      p\        V 4      '       * ;'       dÚ    V\        P                  J ;'       dÀ    V\        P                  P                  \        P                  P                  \        P                  \        P                  39   ;'       dc    V\        P                  P                  \        P                  39   ;'       d.    V\        P                  P                  \        P                  39   # )a)  Whether the wrapper, network and processors have known tensor-batch forward implementations.

Unknown networks and overridden forwards need a probe even with the builders' processors. The builders'
RRDB and SmallSR networks avoid an expensive extra forward when all implementations are unchanged.
Ú__func__Nra   )Úgetattrra   r;   r<   r=   r   r   r   ÚIdentityÚConv2dr   r   r   r   )rI   ra   ÚnetworkÚpreÚposts   &    r*   r‚   Ú3SuperResolution._returns_one_tensor_without_a_probe=  s+  € ô ˜$Ÿ,™,¨
°DÓ9ˆÜœ' $§*¡*¨i¸Ó>À
ÈDÓQˆÜ”g˜d×0Ñ0°)¸TÓBÀJÐPTÓUˆÜ”w˜t×2Ñ2°I¸tÓDÀjÐRVÓWˆä" 4Ó(Ô(÷ Pð PØœ?×2Ñ2Ð2÷Pð PàœBŸK™K×/Ñ/´·±×1BÑ1BÄGÇOÁOÔUf×UnÑUnÐoÑo÷Pð Pð œŸ™×+Ñ+Ô-?×-GÑ-GÐHÑH÷Pð Pð œŸ™×,Ñ,Ô.F×.NÑ.NÐOÑOð	
r-   c                ó<   <€ V ^8„  d   QhRS[ RS[ RS[S[,          /# )r    ÚmoduleÚdummy_inputr?   )r   r   r%   )r(   r)   s   "€r*   r+   rA   P  s'   ø€ ÷ 
ñ 
©Sð 
¹sð 
ÁxÑPSÅ}ñ 
r-   c                óp   € WJg.   V P                  4       '       g   V P                  V4      '       g   R #  R# )NzíUse a network that returns one tensor for the batch, with a pre-processor that hands it one tensor and a post-processor that keeps it one, such as nn.Identity or ResizePreProcessor and OutputRangePostProcessor, to export a dynamic batch.)r‚   Ú_onnx_returns_per_image_outputs)rI   r•   r–   s   &&&r*   Ú_onnx_fixed_batch_hintÚ&SuperResolution._onnx_fixed_batch_hintP  s6   € àÓØ×7Ñ7×9Ò9Ø×7Ñ7¸×DÒDáðCñ	
r-   c                óz   <€ V ^8„  d   Qh/ S[ ;R&   S[S[,          ;R&   S[S[,          ;R&   S[S[,          ;R&   # )r    r>   rF   rG   rH   )r%   r   r'   )r(   r)   s   "€r*   r+   rA   \   sE   ø‡ ‚ ñ  Ñ"ñ! ñ" ™s•mÑ#ñ# ñ$  ¡•}Ñ$ñ% ñ&  ¡•}Ñ$ò' r-   )rF   r;   r>   rG   r=   r<   rH   )N)NrX   )NNrX   )NTTN)r/   r0   r1   r2   r3   r>   rD   ÚstaticmethodrT   rX   Úinference_modera   rk   ru   r…   r‚   r™   r4   r5   r6   Ú__classcell__)rJ   r)   s   @@r*   r   r   \   s‹   ù‡ € ñð #€D÷
&õ &ð: ÷`ó ð`ð> ×ÒÓ÷/ó ð/÷*9ò 9÷4=ò =÷(Iò I÷V
ð 
÷&
ð 
÷i … r-   c                   óD   a € ] tR tRt o Rt]RV 3R lR ll4       tRtV tR# )r   i^  a  Build a SuperResolution model around a Real-ESRGAN RRDB generator that upscales by 4 or 2.

``sr = RRDBNetBuilder.build("RealESRNet_x4plus")`` downloads the released Real-ESRGAN weights on first use and
returns a :class:`SuperResolution`. ``out = sr(images)`` upscales RGB images without resizing them first: a
``(B, 3, H, W)`` tensor becomes ``(B, 3, 4 H, 4 W)``, or ``(B, 3, 2 H, 2 W)`` for ``"RealESRGAN_x2plus"``,
clamped to :math:`[0, 1]`. A list of ``(3, H, W)`` images, of any sizes, returns a list.

See Also:
    - :class:`SmallSRBuilder`: a small network that upscales a 224 x 224 resize by 3.
    - :class:`~kornia.models.RRDBNet`: the generator itself, to train or to load other weights.
    - :class:`SuperResolutionConfig`: picks this builder or the other by name.

c                ó,   <€ V ^8„  d   QhRS[ RS[RS[/# )r    r!   r"   r?   )r%   r&   r   )r(   r)   s   "€r*   r+   ÚRRDBNetBuilder.__annotate__n  s#   ø€ ÷ (
ñ (
™#ð (
Áð (
ÑQ`ñ (
r-   c           	     óÞ  € V R9   d   \        ^^^@^^ ^R7      pMAV R8X  d   \        ^^^@^^ ^R7      pM(V R8X  d   \        ^^^@^^ ^R7      pM\        RV  R24      hV'       dP   \        \        V ,          \        P
                  ! R4      R7      pTP                  TRV9   d   RMR	,          R
R7       VP                  4        \        V\        P                  ! 4       \        RRR7      V R7      # )a  Build a Real-ESRGAN super-resolution model.

Args:
    model_name: Name of the RRDB variant to construct, spelled exactly: ``"RealESRGAN_x4plus"`` and
        ``"RealESRNet_x4plus"`` (23 blocks, x4), ``"RealESRGAN_x4plus_anime_6B"`` (6 blocks, x4) and
        ``"RealESRGAN_x2plus"`` (23 blocks, x2), which needs even ``H`` and ``W``.
    pretrained: If ``True``, download and load pretrained weights for the
        selected model variant; otherwise the network is randomly initialized.

Returns:
    A :class:`SuperResolution` wrapper ready for inference.

Raises:
    ValueError: If ``model_name`` is not one of the supported variants.
)Ú	num_in_chÚ
num_out_chÚnum_featÚ	num_blockÚnum_grow_chÚscaler   r   rO   z{ not found. Please choose from 'RealESRGAN_x4plus', 'RealESRNet_x4plus', 'RealESRGAN_x4plus_anime_6B', 'RealESRGAN_x2plus'.Úcpu)Úmap_locationÚ
params_emaÚparamsT)Ústrictg        g      ð?)Úmin_valÚmax_val©r<   r=   r>   )r   r   )r   rS   r	   rR   rX   ÚdeviceÚload_state_dictrE   r   r   rŽ   r   )r!   r"   r;   Ú
checkpoints   &&  r*   rQ   ÚRRDBNetBuilder.buildm  sø   € ð" ÐCÔCÜ a°AÀÈbÐ^`ÐhiÔj‰EØÐ7Ô7Ü a°AÀÈaÐ]_ÐghÔi‰EØÐ.Ô.Ü a°AÀÈbÐ^`ÐhiÔj‰EäØ˜˜ð %oð oóð ÷
 ô 2´%¸
Õ2CÔRW×R^ÒR^Ð_dÓReÔfˆJØ×!Ñ! *¸\ÈZÔ=W©\Ð]eÕ"fÐosÐ!ÔtØ�
‰
ŒäØÜŸ+š+›-Ü3¸CÈÔMØô	
ð 	
r-   r.   N)r   T©	r/   r0   r1   r2   r3   rœ   rQ   r5   r6   r7   s   @r*   r   r   ^  s#   ø‡ € ñð ÷(
ñ (
ó ö(
r-   c                   óD   a € ] tR tRt o Rt]RV 3R lR ll4       tRtV tR# )r   i™  aD  Build a SuperResolution model around a small sub-pixel network that upscales a 224 x 224 resize.

``sr = SmallSRBuilder.build()`` downloads the weights on first use and returns a :class:`SuperResolution`.
``out = sr(images)`` resizes each RGB image in :math:`[0, 1]` to 224 x 224, discarding its aspect ratio, and
returns one ``(B, 3, 224 r, 224 r)`` tensor in :math:`[0, 1]`, ``r = upscale_factor``.

See Also:
    - :class:`RRDBNetBuilder`: Real-ESRGAN weights, x4 or x2, keeping the aspect ratio.
    - :class:`SuperResolutionConfig`: picks this builder or the other by name.

Nc          
      óH   <€ V ^8„  d   QhRS[ RS[RS[RS[S[,          RS[/# )r    r!   r"   r#   r$   r?   )r%   r&   r'   r   r   )r(   r)   s   "€r*   r+   ÚSmallSRBuilder.__annotate__§  s;   ø€ ÷ -ñ -Ùð-Ù26ð-ÙORð-ÙdlÑmpÕdqð-á	ñ-r-   c                ó.  € V P                  4       R8X  d   \        W!R7      pM\        RV  R24      h\        V\	        \
        \
        4      \        P                  ! 4       V R7      p\
        V,          Vn        Vf   \
        Vn	        V# W5n
        W5n	        V# )aœ  Build the small super-resolution model.

Args:
    model_name: Name of the model variant to build. Only ``"small_sr"`` (any case) is supported.
    pretrained: If ``True``, load pretrained weights for the selected model.
    upscale_factor: Integer scale used by ``SmallSRNetWrapper``. The pre-processor
        first resizes every input to 224 x 224, discarding its aspect ratio, so the
        output is ``224 * upscale_factor`` square: with ``3``, a 100 x 50 and a
        480 x 640 input both give 672 x 672. Pretrained weights exist only for
        ``3``; another factor with ``pretrained=True`` raises a size-mismatch
        :class:`RuntimeError`.
    image_size: Optional fixed input height and width of the graph that
        :meth:`SuperResolution.to_onnx` exports; ``None`` leaves them dynamic. It does not
        change the pre-processor, which always resizes to 224, so the output side stays
        ``224 * upscale_factor``.

Returns:
    A :class:`SuperResolution` instance configured with resizing pre-processing
    and identity post-processing, the network's output being in :math:`[0, 1]` already.

Raises:
    ValueError: If ``model_name`` is not supported.
r   )r"   rO   z* not found. Please choose from 'small_sr'.r°   )rP   r   rS   r   r   Ú_SMALL_SR_INPUT_SIZEr   rŽ   rG   rH   rF   )r!   r"   r#   r$   r;   Úsrs   &&&&  r*   rQ   ÚSmallSRBuilder.build¦  s�   € ð6 ×ÑÓ Ô+Ü% nÔL‰Eä˜v j \Ð1[Ð\Ó]Ð]äØÜ,Ô-AÔCWÓXÜŸ;š;›=Øô	
ˆô  4°nÕDˆÔØÒÜ#7ˆBÔ ð ˆ	ð #-ÔØ#-Ô Øˆ	r-   r.   )r   Té   Nrµ   r7   s   @r*   r   r   ™  s#   ø‡ € ñ
ð ÷-ñ -ó ö-r-   )r   r   r   r   )&r3   Údataclassesr   Útypingr   r   r   r   r   rX   r   Úkornia.core.downloadr	   Úkornia.core.externalr
   ÚImager   Úkornia.core.mixin.onnxr   r   r   r   Úkornia.models.baser   Úkornia.models.processorsr   r   Úkornia.models.rrdbnetr   Úkornia.models.small_srr   Ú__all__rº   rR   r   r   r   r   r.   r-   r*   Ú<module>rÉ      s¬   ðñ$õ "ß 4Õ 4ã Ý å 9Ý 2Ý %ß rÓ rÝ (ß QÝ )Ý 4â
Z€ð Ð ð ÐpØÐpØ ð  #EØÐpð		€ð ÷%ð %ó ð%ô<
�iÐ 5Õ6¸ô 
÷D8
ñ 8
÷v;ó ;r-   