+
    åûj|&  ã            	      óD  € ^ RI Ht ^ RIt^ RIt^ RIt^ RIHtHt ^ RIH	t	H
t
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 ^ R
IHt ]P<                  ! ]4      t ]! R4      t!R R lt" ! R R4      t# ! R R]]PH                  ]#]
]!,          4      t%R# )é    )ÚannotationsN)ÚABCÚabstractmethod)ÚAnyÚGenericÚListÚOptionalÚTypeVarÚUnionÚcast)Únn)Ú_emit_deprecation_warning)Úload_state_dict_from_url)ÚPILImage)ÚImageModuleMixInÚ_to_uint8_image)Úwrite_imageÚModelConfigc               ó$   € V ^8„  d   QhRRRRRR/# )é   Ú	path_stemÚstrÚimagez Union[torch.Tensor, Image.Image]ÚreturnÚNone© )Úformats   "ÚNC:\Ai_Coding\apps\studio\ComfyUI\.venv\Lib\site-packages\kornia\models\base.pyÚ__annotate__r   (   s#   € ÷ /ñ / ð /Ð,Lð /ÐQUñ /ó    c                ó   € \        V\        P                  4      '       g   VP                  V  R24       R# \	        V4      pVP                  4       ^8X  d)   \        V4       F  w  r#\        V  RV R2V4       K  	  R# \        V  R2V4       R# )aá  Write one image, or one file per item of a batch.

``visualize`` returns float images in ``[0, 1]``, but ``write_image`` writes
PNG only for ``uint8``/``uint16``; float32 is TIFF-only and every other
float dtype is rejected outright. These are pictures for a human to look at,
not data to round-trip, so a float image is converted to ``uint8`` the way
``ImageModule`` hands a tensor to PIL: clamped, scaled and rounded. A
``uint8`` or ``uint16`` visualization is written as-is.

``write_image`` takes one image, ``(3, H, W)``, ``(1, H, W)``, ``(H, W)`` or,
for PNG only, ``(4, H, W)``, and rejects a batched tensor; the containers
document their inputs as ``(B, 3, H, W)``, so a batch is written as one file
per item.

A batch of one still gets an index suffix, so a caller does not have to
guess whether a file will be ``name.png`` or ``name_0.png``.

A PIL image, what ``visualize(output_type="pil")`` returns, was made 8-bit by
the same conversion and is written as it is, to ``name.png``.
z.pngNÚ_)Ú
isinstanceÚtorchÚTensorÚsaver   ÚdimÚ	enumerater   )r   r   ÚiÚitems   &&  r   Ú_write_png_batchr+   (   s~   € ô* �eœUŸ\™\×*Ò*Ø�
‰
�i�[ Ð%Ô&ÙÜ˜EÓ"€EØ‡y�yƒ{�aÔÜ  Ö'‰GˆAÜ˜9˜+ Q q c¨Ð.°Ö5ó (ô 	�y�k Ð&¨Ö.r    c                  ól   € ] tR t^Ht$ RtRtR]R&   R R lt]R R l4       t	RR
 R llt
RR R lltRtR	# )ÚModelBaseMixinzAProvide common properties and utilities for Kornia model classes.Úmodelr   Únamec               ó$   € V ^8„  d   QhRRRRRR/# )r   Úoutputz'Union[torch.Tensor, List[torch.Tensor]]Úoutput_typer   r   ú:Union[torch.Tensor, List[torch.Tensor], List[Image.Image]]r   )r   s   "r   r   ÚModelBaseMixin.__annotate__M   s$   € ÷ ñ Ø=ðØLOðà	Cñr    c           
     ó0  € V P                  V4       VR8X  d~   . p\        V\        4      '       d   TMV. FZ  pVP                  4       ^8X  d
   VR,          MTpVP	                  R VP
                  ! R.VP                  RR O5!   4       4       K\  	  V# V# )aÆ  Convert the output tensor to the desired type.

Args:
    output: The output tensor or list of tensors.
    output_type: The desired output type. Accepted values are "torch" and "pil".

Returns:
    The output unchanged for "torch". For "pil", a list of PIL images, one per ``(C, H, W)`` or
    ``(H, W)`` image: a ``(B, C, H, W)`` tensor gives B images, and a list gives the images of each
    element in turn. They are converted as :meth:`~kornia.core.mixin.image_module.ImageModuleMixIn.to_pil`
    does: a floating image is clamped to ``[0, 1]`` and rounded to 8 bits, and a one-channel or
    ``(H, W)`` image becomes a mode ``"L"`` image.

Raises:
    RuntimeError: If the output type is not supported.

ÚpilNc              3  óN   "  € T F  p\         P                  ! V4      x € K  	  R # 5i©N)r   Ú_chw_to_pil)Ú.0Úchws   & r   Ú	<genexpr>Ú1ModelBaseMixin._tensor_to_type.<locals>.<genexpr>g   s!   é € ÐhÑKgÀCÔ.×:Ò:¸3×?Ð?ÓKgùs   ‚#%éÿÿÿÿéýÿÿÿ)Ú_check_output_typer#   Úlistr'   ÚextendÚreshapeÚshape)Úselfr1   r2   ÚimagesÚts   &&&  r   Ú_tensor_to_typeÚModelBaseMixin._tensor_to_typeM   s‘   € ð( 	×Ñ Ô,Ø˜%ÔØˆFÜ)¨&´$×7Ò7‘V¸f¸XÒE�à Ÿu™u›w¨!œ|�A�d–G°�Ø—‘ÑhÈ1Ï9Ê9ÐUWÐKgÐZ[×ZaÑZaÐbdÐbeÐZfÔKgÓhÖhñ Fð ˆMØˆr    c               ó    € V ^8„  d   QhRRRR/# )r   r2   r   r   r   r   )r   s   "r   r   r4   l   s   € ÷ vñ v¨ð v°ñ vr    c                ó2   € V R9  d   \        RV  R24      hR# )zBRaise ``RuntimeError`` unless ``output_type`` is "torch" or "pil".zOutput type z9 is not supported. Accepted values are 'torch' and 'pil'.N)r$   r6   )ÚRuntimeError)r2   s   &r   r@   Ú!ModelBaseMixin._check_output_typek   s'   € ð Ð.Ô.Ü ¨k¨]Ð:sÐtÓuÐuñ /r    Nc               ó(   € V ^8„  d   QhRRRRRRRR/# )	r   r1   r3   Ú	directoryr   Úis_batchzOptional[bool]r   r   r   )r   s   "r   r   r4   q   s2   € ÷ 9ñ 9àJð9ð ð9ð !ð	9ð
 
ñ9r    c                ó@  € Ve   \        RRRR4       \        P                  ! VRR7       \        P                  P	                  \        P
                  R7      P                  R4      p\        V\        4      '       dQ   \        V4       F@  w  rV\        \        P                  P                  W P                   R	V R	V 24      V4       KB  	  M8\        \        P                  P                  W P                   R	V 24      V4       \        P                  R
V 24       R# )a–  Save the output tensor to a directory.

Args:
    output: The output tensor, or a list of tensors or PIL images.
    directory: The directory to save the output.
    is_batch: deprecated since kornia 0.9.1 and ignored; passing ``True`` or ``False`` emits a
      :class:`DeprecationWarning`, and the default ``None`` does not. A 4D tensor is always written as one
      file per item, whatever its value.

Nzsave(is_batch=...)z0.9.1zkThe argument has no effect: the files written depend only on `output`, whatever its value; stop passing it.T©Úexist_ok©Útzú%Y%m%d_%H%M%Sr"   úOutputs are saved in )r   ÚosÚmakedirsÚdatetimeÚnowÚUTCÚstrftimer#   rA   r(   r+   ÚpathÚjoinr/   ÚloggerÚinfo)rE   r1   rO   rP   Ú	timestampr)   Úouts   &&&&   r   r&   ÚModelBaseMixin.saveq   sã   € ð  ÒÜ%Ø$ØØðô	ô 	�Š�I¨Õ-Ü×%Ñ%×)Ñ)¬X¯\©\Ð)Ó:×CÑCÀOÓTˆ	Ü�fœd×#Ò#Ü# FÖ+‘�Ü ¤§¡§¡¨i¿I¹I¸;ÀaÈ	À{ÐRSÐTUÐSVÐ9WÓ!XÐZ]Ö^ò ,ô œRŸW™WŸ\™\¨)¿	¹	°{À!ÀIÀ;Ð5OÓPÐRXÔYÜ�‰Ð+¨I¨;Ð7Ö8r    c               ó(   € V ^8„  d   QhRRRRRRRR/# )	r   r1   r3   rO   úOptional[str]Úsuffixr   r   r   r   )r   s   "r   r   r4   ’   s2   € ÷ 9ñ 9àJð9ð !ð9ð ð	9ð
 
ñ9r    c                ó
  € Vfp   V P                    V R\        P                  P                  \        P                  R7      P	                  R4      : 2p\
        P                  P                  RV4      p\
        P                  ! VRR7       \        P                  P                  \        P                  R7      P	                  R4      p\        V\        4      '       dS   \        V4       FB  w  rg\        \
        P                  P                  W P                    V RV RV 24      V4       KD  	  M:\        \
        P                  P                  W P                    V RV 24      V4       \        P                  R	V 24       R# )
a  Save the output tensor to a directory with an optional suffix.

Args:
    output: The output tensor, or a list of tensors or PIL images.
    directory: The directory to save the output. If None, a default directory is used.
    suffix: Optional suffix to add to the filename.

Nr"   rT   z%Y%m%d%H%M%SÚkornia_outputsTrR   rV   rW   )r/   rZ   r[   r\   r]   rX   r^   r_   rY   r#   rA   r(   r+   r`   ra   )rE   r1   rO   rg   r/   rb   r)   rc   s   &&&&    r   Ú_save_outputsÚModelBaseMixin._save_outputs’   s&  € ð ÒØ—i‘i�[  ¨¬(×*;Ñ*;×*?Ñ*?Ä8Ç<Á<Ð*?Ó*P×*YÑ*YÐZhÓ*iÑ)lÐmˆDÜŸ™Ÿ™Ð%5°tÓ<ˆIä
�Š�I¨Õ-Ü×%Ñ%×)Ñ)¬X¯\©\Ð)Ó:×CÑCÀOÓTˆ	Ü�fœd×#Ò#Ü# FÖ+‘�Ü ¤§¡§¡¨i¿I¹I¸;ÀvÀhÈaÐPYÈ{ÐZ[Ð\]Ð[^Ð9_Ó!`ÐbeÖfò ,ô œRŸW™WŸ\™\¨)¿	¹	°{À6À(È!ÈIÈ;Ð5WÓXÐZ`ÔaÜ�‰Ð+¨I¨;Ð7Ö8r    r   r8   )NÚ )Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r/   Ú__annotations__rH   Ústaticmethodr@   r&   rj   Ú__static_attributes__r   r    r   r-   r-   H   s:   ‡ ÙKà€Dˆ#Óõð< ôvó ðv÷
9÷B9ó 9r    r-   c                  ór   € ] tR t^®tRtRR R llt]]R R l4       4       tRRR	RR
RRRRRRR/R R llt	Rt
R# )Ú	ModelBasez2Abstract model class with some utilities function.Nc               ó$   € V ^8„  d   QhRRRRRR/# )r   Ú
checkpointzstr | list[str]ÚdevicezOptional[torch.device]r   r   r   )r   s   "r   r   ÚModelBase.__annotate__±   s#   € ÷ ñ ¨/ð ÐCYð Ðeiñ r    c                óÀ  € \        V\        4      '       d    \        P                  P	                  V4      MRpVe\   \        P                  P                  V4      '       d7   \        VR4      ;_uu_ 4       p\        P                  ! WBRR7      pRRR4       M\        WR7      pV P                  X4       Ve   V P                  V4       R# R#   + '       g   i     L:; i)as  Load checkpoint from a given url or file.

Either way the file is loaded with ``weights_only=True``, so it may hold
tensors, primitive types and plain containers only; see
:func:`kornia.core.download.load_state_dict_from_url`.

Args:
    checkpoint: The url or filepath for the respective checkpoint
    device: The desired device to load the weights and move the model

NÚrbT)Úmap_locationÚweights_only)r}   )r#   r   rX   r^   Ú
expanduserÚisfileÚopenr$   Úloadr   Úload_state_dictÚto)rE   rx   ry   ÚlocalÚfÚ
state_dicts   &&&   r   Úload_checkpointÚModelBase.load_checkpoint±   sŸ   € ô 3=¸ZÌ×2MÒ2M”—‘×"Ñ" :Ô.ÐSWˆØÒ¤§¡§¡°×!6Ò!6Ü�e˜T×"Ô" aÜ"ŸZšZ¨ÈTÔR�
÷ #Ð"ô 2°*ÔRˆJà×Ñ˜ZÔ(ØÒØ�G‰G�FŽOñ ÷ #×"ús   Á5CÃC	c               ó    € V ^8„  d   QhRRRR/# )r   Úconfigr   r   úModelBase[ModelConfig]r   )r   s   "r   r   rz   Ê   s   € ÷ "ñ "˜Kð "Ð,Bñ "r    c                ó   € \         h)z[Build/load the model.

Args:
    config: The specifications for the model be build/loaded

)ÚNotImplementedError)r‹   s   &r   Úfrom_configÚModelBase.from_configÈ   s
   € ô "Ð!r    Ú	fullgraphFÚdynamicÚbackendÚinductorÚmodeÚoptionsÚdisablec               ó4   € V ^8„  d   QhRRRRRRRRRR	R
RRR/# )r   r‘   Úboolr’   r“   r   r•   rf   r–   zOptional[dict[Any, Any]]r—   r   rŒ   r   )r   s   "r   r   rz   Ó   sR   € ÷ 6ñ 6ð ð6ð ð	6ð
 ð6ð ð6ð *ð6ð ð6ð 
 ñ6r    c          
     ól   € \         P                  ! WW#WEVR7      p\        \        \        ,          V4      # )a2  Compile this model with :func:`torch.compile`.

Args:
    fullgraph: Whether Dynamo should require a single full graph.
    dynamic: Whether dynamic shape tracing is enabled.
    backend: Compilation backend name passed to :func:`torch.compile`.
    mode: Optional backend-specific compilation mode.
    options: Optional backend-specific option dictionary.
    disable: If ``True``, return an uncompiled model wrapper according
        to PyTorch's compile semantics.

Returns:
    Compiled model object with the same high-level interface as this
    instance.
)r‘   r’   r“   r•   r–   r—   )r$   Úcompiler   rv   r   )rE   r‘   r’   r“   r•   r–   r—   Úcompileds   &$$$$$$ r   r›   ÚModelBase.compileÓ   s0   € ô2 —=’=Ø¨wÈdÐmtô
ˆô ”IœkÕ*¨HÓ5Ð5r    r   r8   )rm   rn   ro   rp   rq   rˆ   rs   r   r�   r›   rt   r   r    r   rv   rv   ®   sl   † Ù<÷ð. Øô"ó ó ð"ð6ð  ð6ð ð	6ð
 "ð6ð #ð6ð -1ð6ð ÷6ó 6r    rv   )&Ú
__future__r   rZ   ÚloggingrX   Úabcr   r   Útypingr   r   r   r	   r
   r   r   r$   r   Úkornia.core._compatr   Úkornia.core.downloadr   Úkornia.core.externalr   ÚImageÚkornia.core.mixin.image_moduler   r   Ú	kornia.ior   Ú	getLoggerrm   r`   r   r+   r-   ÚModulerv   r   r    r   Ú<module>rª      s~   ðõ$ #ã Û Û 	ß #ß E× EÑ Eã Ý å 9Ý 9Ý 2ß LÝ !à	×	Ò	˜8Ó	$€á�mÓ$€õ/÷@c9ñ c9ôLA6��R—Y‘Y °¸Õ0Dö A6r    