+
    œ°³j  ã                   óâ   € R t ^ RIHt ^ RIt^ RIt^ RIHt ^RI	H
t
 ^RIHt ^RIHtHt ^RIHtHt ^RIHtHt ^R	IHtHt  ! R
 R]RR7      tR R ltR R lt] ! R R]
4      4       tR.tR# )z#Image processor class for ImageGPT.)ÚUnionN)Ú
functional)ÚTorchvisionBackend)ÚBatchFeature)Úgroup_images_by_shapeÚreorder_images)ÚPILImageResamplingÚSizeDict)ÚImagesKwargsÚUnpack)Ú
TensorTypeÚauto_docstringc                   ó0   a € ] tR t^!t o RtV 3R ltRtV tR# )ÚImageGPTImageProcessorKwargsa   
clusters (`np.ndarray` or `list[list[int]]` or `torch.Tensor`, *optional*, defaults to `self.clusters`):
    The color clusters to use, of shape `(n_clusters, 3)` when color quantizing. Can be overridden by `clusters`
    in `preprocess`.
do_color_quantize (`bool`, *optional*, defaults to `self.do_color_quantize`):
    Controls whether to apply color quantization to convert continuous pixel values to discrete cluster indices.
    When True, each pixel is assigned to its nearest color cluster, enabling ImageGPT's discrete token modeling.
c                óŒ   <€ V ^8„  d   Qh/ S[ S[P                  S[S[S[,          ,          R3,          R,          ;R&   S[;R&   # )é   útorch.TensorNÚclustersÚdo_color_quantize)r   ÚnpÚndarrayÚlistÚintÚbool)ÚformatÚ__classdict__s   "€Úw/home/luca/screen-checking/.venv/lib/python3.14/site-packages/transformers/models/imagegpt/image_processing_imagegpt.pyÚ__annotate__Ú)ImageGPTImageProcessorKwargs.__annotate__!   s<   ø‡ ‚ ñ ‘B—J‘J¡¡T©#¥Y¥°Ð?Õ@À4ÕGÑGñ ñ Ñò ó    © N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__Ú__annotate_func__Ú__static_attributes__Ú__classdictcell__)r   s   @r   r   r   !   s   ø‡ € ñ÷ ƒ r   r   F)Útotalc                óx   € V ^8„  d   QhR\         P                  R\         P                  R\         P                  /# )r   ÚaÚbÚreturn©ÚtorchÚTensor)r   s   "r   r   r   /   s-   € ÷ ñ ¬¯©ð ¼¿¹ð Ì%Ï,É,ñ r   c                ó  € VP                  4       p\        P                  ! V ^,          ^R7      p\        P                  ! V^,          ^ R7      p\        P                  ! W4      pVR,          ^V,          ,
          VR,          ,           pV# )zÒ
Compute squared Euclidean distances between all pixels and clusters.

Args:
    a: (N, 3) tensor of pixel RGB values
    b: (M, 3) tensor of cluster RGB values

Returns:
    (N, M) tensor of squared distances
©Údim)ºNNNN)Nr4   )Útr/   ÚsumÚmatmul)r+   r,   Úa2Úb2ÚabÚds   &&    r   Ú squared_euclidean_distance_torchr<   /   se   € ð 	
�‰‹€AÜ	�Š�1�a•4˜QÔ	€BÜ	�Š�1�a•4˜QÔ	€BÜ	�Š�aÓ	€BØ
ˆ7��a˜"•fÕ˜r '�{Õ*€AØ€Hr   c                óx   € V ^8„  d   QhR\         P                  R\         P                  R\         P                  /# )r   Úxr   r-   r.   )r   s   "r   r   r   B   s-   € ÷ "ñ "œEŸL™Lð "´E·L±Lð "ÄUÇ\Á\ñ "r   c                óH   € \        W4      p\        P                  ! V^R7      # )z×
Assign each pixel to its nearest color cluster.

Args:
    x: (H*W, 3) tensor of flattened pixel RGB values
    clusters: (n_clusters, 3) tensor of cluster RGB values

Returns:
    (H*W,) tensor of cluster indices
r2   )r<   r/   Úargmin)r>   r   r;   s   && r   Úcolor_quantize_torchrA   B   s   € ô 	)¨Ó5€AÜ�<Š<˜˜qÔ!Ð!r   c                   ó¶   a a€ ] tR t^Qt oR.t]t]P                  t	Rt
Rt. ROt. ROtRtRtRRRR/tRtRV3R lV 3R llltRV3R	 lR
 lltV 3R ltRtVtV ;t# )ÚImageGPTImageProcessorÚ	input_idsTNÚheighté   Úwidthc                óŒ   <€ V ^8„  d   QhRS[ S[P                  ,          S[P                  ,          R,          RS[S[,          /# )r   r   NÚkwargs)r   r   r   r/   r0   r   r   )r   r   s   "€r   r   Ú#ImageGPTImageProcessor.__annotate___   s<   ø€ ÷ 6ñ 6á™Ÿ™Õ#¡e§l¡lÕ2°TÕ9ð6ñ Ñ5Õ6ñ6r   c                ó„   <€ Ve'   \         P                  ! V\         P                  R7      MRp\        SV `  ! RRV/VB  R# )zÓ
clusters (`np.ndarray` or `list[list[int]]` or `torch.Tensor`, *optional*):
    The color clusters to use, of shape `(n_clusters, 3)` when color quantizing. Can be overridden by `clusters`
    in `preprocess`.
N©Údtyper   r    )r/   Ú	as_tensorÚfloat32ÚsuperÚ__init__)Úselfr   rI   Ú	__class__s   &&,€r   rQ   ÚImageGPTImageProcessor.__init___   s8   ø€ ð FNÒEY”5—?’? 8´5·=±=ÕAÐ_cˆÜ‰ÒÑ5 (Ð5¨fÔ5r   c                ól  <€ V ^8„  d   QhRS[ R,          RS[RS[RRRS[RS[R	S[R
S[RS[RS[S[ S[,          ,          R,          RS[S[ S[,          ,          R,          RS[R,          RS[S[,          R,          RS[R,          RS[ S[P                  ,          S[P                  ,          R,          /# )r   Úimagesr   Ú	do_resizeÚsizeÚresamplez7PILImageResampling | tvF.InterpolationMode | int | NoneÚdo_center_cropÚ	crop_sizeÚ
do_rescaleÚrescale_factorÚdo_normalizeÚ
image_meanNÚ	image_stdÚdisable_groupingÚreturn_tensorsr   r   )
r   r   r	   ÚfloatÚstrr   r   r   r/   r0   )r   r   s   "€r   r   rJ   l   s  ø€ ÷ I]ñ I]á�^Õ$ðI]ñ ðI]ñ ð	I]ð
 LðI]ñ ðI]ñ ðI]ñ ðI]ñ ðI]ñ ðI]ñ ™D¡�KÕ'¨$Õ.ðI]ñ ™4¡�;Õ&¨Õ-ðI]ñ  �+ðI]ñ ™jÕ(¨4Õ/ðI]ñ   $�;ðI]ñ  ™Ÿ™Õ#¡e§l¡lÕ2°TÕ9ñ!I]r   c           	     óB  € \        WR 7      w  pp/ pVP                  4        F&  w  ppV'       d   V P                  VW4R7      pVVV&   K(  	  \        VV4      p\        VVR 7      w  pp/ pVP                  4        F9  w  ppV'       d   V P	                  VV4      pV P                  VWxWšV4      pVVV&   K;  	  \        VV4      pV'       EdG   Vf   \        R4      h\        V\        P                  4      '       g'   \        P                  ! V\        P                  R7      MTP                  V^ ,          P                  V^ ,          P                  R7      p\        VVR 7      w  pp/ pVP                  4        F{  w  pp\        VP!                  ^ ^^^4      P#                  R^4      V4      pVP#                  VP$                  ^ ,          R4      P#                  VP$                  ^ ,          R4      VV&   K}  	  \        VV4      p\'        RV/VR7      # \'        RV/VR7      # ))ra   )ÚimagerX   rY   z1Clusters must be provided for color quantization.rL   rD   )ÚdataÚtensor_typeÚpixel_valueséÿÿÿÿ)r   ÚitemsÚresizer   Úcenter_cropÚrescale_and_normalizeÚ
ValueErrorÚ
isinstancer/   r0   rN   rO   ÚtoÚdevicerM   rA   ÚpermuteÚreshapeÚshaper   )rR   rV   rW   rX   rY   rZ   r[   r\   r]   r^   r_   r`   ra   rb   r   r   rI   Úgrouped_imagesÚgrouped_images_indexÚresized_images_groupedru   Ústacked_imagesÚresized_imagesÚprocessed_images_groupedri   Úclusters_torchÚinput_ids_groupedrD   s   &&&&&&&&&&&&&&&&,           r   Ú_preprocessÚ"ImageGPTImageProcessor._preprocessl   s.  € ô( 0EÀVÔ/oÑ,ˆÐ,Ø!#ÐØ%3×%9Ñ%9Ö%;Ñ!ˆE�>ßØ!%§¡°>È Ó!`�Ø,:Ð" 5Ó)ñ &<ô (Ð(>Ð@TÓUˆô 0EÀ^ÐfvÔ/wÑ,ˆÐ,Ø#%Ð Ø%3×%9Ñ%9Ö%;Ñ!ˆE�>ßØ!%×!1Ñ!1°.À)Ó!L�à!×7Ñ7Ø 
¸LÐV_óˆNð /=Ð$ UÓ+ñ &<ô &Ð&>Ð@TÓUˆ÷ ÐàÒÜ Ð!TÓUÐUô GQÐQYÔ[`×[gÑ[g×FhÒFh”—’ ´·±Õ>Ðnvß‰b�˜a•×'Ñ'¨|¸A­×/DÑ/DˆbÓEð ô 4IØÐ/?ô4Ñ0ˆNÐ0ð !#Ðà)7×)=Ñ)=Ö)?Ñ%��~Ü0Ø"×*Ñ*¨1¨a°°AÓ6×>Ñ>¸rÀ1ÓEÀ~ó�	ð ,5×+<Ñ+<¸^×=QÑ=QÐRSÕ=TÐVXÓ+Y×+aÑ+aØ"×(Ñ(¨Õ+¨Ró,Ð! %Ó(ñ	 *@ô 'Ð'8Ð:NÓOˆIä k°9Ð%=È>ÔZÐZä .°,Ð!?È^Ô\Ð\r   c                óÌ   <€ \         SV `  4       pVP                  R 4      eB   \        VR ,          \        P
                  4      '       d   VR ,          P                  4       VR &   V# )r   )rP   Úto_dictÚgetrp   r/   r0   Útolist)rR   ÚoutputrS   s   & €r   r�   ÚImageGPTImageProcessor.to_dict·   sS   ø€ ä‘‘Ó"ˆØ�:‰:�jÓ!Ò-´*¸VÀJÕ=OÔQV×Q]ÑQ]×2^Ò2^Ø!'¨
Õ!3×!:Ñ!:Ó!<ˆF�:Ñàˆr   r    )ç      à?r†   r†   )N)NN)r!   r"   r#   r$   Úmodel_input_namesr   Úvalid_kwargsr   ÚBILINEARrY   r   r   r_   r`   r\   r^   rX   rW   rQ   r~   r�   r'   r(   Ú__classcell__)rS   r   s   @@r   rC   rC   Q   sr   ù‡ € à$˜ÐØ/€LØ!×*Ñ*€HØÐØ€HÚ €JÚ€IØ€JØ€LØ�c˜7 CÐ(€DØ€I÷6õ 6÷I]ò I]÷Võ r   rC   )r%   Útypingr   Únumpyr   r/   Útorchvision.transforms.v2r   ÚtvFÚimage_processing_backendsr   Úimage_processing_utilsr   Úimage_transformsr   r   Úimage_utilsr   r	   Úprocessing_utilsr
   r   Úutilsr   r   r   r<   rA   rC   Ú__all__r    r   r   Ú<module>r–      sl   ðñ *å ã Û Ý 7å ;Ý 2ß Eß 7ß 4÷ô <°uõ õõ&"ð ôkÐ/ó kó ðkð\ $Ð
$‚r   