+
    œ°³jËg  ã                   óT  € R t ^ RIt^ RIt^ RIHt ^ RI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 ^R	IHt ^R
IHtHtHt ^RIHtHt ^RIHt ^RIHtHtH t  ^RI!H"t"H#t#H$t$H%t%H&t&H't'H(t(H)t)H*t*H+t+H,t, ]! RR7      ]	 ! R R]4      4       4       t-]! RR7      ]	 ! R R] 4      4       4       t.]! RR7      ]	 ! R R]4      4       4       t/ ! R R]'4      t0]] ! R R]4      4       4       t1]] ! R R]4      4       4       t2 ! R R]+4      t3 ! R R ])4      t4 ! R! R"]#4      t5 ! R# R$]"4      t6 ! R% R&]%4      t7 ! R' R(]%4      t8] ! R) R*](4      4       t9 ! R+ R,]$4      t: ! R- R.]94      t; ! R/ R0]*4      t< ! R1 R2],4      t= ! R3 R4]&4      t>]! R5R67       ! R7 R8]94      4       t?. R9Ot@R# ):zPyTorch CLIPSeg model.N)Ú	dataclass)ÚAny)Ústrict)Únn)Úinitialization)ÚBaseModelOutputWithPooling)ÚPreTrainedModel)ÚUnpack)ÚModelOutputÚTransformersKwargsÚauto_docstring)Úcan_return_tupleÚmerge_with_config_defaults)Úcapture_outputs)Ú
CLIPConfigÚCLIPTextConfigÚCLIPVisionConfig)ÚCLIPMLPÚCLIPAttentionÚCLIPEncoderÚCLIPEncoderLayerÚ	CLIPModelÚ
CLIPOutputÚCLIPPreTrainedModelÚCLIPTextEmbeddingsÚCLIPTextModelÚCLIPVisionEmbeddingsÚCLIPVisionModelzCIDAS/clipseg-rd64)Ú
checkpointc                   ó(   € ] tR t^0tRt]! 4       tRtR# )ÚCLIPSegTextConfiga¸  
Example:

```python
>>> from transformers import CLIPSegTextConfig, CLIPSegTextModel

>>> # Initializing a CLIPSegTextConfig with CIDAS/clipseg-rd64 style configuration
>>> configuration = CLIPSegTextConfig()

>>> # Initializing a CLIPSegTextModel (with random weights) from the CIDAS/clipseg-rd64 style configuration
>>> model = CLIPSegTextModel(configuration)

>>> # Accessing the model configuration
>>> configuration = model.config
```© N©Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__ÚAttributeErrorÚprojection_dimÚ__static_attributes__r!   ó    Úl/home/luca/screen-checking/.venv/lib/python3.14/site-packages/transformers/models/clipseg/modular_clipseg.pyr    r    0   ó   † ññ  $Ó%„Nr+   r    c                   ó(   € ] tR t^FtRt]! 4       tRtR# )ÚCLIPSegVisionConfigaÄ  
Example:

```python
>>> from transformers import CLIPSegVisionConfig, CLIPSegVisionModel

>>> # Initializing a CLIPSegVisionConfig with CIDAS/clipseg-rd64 style configuration
>>> configuration = CLIPSegVisionConfig()

>>> # Initializing a CLIPSegVisionModel (with random weights) from the CIDAS/clipseg-rd64 style configuration
>>> model = CLIPSegVisionModel(configuration)

>>> # Accessing the model configuration
>>> configuration = model.config
```r!   Nr"   r!   r+   r,   r/   r/   F   r-   r+   r/   c                   óP   a € ] tR t^\t o RtR	t^@t^tRtRt	Rt
^ tRtV 3R ltRtV tR# )
ÚCLIPSegConfiga®  
extract_layers (`list[int]`, *optional*, defaults to `[3, 6, 9]`):
    Layers to extract when forwarding the query image through the frozen visual backbone of CLIP.
reduce_dim (`int`, *optional*, defaults to 64):
    Dimensionality to reduce the CLIP vision embedding.
conditional_layer (`int`, *optional*, defaults to 0):
    The layer to use of the Transformer encoder whose activations will be combined with the condition
    embeddings using FiLM (Feature-wise Linear Modulation). If 0, the last layer is used.
use_complex_transposed_convolution (`bool`, *optional*, defaults to `False`):
    Whether to use a more complex transposed convolution in the decoder, enabling more fine-grained
    segmentation..

Example:

```python
>>> from transformers import CLIPSegConfig, CLIPSegModel

>>> # Initializing a CLIPSegConfig with CIDAS/clipseg-rd64 style configuration
>>> configuration = CLIPSegConfig()

>>> # Initializing a CLIPSegModel (with random weights) from the CIDAS/clipseg-rd64 style configuration
>>> model = CLIPSegModel(configuration)

>>> # Accessing the model configuration
>>> configuration = model.config

>>> # We can also initialize a CLIPSegConfig from a CLIPSegTextConfig and a CLIPSegVisionConfig

>>> # Initializing a CLIPSegText and CLIPSegVision configuration
>>> config_text = CLIPSegTextConfig()
>>> config_vision = CLIPSegVisionConfig()

>>> config = CLIPSegConfig(text_config=config_text, vision_config=config_vision)
```ç        Ú
quick_gelui   Fc                ó¾   <€ V ^8„  d   Qh/ S[ S[,          S[S[R3,          ,          ;R&   S[;R&   S[;R&   S[S[,          ;R&   S[;R&   S[;R&   S[;R&   S[;R	&   # )
é   .Úextract_layersÚ
reduce_dimÚdecoder_num_attention_headsÚdecoder_attention_dropoutÚdecoder_hidden_actÚdecoder_intermediate_sizeÚconditional_layerÚ"use_complex_transposed_convolution)ÚlistÚintÚtupleÚfloatÚstrÚbool)ÚformatÚ__classdict__s   "€r,   Ú__annotate__ÚCLIPSegConfig.__annotate__\   s’   ø‡ ‚ ñL ™•I¡¡c¨3 h¥Õ/Ñ;ñM ñN ÑñO ñP "%Ñ(ñQ ñR  %¡s�{Ñ0ñS ñT Ñ*ñU ñV  #Ñ)ñW ñX ÑñY ñZ )-Ñ4ò[ r+   r!   N)é   é   é	   )r#   r$   r%   r&   r'   r6   r7   r8   r9   r:   r;   r<   r=   Ú__annotate_func__r*   Ú__classdictcell__©rE   s   @r,   r1   r1   \   sC   ø‡ € ñ!ðF 3<€NØ€JØ'(ÐØ-0ÐØ*ÐØ%)ÐØÐØ/4Ð&÷[ ƒ r+   r1   c                   ó   € ] tR t^ŒtRtR# )ÚCLIPSegOutputr!   N©r#   r$   r%   r&   r*   r!   r+   r,   rO   rO   Œ   ó   † Ûr+   rO   c                   ó<   a € ] tR t^�t o RtRtRtRtV 3R ltRt	V t
R# )ÚCLIPSegDecoderOutputa}  
logits (`torch.FloatTensor` of shape `(batch_size, height, width)`):
    Classification scores for each pixel.
hidden_states (`tuple(torch.FloatTensor)`, *optional*,):
    Hidden-states of the model at the output of each layer plus the optional initial embedding outputs.

    Returned when `output_hidden_states=True` is passed or when `config.output_hidden_states=True`
attentions (`tuple(torch.FloatTensor)`, *optional*):
    Attentions weights after the attention softmax, used to compute the weighted average in the self-attention
    heads. Returned when `output_attentions=True` is passed or when `config.output_attentions=True`
Nc                óÌ   <€ V ^8„  d   Qh/ S[ P                  R,          ;R&   S[S[ P                  R3,          R,          ;R&   S[S[ P                  R3,          R,          ;R&   # )r5   NÚlogits.Úhidden_statesÚ
attentions)ÚtorchÚFloatTensorr@   )rD   rE   s   "€r,   rF   Ú!CLIPSegDecoderOutput.__annotate__�   sa   ø‡ ‚ ñ ×Ñ Õ$Ñ+ñ ñ  ™×*Ñ*¨CÐ/Õ0°4Õ7Ñ>ñ! ñ" ‘e×'Ñ'¨Ð,Õ-°Õ4Ñ;ò# r+   r!   )r#   r$   r%   r&   r'   rU   rV   rW   rK   r*   rL   rM   s   @r,   rS   rS   �   s"   ø‡ € ñ
ð (,€FØ:>€MØ7;€J÷# ƒ r+   rS   c                   óZ   a € ] tR t^¤t o RtRtRtRtRtRt	Rt
V 3R lR ltV 3R ltRtV tR# )ÚCLIPSegImageSegmentationOutputa²  
loss (`torch.FloatTensor` of shape `(1,)`, *optional*, returned when `labels` is provided):
    Binary cross entropy loss for segmentation.
logits (`torch.FloatTensor` of shape `(batch_size, height, width)`):
    Classification scores for each pixel.
conditional_embeddings (`torch.FloatTensor` of shape `(batch_size, projection_dim)`):
    Conditional embeddings used for segmentation.
pooled_output (`torch.FloatTensor` of shape `(batch_size, embed_dim)`):
    Pooled output of the [`CLIPSegVisionModel`].
vision_model_output (`BaseModelOutputWithPooling`):
    The output of the [`CLIPSegVisionModel`].
decoder_output (`CLIPSegDecoderOutput`):
    The output of the [`CLIPSegDecoder`].
Nc                ó0   <€ V ^8„  d   QhRS[ S[,          /# ©r5   Úreturn)r@   r   )rD   rE   s   "€r,   rF   Ú+CLIPSegImageSegmentationOutput.__annotate__½   s   ø€ ÷ _ñ _™%¡�*ñ _r+   c                ó’   € \         ;QJ d"    . R  V P                  4        4       F  NK  	  5# ! R  V P                  4        4       4      # )c              3   ór   "  € T F-  p\        V\        4      '       d   VP                  4       MTx € K/  	  R # 5i©N)Ú
isinstancer
   Úto_tuple)Ú.0Úvs   & r,   Ú	<genexpr>Ú:CLIPSegImageSegmentationOutput.to_tuple.<locals>.<genexpr>¾   s)   é € Ð^ÑP]È1¤Z°´;×%?Ò%?�Q—Z‘Z”\ÀQÔFÓP]ùs   ‚57)r@   Úvalues)Úselfs   &r,   re   Ú'CLIPSegImageSegmentationOutput.to_tuple½   s8   € ßŒuÑ^ÐPT×P[ÑP[ÔP]Ó^�uÐ^ˆuÑ^ÐPT×P[ÑP[ÔP]Ó^Ó^Ð^r+   c                óê   <€ V ^8„  d   Qh/ S[ P                  R,          ;R&   S[ P                  R,          ;R&   S[ P                  R,          ;R&   S[ P                  R,          ;R&   S[;R&   S[;R&   # )r5   NÚlossrU   Úconditional_embeddingsÚpooled_outputÚvision_model_outputÚdecoder_output)rX   rY   r   rS   )rD   rE   s   "€r,   rF   r`   ¤   s   ø‡ ‚ ñ$ ×
Ñ
˜dÕ
"Ñ)ñ% ñ& ×Ñ Õ$Ñ+ñ' ñ( "×-Ñ-°Õ4Ñ;ñ) ñ* ×$Ñ$ tÕ+Ñ2ñ+ ñ, 4Ñ:ñ- ñ. )Ñ/ò/ r+   r!   )r#   r$   r%   r&   r'   rn   rU   ro   rp   rq   rr   re   rK   r*   rL   rM   s   @r,   r\   r\   ¤   s?   ø‡ € ñð &*€DØ'+€FØ7;ÐØ.2€MØ6:ÐØ+/€N÷_ð _÷3 ƒ r+   r\   c                   óB   a a€ ] tR t^Át oRV3R lV 3R llltRtVtV ;t# )ÚCLIPSegVisionEmbeddingsc                óN   <€ V ^8„  d   QhRS[ P                  RS[ P                  /# )r5   Úpixel_valuesr_   )rX   rY   ÚTensor)rD   rE   s   "€r,   rF   Ú$CLIPSegVisionEmbeddings.__annotate__Ã   s,   ø€ ÷ @ñ @¡E×$5Ñ$5ð @ÑY^×YeÑYeñ @r+   c                ó&   <€ \         SV `  W4       R # rc   ©ÚsuperÚforward)rk   rv   Úinterpolate_pos_encodingÚ	__class__s   &&&€r,   r|   ÚCLIPSegVisionEmbeddings.forwardÃ   s   ø€ Ü‰‰˜Ö?r+   r!   ©T©r#   r$   r%   r&   r|   r*   rL   Ú__classcell__©r~   rE   s   @@r,   rt   rt   Á   s   ù‡ € ÷@÷ @õ @r+   rt   c                   ó   € ] tR t^ÇtRtR# )ÚCLIPSegTextEmbeddingsr!   NrP   r!   r+   r,   r…   r…   Ç   rQ   r+   r…   c                   ó   € ] tR t^ËtRtR# )ÚCLIPSegAttentionr!   NrP   r!   r+   r,   r‡   r‡   Ë   rQ   r+   r‡   c                   ó   € ] tR t^ÏtRtR# )Ú
CLIPSegMLPr!   NrP   r!   r+   r,   r‰   r‰   Ï   rQ   r+   r‰   c                   ó   € ] tR t^ÓtRtR# )ÚCLIPSegEncoderLayerr!   NrP   r!   r+   r,   r‹   r‹   Ó   rQ   r+   r‹   c                   ó6   a € ] tR t^×t o RtV 3R lR ltRtV tR# )ÚCLIPSegDecoderLayerz˜
CLIPSeg decoder layer, which is identical to `CLIPSegEncoderLayer`, except that normalization is applied after
self-attention/MLP, rather than before.
c                óx   <€ V ^8„  d   QhRS[ P                  RS[ P                  RS[S[ P                  ,          /# )r5   rV   Úattention_maskr_   )rX   rw   r@   rY   )rD   rE   s   "€r,   rF   Ú CLIPSegDecoderLayer.__annotate__Ý   s<   ø€ ÷ ñ á—|‘|ðñ Ÿ™ðñ
 
‰u× Ñ Õ	!ñr+   c                óÄ   € TpV P                   ! RR VRV/VB w  rWA,           pV P                  V4      pTpV P                  V4      pWA,           pV P                  V4      pV# )rV   r�   r!   )Ú	self_attnÚlayer_norm1ÚmlpÚlayer_norm2)rk   rV   r�   ÚkwargsÚresidualÚ_s   &&&,  r,   r|   ÚCLIPSegDecoderLayer.forwardÝ   s   € ð !ˆàŸ>š>ñ 
Ø'ð
à)ð
ð ñ
Ñˆð !Õ0ˆØ×(Ñ(¨Ó7ˆà ˆØŸ™ Ó/ˆØ Õ0ˆØ×(Ñ(¨Ó7ˆàÐr+   r!   N)r#   r$   r%   r&   r'   r|   r*   rL   rM   s   @r,   r�   r�   ×   s   ø‡ € ñ÷
ö r+   r�   c                   ó^   a € ] tR t^öt o R]].R]/t]P                  ! 4       R 4       t
RtV tR# )ÚCLIPSegPreTrainedModelrV   rW   c                óØ	  € \         P                  ! W4       V P                  P                  p\	        V\
        4      '       dÊ   \        P                  ! VP                  P                  RVR,          R7       \        P                  ! VP                  P                  RVR,          R7       \        P                  ! VP                  \        P                  ! VP                  P                  R,          4      P!                  R4      4       R# \	        V\"        4      '       Ed   \        P                  ! VP$                  RVP&                  R,          V,          R7       \        P                  ! VP(                  P                  VP                  P*                  V,          R7       \        P                  ! VP                  P                  VP                  P*                  V,          R7       \        P                  ! VP                  \        P                  ! VP,                  4      P!                  R4      4       R# \	        V\.        4      '       Ed   VP&                  R,          ^VP                  P0                  ,          R,          ,          V,          pVP&                  R,          V,          p\        P                  ! VP2                  P                  VR7       \        P                  ! VP4                  P                  VR7       \        P                  ! VP6                  P                  VR7       \        P                  ! VP8                  P                  VR7       R# \	        V\:        4      '       dÓ   VP                  P<                  R,          ^VP                  P0                  ,          R,          ,          V,          p^VP                  P<                  ,          R,          V,          p\        P                  ! VP>                  P                  VR7       \        P                  ! VP@                  P                  VR7       R# \	        V\B        4      '       d‹   \        P                  ! VPD                  P                  VPF                  R,          V,          R7       \        P                  ! VPH                  P                  VPJ                  R,          V,          R7       R# R# )	zInitialize the weightsr2   g{®Gáz”?)ÚmeanÚstd)rž   Néÿÿÿÿ)é   rŸ   g      à¿)&r   Ú_init_weightsÚconfigÚinitializer_factorrd   r…   ÚinitÚnormal_Útoken_embeddingÚweightÚposition_embeddingÚcopy_Úposition_idsrX   ÚarangeÚshapeÚexpandrt   Úclass_embeddingÚ	embed_dimÚpatch_embeddingÚinitializer_rangeÚnum_positionsr‡   Únum_hidden_layersÚq_projÚk_projÚv_projÚout_projr‰   Úhidden_sizeÚfc1Úfc2ÚCLIPSegModelÚtext_projectionÚtext_embed_dimÚvisual_projectionÚvision_embed_dim)rk   ÚmoduleÚfactorÚin_proj_stdÚout_proj_stdÚfc_stds   &&    r,   r¡   Ú$CLIPSegPreTrainedModel._init_weightsý   s  € ô 	×%Ò% dÔ3Ø—‘×/Ñ/ˆÜ�fÔ3×4Ò4Ü�LŠL˜×/Ñ/×6Ñ6¸SÀfÈtÅmÕTÜ�LŠL˜×2Ñ2×9Ñ9ÀÈÐRVÍÕWÜ�JŠJ�v×*Ñ*¬E¯LªL¸×9LÑ9L×9RÑ9RÐSUÕ9VÓ,W×,^Ñ,^Ð_fÓ,gÖhÜ˜Ô 7×8Ó8Ü�LŠL˜×/Ñ/°c¸v×?OÑ?OÐQUÕ?UÐX^Õ?^Õ_Ü�LŠL˜×/Ñ/×6Ñ6¸F¿M¹M×<[Ñ<[Ð^dÕ<dÕeÜ�LŠL˜×2Ñ2×9Ñ9¸v¿}¹}×?^Ñ?^ÐagÕ?gÕhÜ�JŠJ�v×*Ñ*¬E¯LªL¸×9MÑ9MÓ,N×,UÑ,UÐV]Ó,^Ö_Ü˜Ô 0×1Ó1Ø!×+Ñ+¨TÕ1°q¸6¿=¹=×;ZÑ;ZÕ7ZÐ_cÕ6cÕdÐgmÕmˆKØ"×,Ñ,¨dÕ2°fÕ<ˆLÜ�LŠL˜Ÿ™×-Ñ-°;Õ?Ü�LŠL˜Ÿ™×-Ñ-°;Õ?Ü�LŠL˜Ÿ™×-Ñ-°;Õ?Ü�LŠL˜Ÿ™×/Ñ/°\×BÜ˜¤
×+Ò+Ø!Ÿ=™=×4Ñ4°dÕ:ÀÀFÇMÁM×DcÑDcÕ@cÐhlÕ?lÕmÐpvÕvˆKØ˜&Ÿ-™-×3Ñ3Õ3¸Õ<¸vÕEˆFÜ�LŠL˜Ÿ™×*Ñ*°Õ7Ü�LŠL˜Ÿ™×*Ñ*°×<Ü˜¤×-Ò-Ü�LŠLØ×&Ñ&×-Ñ-Ø×)Ñ)¨4Õ/°&Õ8õô �LŠLØ×(Ñ(×/Ñ/Ø×+Ñ+¨TÕ1°FÕ:÷ñ .r+   r!   N)r#   r$   r%   r&   r‹   r�   r‡   Ú_can_record_outputsrX   Úno_gradr¡   r*   rL   rM   s   @r,   r›   r›   ö   s;   ø‡ € ð 	Ð-Ð/BÐCØÐ&ðÐð
 ‡]‚]ƒ_ñ!ó ö!r+   r›   c                   ó   € ] tR tRtRtR# )ÚCLIPSegEncoderi"  r!   NrP   r!   r+   r,   rÉ   rÉ   "  rQ   r+   rÉ   c                   ón   a a€ ] tR tRt oV3R lV 3R llt]]]V3R lR l4       4       4       tRt	Vt
V ;t# )ÚCLIPSegDecoderi&  c                ó    <€ V ^8„  d   QhRS[ /# ©r5   r¢   ©r1   )rD   rE   s   "€r,   rF   ÚCLIPSegDecoder.__annotate__'  s   ø€ ÷ *ñ *™}ñ *r+   c                ó˜  <€ \         SV `  V4       VP                  V n        \        P                  ! VP
                  VP                  4      V n        \        P                  ! VP
                  VP                  4      V n        VP                  '       Ed%   VP                  P                  ^,          VP                  P                  ^,          3p\        P                  ! \        P                  ! VP                  VP                  ^^R7      \        P                  ! 4       \        P                  ! VP                  VP                  ^,          V^ ,          V^ ,          R7      \        P                  ! 4       \        P                  ! VP                  ^,          ^V^,          V^,          R7      4      V n        MQ\        P                  ! VP                  ^VP                  P                  VP                  P                  R7      V n        \#        VP$                  4      p\        P&                  ! \)        V4       Uu. uF8  p\        P                  ! VP                  P*                  VP                  4      NK:  	  up4      V n        \.        P0                  ! VP                  4      pVP                  Vn        VP2                  Vn        VP6                  Vn        RVn        \        P&                  ! \)        \#        VP$                  4      4       Uu. uF  p\=        V4      NK  	  up4      V n        V PA                  4        R# u upi u upi )é   )Úkernel_sizeÚpadding)rÒ   Ústride)rÔ   ÚreluN)!r{   Ú__init__r<   r   ÚLinearr)   r7   Úfilm_mulÚfilm_addr=   Úvision_configÚ
patch_sizeÚ
SequentialÚConv2dÚReLUÚConvTranspose2dÚtransposed_convolutionÚlenr6   Ú
ModuleListÚranger¸   ÚreducesÚcopyÚdeepcopyr8   Únum_attention_headsr;   Úintermediate_sizeÚ
hidden_actr�   ÚlayersÚ	post_init)rk   r¢   Útransposed_kernelsÚdepthr˜   Údecoder_configr~   s   &&    €r,   rÖ   ÚCLIPSegDecoder.__init__'  sj  ø€ Ü‰Ñ˜Ô à!'×!9Ñ!9ˆÔäŸ	š	 &×"7Ñ"7¸×9JÑ9JÓKˆŒÜŸ	š	 &×"7Ñ"7¸×9JÑ9JÓKˆŒà×4×4Ñ4Ø"(×"6Ñ"6×"AÑ"AÀQÕ"FÈ×H\ÑH\×HgÑHgÐklÕHlÐ!mÐä*,¯-ª-Ü—	’	˜&×+Ñ+¨V×->Ñ->ÈAÐWXÔYÜ—’“	Ü×"Ò"Ø×%Ñ%Ø×%Ñ%¨Õ*Ø 2°1Õ 5Ø-¨aÕ0ô	ô —’“	Ü×"Ò"Ø×%Ñ%¨Õ*¨AÐ;MÈaÕ;PÐYkÐlmÕYnôó+ˆDÕ'ô +-×*<Ò*<Ø×!Ñ! 1 f×&:Ñ&:×&EÑ&EÈf×NbÑNb×NmÑNmô+ˆDÔ'ô �F×)Ñ)Ó*ˆÜ—}’}ÜUZÐ[`ÔUaÓbÑUaÐPQŒR�YŠY�v×+Ñ+×7Ñ7¸×9JÑ9JÖKÑUaÑbó
ˆŒô Ÿš v×';Ñ';Ó<ˆØ%+×%6Ñ%6ˆÔ"Ø-3×-OÑ-OˆÔ*Ø+1×+KÑ+KˆÔ(Ø$*ˆÔ!Ü—m’mÔRWÔX[Ð\b×\qÑ\qÓXrÔRsÓ$tÑRsÈQÔ%8¸Ö%HÑRsÑ$tÓuˆŒà�‰Öùò cùò %us   È<>MÌMc                óz   <€ V ^8„  d   QhRS[ S[P                  ,          RS[P                  RS[S[,          RS[/# )r5   rV   ro   r–   r_   )r@   rX   rw   r	   r   rS   )rD   rE   s   "€r,   rF   rÏ   V  sF   ø€ ÷ %3ñ %3á™UŸ\™\Õ*ð%3ñ !&§¡ð%3ñ Ñ+Õ,ð	%3ñ
 
ñ%3r+   c                óò  € VRRR1,          pRp\        \        W@P                  V P                  4      4       F’  w  pw  rxp	Ve   V	! V4      V,           pMV	! V4      pW`P                  8X  dS   V P                  V4      VP                  ^^ ^4      ,          V P                  V4      ,           pVP                  ^^ ^4      pV! V3RR/VB pK”  	  VR,          P                  ^^4      p\        \        P                  ! VP                  ^,          4      4      p
VP                  ^ ,          pVP                  WµP                  ^,          Wª4      pV P                  V4      P                  ^4      p\!        VR7      # )a  
conditional_embeddings (`torch.FloatTensor` of shape `(batch_size, config.projection_dim)`, *optional*):
    The conditional embeddings for the query images. If provided, the model will use this instead of computing
    the embeddings from the conditional_pixel_values.
Nr�   )rU   rŸ   )ºNNN:r    NNrò   )Ú	enumerateÚziprê   rä   r<   rØ   ÚpermuterÙ   Ú	transposer?   ÚmathÚsqrtr¬   Úviewrà   ÚsqueezerS   )rk   rV   ro   r–   ÚactivationsÚoutputÚiÚ
activationÚlayerÚreduceÚsizeÚ
batch_sizerU   s   &&&,         r,   r|   ÚCLIPSegDecoder.forwardS  sS  € ð $¡D b DÕ)ˆàˆÜ.7¼¸KÏÉÐVZ×VbÑVbÓ8cÖ.dÑ*ˆAÑ*�
 6ØÒ!Ù 
Ó+¨fÕ4‘á 
Ó+�à×*Ñ*Ô*ØŸ™Ð'=Ó>ÀÇÁÐPQÐSTÐVWÓAXÕXÐ[_×[hÑ[hØ*ó\õ �ð  Ÿ™¨¨1¨aÓ0�á˜6ÑA°$ÐA¸&ÑAŠFñ /eð ˜Õ!×+Ñ+¨A¨qÓ1ˆä”4—9’9˜VŸ\™\¨!�_Ó-Ó.ˆà+×1Ñ1°!Õ4ˆ
Ø—‘˜Z¯©°a­¸$ÓEˆà×,Ñ,¨VÓ4×<Ñ<¸QÓ?ˆä#¨6Ô2Ð2r+   )r<   rÙ   rØ   rê   rä   rà   )r#   r$   r%   r&   rÖ   r   r   r   r|   r*   rL   r‚   rƒ   s   @@r,   rË   rË   &  s9   ù‡ € ÷*ó *ðX  ØØ÷%3ó ó ó  ÷%3ð %3r+   rË   c                   ó>   a a€ ] tR tRt oV3R lV 3R lltRtVtV ;t# )ÚCLIPSegTextModeli~  c                ó0   <€ V ^8„  d   QhRS[ S[,          /# r^   )r@   r   )rD   rE   s   "€r,   rF   ÚCLIPSegTextModel.__annotate__  s   ø€ ÷ /ñ /©Ñ1KÕ)Kñ /r+   c                ó$   <€ \         SV `  ! R/ VB # )aë  
Examples:

```python
>>> from transformers import AutoTokenizer, CLIPSegTextModel

>>> tokenizer = AutoTokenizer.from_pretrained("CIDAS/clipseg-rd64-refined")
>>> model = CLIPSegTextModel.from_pretrained("CIDAS/clipseg-rd64-refined")

>>> inputs = tokenizer(["a photo of a cat", "a photo of a dog"], padding=True, return_tensors="pt")

>>> outputs = model(**inputs)
>>> last_hidden_state = outputs.last_hidden_state
>>> pooled_output = outputs.pooler_output  # pooled (EOS token) states
```r!   rz   ©rk   Úsuper_kwargsr~   s   &,€r,   r|   ÚCLIPSegTextModel.forward  s   ø€ ô  ‰wŠÑ. Ñ.Ð.r+   r!   r�   rƒ   s   @@r,   r  r  ~  s   ù‡ € ÷/÷ /ó /r+   r  c                   óB   a a€ ] tR tRt oRV3R lV 3R llltRtVtV ;t# )ÚCLIPSegVisionModeli’  c          	      ó‚   <€ V ^8„  d   QhRS[ P                  R,          RS[R,          RS[S[,          RS[S[,          /# )r5   rv   Nr}   r–   r_   ©rX   rY   rC   r	   r   r@   r   )rD   rE   s   "€r,   rF   ÚCLIPSegVisionModel.__annotate__“  sT   ø€ ÷ Qñ Qá×'Ñ'¨$Õ.ðQñ #'¨¥+ðQñ Ñ+Õ,ð	Qñ
 
Ñ+Õ	+ñQr+   c                ó&   <€ \         SV `  ! W3/ VB # )a«  
Examples:

```python
>>> import httpx
>>> from io import BytesIO
>>> from PIL import Image
>>> from transformers import AutoProcessor, CLIPSegVisionModel

>>> processor = AutoProcessor.from_pretrained("CIDAS/clipseg-rd64-refined")
>>> model = CLIPSegVisionModel.from_pretrained("CIDAS/clipseg-rd64-refined")

>>> url = "http://images.cocodataset.org/val2017/000000039769.jpg"
>>> with httpx.stream("GET", url) as response:
...     image = Image.open(BytesIO(response.read()))

>>> inputs = processor(images=image, return_tensors="pt")

>>> outputs = model(**inputs)
>>> last_hidden_state = outputs.last_hidden_state
>>> pooled_output = outputs.pooler_output  # pooled CLS states
```rz   ©rk   rv   r}   r–   r~   s   &&&,€r,   r|   ÚCLIPSegVisionModel.forward“  s   ø€ ô8 ‰wŠ˜|ÑPÈÑPÐPr+   r!   r€   r�   rƒ   s   @@r,   r  r  ’  s   ù‡ € ÷Q÷ Qõ Qr+   r  c                   ój   a a€ ] tR tRt oV 3R ltRV3R lV 3R llltRV3R lV 3R llltRtVtV ;t	# )	r»   i²  c                ó$   <€ \         SV `  ! R/ VB # )a·  
Examples:

```python
>>> import torch
>>> from transformers import AutoTokenizer, CLIPSegModel

>>> tokenizer = AutoTokenizer.from_pretrained("CIDAS/clipseg-rd64-refined")
>>> model = CLIPSegModel.from_pretrained("CIDAS/clipseg-rd64-refined")

>>> inputs = tokenizer(["a photo of a cat", "a photo of a dog"], padding=True, return_tensors="pt")
>>> with torch.inference_mode():
...     text_features = model.get_text_features(**inputs)
```r!   )r{   Úget_text_featuresr	  s   &,€r,   r  ÚCLIPSegModel.get_text_features³  s   ø€ ô ‰wÒ(Ñ8¨<Ñ8Ð8r+   c          	      óf   <€ V ^8„  d   QhRS[ P                  RS[RS[S[,          RS[S[,          /# )r5   rv   r}   r–   r_   r  )rD   rE   s   "€r,   rF   ÚCLIPSegModel.__annotate__Ä  sK   ø€ ÷ \ñ \á×'Ñ'ð\ñ #'ð\ñ Ñ+Õ,ð	\ñ
 
Ñ+Õ	+ñ\r+   c                ó&   <€ \         SV `  ! W3/ VB # )a$  
Examples:

```python
>>> import torch
>>> from transformers import AutoProcessor, CLIPSegModel
>>> from transformers.image_utils import load_image

>>> processor = AutoProcessor.from_pretrained("CIDAS/clipseg-rd64-refined")
>>> model = CLIPSegModel.from_pretrained("CIDAS/clipseg-rd64-refined")

>>> url = "http://images.cocodataset.org/val2017/000000039769.jpg"
>>> image = load_image(url)

>>> inputs = processor(images=image, return_tensors="pt")

>>> with torch.inference_mode():
...     image_features = model.get_image_features(**inputs)
```)r{   Úget_image_featuresr  s   &&&,€r,   r  ÚCLIPSegModel.get_image_featuresÄ  s   ø€ ô2 ‰wÒ)¨,Ñ[ÐTZÑ[Ð[r+   c                ó    <€ V ^8„  d   QhRS[ /# )r5   r}   )rC   )rD   rE   s   "€r,   rF   r  ß  s   ø€ ÷ [ñ [±ñ [r+   c                ó,   <€ \         SV `  ! RRV/VB  R# )al  
return_loss (`bool`, *optional*):
    Whether or not to return the contrastive loss.

Examples:

```python
>>> import torch
>>> from transformers import AutoProcessor, CLIPSegModel
>>> from transformers.image_utils import load_image

>>> processor = AutoProcessor.from_pretrained("CIDAS/clipseg-rd64-refined")
>>> model = CLIPSegModel.from_pretrained("CIDAS/clipseg-rd64-refined")

>>> url = "http://images.cocodataset.org/val2017/000000039769.jpg"
>>> image = load_image(url)

>>> inputs = processor(
...     text=["a photo of a cat", "a photo of a dog"], images=image, return_tensors="pt", padding=True
... )

>>> with torch.inference_mode():
...     outputs = model(**inputs)
>>> logits_per_image = outputs.logits_per_image  # this is the image-text similarity score
>>> probs = logits_per_image.softmax(dim=1)  # we can take the softmax to get the label probabilities
```r}   Nr!   rz   )rk   r}   r
  r~   s   &&,€r,   r|   ÚCLIPSegModel.forwardß  s   ø€ ô6 	‰ŠÑZÐ1IÐZÈ\ÔZr+   r!   r€   )
r#   r$   r%   r&   r  r  r|   r*   rL   r‚   rƒ   s   @@r,   r»   r»   ²  s(   ù‡ € õ9÷"\õ \÷6[÷ [õ [r+   r»   zn
    CLIPSeg model with a Transformer-based decoder on top for zero-shot and one-shot image segmentation.
    )Úcustom_introc                   óŠ   a a€ ] tR tRt oV3R lV 3R lltR
V3R lR llt]]RV3R lR ll4       4       tV3R lt	R	t
VtV ;t# )ÚCLIPSegForImageSegmentationiý  c                ó    <€ V ^8„  d   QhRS[ /# rÍ   rÎ   )rD   rE   s   "€r,   rF   Ú(CLIPSegForImageSegmentation.__annotate__  s   ø€ ÷ ñ ™}ñ r+   c                ó¨   <€ \         SV `  V4       \        V4      V n        VP                  V n        \        V4      V n        V P                  4        R # rc   )r{   rÖ   r»   Úclipr6   rË   Údecoderrë   )rk   r¢   r~   s   &&€r,   rÖ   Ú$CLIPSegForImageSegmentation.__init__  s@   ø€ Ü‰Ñ˜Ô Ü  Ó(ˆŒ	Ø$×3Ñ3ˆÔÜ% fÓ-ˆŒà�‰Ör+   c                óè   <€ V ^8„  d   QhRS[ R,          RS[P                  R,          RS[P                  R,          RS[P                  R,          RS[P                  R,          RS[P                  /# )r5   r  NÚ	input_idsr�   rª   Úconditional_pixel_valuesr_   )r?   rX   rw   rY   )rD   rE   s   "€r,   rF   r$    su   ø€ ÷ &ñ &á˜$•Jð&ñ —<‘< $Õ&ð&ñ Ÿ™ tÕ+ð	&ñ
 —l‘l TÕ)ð&ñ #(§,¡,°Õ"5ð&ñ 
×	Ñ	ñ&r+   c                ó  € Vek   \        V4      V8w  d   \        R4      h\        P                  ! 4       ;_uu_ 4        V P                  P                  W#VR7      P                  pR R R 4       V# Vei   \        V4      V8w  d   \        R4      h\        P                  ! 4       ;_uu_ 4        V P                  P                  V4      P                  pR R R 4       V# \        R4      h  + '       g   i     X# ; i  + '       g   i     X# ; i)Nz@Make sure to pass as many prompt texts as there are query images)r�   rª   zAMake sure to pass as many prompt images as there are query imagesz[Invalid conditional, should be either provided as `input_ids` or `conditional_pixel_values`)rá   Ú
ValueErrorrX   rÇ   r&  r  Úpooler_outputr  )rk   r  r*  r�   rª   r+  ro   s   &&&&&& r,   Úget_conditional_embeddingsÚ6CLIPSegForImageSegmentation.get_conditional_embeddings  sé   € ð Ò ä�9‹~ Ô+Ü Ð!cÓdÐdÜ—’—•Ø)-¯©×)DÑ)DØÈ<ð *Eó *ç‘-ð '÷ !ð &Ð%ð &Ò1äÐ+Ó,°
Ô:Ü Ð!dÓeÐeÜ—’—•Ø)-¯©×)EÑ)EÐF^Ó)_×)mÑ)mÐ&÷ !ð &Ð%ô	 Ømóð ÷ !–ð &Ð%ú÷ !–ð &Ð%ús   ½(C&Â+&C:Ã&C7	Ã:D	c                ód  <€ V ^8„  d   QhRS[ P                  R,          RS[ P                  R,          RS[ P                  R,          RS[ P                  R,          RS[ P                  R,          RS[ P                  R,          RS[ P                  R,          R	S[R
S[S[,          RS[S[,          /
# )r5   r*  Nrv   r+  ro   r�   rª   Úlabelsr}   r–   r_   )	rX   rY   rw   Ú
LongTensorrC   r	   r   r@   rO   )rD   rE   s   "€r,   rF   r$  ,  sÑ   ø€ ÷ n
ñ n
á×$Ñ$ tÕ+ðn
ñ ×'Ñ'¨$Õ.ðn
ñ #(×"3Ñ"3°dÕ":ð	n
ñ
 !&× 1Ñ 1°DÕ 8ðn
ñ Ÿ™ tÕ+ðn
ñ ×&Ñ&¨Õ-ðn
ñ × Ñ  4Õ'ðn
ñ #'ðn
ñ Ñ+Õ,ðn
ñ 
‘Õ	ñn
r+   c	           	     óÆ  € \         P                  ! 4       ;_uu_ 4        RV	R&   V P                  P                  ! RRVRV/V	B p
V
P                  pV
P
                  pV P                   Uu. uF  qÜV^,           ,          NK  	  pp\        V
P                  V
P                  V
P
                  V
P                  R7      p
RRR4       Vf)   V P                  VP                  ^ ,          VVVVR7      pMkVP                  ^ ,          VP                  ^ ,          8w  d   \        R4      hVP                  ^,          V P                  P                  8w  d   \        R	4      hV P                  ! XV3/ V	B pVP                   pRpVe:   VP#                  VP$                  4      p\&        P(                  ! 4       pV! VV4      p\+        VVVXX
VR
7      # u upi   + '       g   i     EL; i)a®  
conditional_pixel_values (`torch.FloatTensor`, *optional*):
    The pixel values of the conditional images.
conditional_embeddings (`torch.FloatTensor` of shape `(batch_size, config.projection_dim)`, *optional*):
    The conditional embeddings for the query images. If provided, the model will use this instead of computing
    the embeddings from the conditional_pixel_values.
labels (`torch.LongTensor` of shape `(batch_size,)`, *optional*):
    Labels for computing the sequence classification/regression loss. Indices should be in `[0, ...,
    config.num_labels - 1]`. If `config.num_labels == 1` a regression loss is computed (Mean-Square loss), If
    `config.num_labels > 1` a classification loss is computed (Cross-Entropy).

Examples:

```python
>>> import torch
>>> from transformers import AutoProcessor, CLIPSegForImageSegmentation
>>> from transformers.image_utils import load_image

>>> processor = AutoProcessor.from_pretrained("CIDAS/clipseg-rd64-refined")
>>> model = CLIPSegForImageSegmentation.from_pretrained("CIDAS/clipseg-rd64-refined")

>>> url = "http://images.cocodataset.org/val2017/000000039769.jpg"
>>> image = load_image(url)

>>> texts = ["a cat", "a remote", "a blanket"]
>>> inputs = processor(text=texts, images=[image] * len(texts), padding=True, return_tensors="pt")

>>> with torch.inference_mode():
...     outputs = model(**inputs)

>>> logits = outputs.logits
>>> print(logits.shape)
torch.Size([3, 352, 352])
```TÚoutput_hidden_statesrv   r}   )Úlast_hidden_stater.  rV   rW   N)r  r*  r�   rª   r+  zWMake sure to pass as many conditional embeddings as there are query images in the batchzcMake sure that the feature dimension of the conditional embeddings matches `config.projection_dim`.)rn   rU   ro   rp   rq   rr   r!   )rX   rÇ   r&  r  r.  rV   r6   r   r6  rW   r/  r¬   r-  r¢   r)   r'  rU   ÚtoÚdevicer   ÚBCEWithLogitsLossr\   )rk   r*  rv   r+  ro   r�   rª   r2  r}   r–   Úvision_outputsrp   rV   rý   rû   Údecoder_outputsrU   rn   Úloss_fns   &&&&&&&&&,         r,   r|   Ú#CLIPSegForImageSegmentation.forward*  sê  € ôb �]Š]�_�_Ø-1ˆFÐ)Ñ*Ø!ŸY™Y×9Ò9ñ Ø)ðà)Aðð ñˆNð
 +×8Ñ8ˆMà*×8Ñ8ˆMà9=×9LÒ9LÓMÑ9L°A¨¨Q­×/Ð/Ñ9LˆKÐMô 8Ø"0×"BÑ"BØ,×:Ñ:Ø,×:Ñ:Ø)×4Ñ4ô	ˆN÷ ð, "Ò)Ø%)×%DÑ%DØ'×-Ñ-¨aÕ0Ø#Ø-Ø)Ø)Að &Eó &Ñ"ð &×+Ñ+¨AÕ.°,×2DÑ2DÀQÕ2GÔGÜ Ømóð ð &×+Ñ+¨AÕ.°$·+±+×2LÑ2LÔLÜ ð0óð ð Ÿ,š,ØØ"ñ
ð ñ
ˆð
 !×'Ñ'ˆàˆØÒà—Y‘Y˜vŸ}™}Ó-ˆFÜ×*Ò*Ó,ˆGÙ˜6 6Ó*ˆDä-ØØØ#9Ø'Ø .Ø*ô
ð 	
ùò[ N÷ �_ˆ_ús   žAGÁ*G
Â9GÇ
GÇG 	c                ó&   <€ V ^8„  d   Qh/ S[ ;R&   # rÍ   rÎ   )rD   rE   s   "€r,   rF   r$  ý  s   ø‡ ‚ ñ Ñò r+   )r&  r'  r6   )NNNNN)NNNNNNNT)r#   r$   r%   r&   rÖ   r/  r   r   r|   rK   r*   rL   r‚   rƒ   s   @@r,   r"  r"  ý  sE   ù‡ € ÷ó ÷&ò &ð: Ø÷n
ñ n
ó ó ðn
÷_ … r+   r"  )r1   r    r/   r»   r›   r  r  r"  )Ar'   rå   r÷   Údataclassesr   Útypingr   rX   Úhuggingface_hub.dataclassesr   r   Ú r   r¤   Úmodeling_outputsr   Úmodeling_utilsr   Úprocessing_utilsr	   Úutilsr
   r   r   Úutils.genericr   r   Úutils.output_capturingr   Úclip.configuration_clipr   r   r   Úclip.modeling_clipr   r   r   r   r   r   r   r   r   r   r   r    r/   r1   rO   rS   r\   rt   r…   r‡   r‰   r‹   r�   r›   rÉ   rË   r  r  r»   r"  Ú__all__r!   r+   r,   Ú<module>rL     s  ðñ ã Û Ý !Ý ã Ý .Ý å &Ý :Ý -Ý &ß DÑ Dß IÝ 5ß RÑ R÷÷ ÷ ñ ñ Ð/Ô0Øô&˜ó &ó ó 1ð&ñ( Ð/Ô0Øô&Ð*ó &ó ó 1ð&ñ( Ð/Ô0Øô+5�Jó +5ó ó 1ð+5ô\	�Jô 	ð Ø
ô<˜;ó <ó ó ð<ð$ Ø
ô_ [ó _ó ó ð_ô6@Ð2ô @ô	Ð.ô 	ô	�}ô 	ô	�ô 	ô	Ð*ô 	ôÐ*ô ð> ô(Ð0ó (ó ð(ôV	�[ô 	ôU3Ð+ô U3ôp/�}ô /ô(Q˜ô Qô@H[�9ô H[ñV ðôô
X
Ð"8ó X
óð
X
òv	‚r+   