Ë
    ÛÓ^jé  ã                   óÔ   — d Z ddlmZ ddlmZ ddlZddlmZ ddl	m
Z
 ddlmZ dd	lmZmZ dd
lmZmZmZmZ ddlmZmZ ddlmZmZ  G d„ ded¬«      Ze G d„ de
«      «       ZdgZy)z'Image processor class for EfficientNet.é    )Ú	lru_cache)ÚOptionalN)Ú
functionalé   )ÚTorchvisionBackend)ÚBatchFeature)Úgroup_images_by_shapeÚreorder_images)ÚIMAGENET_STANDARD_MEANÚIMAGENET_STANDARD_STDÚPILImageResamplingÚSizeDict)ÚImagesKwargsÚUnpack)Ú
TensorTypeÚauto_docstringc                   ó&   — e Zd ZU dZeed<   eed<   y)Ú EfficientNetImageProcessorKwargsak  
    rescale_offset (`bool`, *optional*, defaults to `self.rescale_offset`):
        Whether to rescale the image between [-max_range/2, scale_range/2] instead of [0, scale_range].
    include_top (`bool`, *optional*, defaults to `self.include_top`):
        Normalize the image again with the standard deviation only for image classification if set to True.
    Úrescale_offsetÚinclude_topN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚboolÚ__annotations__© ó    ú‰/var/www/ramen.bs-engineer-server.com/venv/lib/python3.12/site-packages/transformers/models/efficientnet/image_processing_efficientnet.pyr   r   #   s   … ñð ÓØÔr   r   F)Útotalc            %       ó  ‡ — e Zd ZdZeZej                  Ze	Z
eZdddœZdddœZdZdZdZdZdZdZdZdee   fˆ fd	„Z	 d*d
ddededdfd„Z ed¬«      	 	 	 	 	 	 	 d+dedz  deee   z  dz  deee   z  dz  dedz  dedz  ded   dedz  defd„«       Z	 d*dddedededeee   z  deee   z  deddfd„Z 	 	 d,ded   dede!d d!d"ed#e!dedededeee   z  dz  deee   z  dz  d$edz  d%e!dz  d&edz  d'e"e#z  dz  ded(ede$f$d)„Z%ˆ xZ&S )-ÚEfficientNetImageProcessorzITorchvision backend for EfficientNet with rescale offset and include_top.iZ  )ÚheightÚwidthi!  TFgp?Úkwargsc                 ó$   •— t        ‰| �  di |¤Ž y )Nr   )ÚsuperÚ__init__)Úselfr%   Ú	__class__s     €r   r(   z#EfficientNetImageProcessor.__init__B   s   ø€ Ü‰ÑÑ"˜6Ó"r   Úimageztorch.TensorÚscaleÚoffsetÚreturnc                 ó   — ||z  }|r|dz  }|S )z@Rescale by scale; if offset=True then image = image * scale - 1.é   r   )r)   r+   r,   r-   r%   Úrescaleds         r   Úrescalez"EfficientNetImageProcessor.rescaleE   s   € ð ˜5‘=ˆÙØ˜‰MˆHØˆr   é
   )ÚmaxsizeNÚdo_normalizeÚ
image_meanÚ	image_stdÚ
do_rescaleÚrescale_factorÚdeviceztorch.devicer   c                 ó�   — |r@|r>|s<t        j                  ||¬«      d|z  z  }t        j                  ||¬«      d|z  z  }d}|||fS )N)r:   g      ð?F)ÚtorchÚtensor)r)   r5   r6   r7   r8   r9   r:   r   s           r   Ú!_fuse_mean_std_and_rescale_factorz<EfficientNetImageProcessor._fuse_mean_std_and_rescale_factorR   sQ   € ñ ™,©~ÜŸ™ j¸Ô@ÀCÈ.ÑDXÑYˆJÜŸ™ Y°vÔ>À#ÈÑBVÑWˆIØˆJØ˜9 jÐ0Ð0r   Úimagesc           	      óä   — | j                  ||||||j                  |¬«      \  }}}|r| j                  |||¬«      }|r1| j                  |j	                  t
        j                  ¬«      ||«      }|S )N)r5   r6   r7   r8   r9   r:   r   )r-   )Údtype)r>   r:   r2   Ú	normalizeÚtor<   Úfloat32)r)   r?   r8   r9   r5   r6   r7   r   s           r   Ú"rescale_and_normalize_efficientnetz=EfficientNetImageProcessor.rescale_and_normalize_efficientnetc   s}   € ð -1×,RÑ,RØ%Ø!ØØ!Ø)Ø—=‘=Ø)ð -Só -
Ñ)ˆ
�I˜zñ Ø—\‘\ &¨.À�\ÓPˆFÙØ—^‘^ F§I¡I´E·M±M IÓ$BÀJÐPYÓZˆFØˆr   Ú	do_resizeÚsizeÚresamplez7PILImageResampling | tvF.InterpolationMode | int | NoneÚdo_center_cropÚ	crop_sizeÚdo_padÚpad_sizeÚdisable_groupingÚreturn_tensorsr   c           
      ó¶  — t        ||¬«      \  }}i }|j                  «       D ]  \  }}|r| j                  |||«      }|||<   Œ! t        ||«      }t        ||¬«      \  }}i }|j                  «       D ]J  \  }}|r| j	                  ||«      }| j                  ||||	|
||«      }|r| j                  |d|«      }|||<   ŒL t        ||«      }t        d|i|¬«      S )z&Custom preprocessing for EfficientNet.)rM   r   Úpixel_values)ÚdataÚtensor_type)r	   ÚitemsÚresizer
   Úcenter_croprE   rB   r   )r)   r?   rF   rG   rH   rI   rJ   r8   r9   r5   r6   r7   rK   rL   rM   rN   r   r   r%   Úgrouped_imagesÚgrouped_images_indexÚresized_images_groupedÚshapeÚstacked_imagesÚresized_imagesÚprocessed_images_groupedÚprocessed_imagess                              r   Ú_preprocessz&EfficientNetImageProcessor._preprocess}   s  € ô, 0EÀVÐ^nÔ/oÑ,ˆÐ,Ø!#ÐØ%3×%9Ñ%9Ó%;ò 	;Ñ!ˆE�>ÙØ!%§¡¨^¸TÀ8Ó!L�Ø,:Ð" 5Ò)ð	;ô (Ð(>Ð@TÓUˆä/DÀ^ÐfvÔ/wÑ,ˆÐ,Ø#%Ð Ø%3×%9Ñ%9Ó%;ò 	=Ñ!ˆE�>ÙØ!%×!1Ñ!1°.À)Ó!L�Ø!×DÑDØ 
¨N¸LÈ*ÐV_ÐaoóˆNñ Ø!%§¡°ÀÀ9Ó!M�Ø.<Ð$ UÒ+ð	=ô *Ð*BÐDXÓYÐÜ .Ð2BÐ!CÐQ_Ô`Ð`r   )F)NNNNNNF)FT)'r   r   r   r   r   Úvalid_kwargsr   ÚBICUBICrH   r   r6   r   r7   rG   rJ   rF   rI   r8   r9   r   r5   r   r   r(   Úfloatr   r2   r   Úlistr   Útupler>   rE   r   Ústrr   r   r^   Ú__classcell__)r*   s   @r   r"   r"   /   s½  ø„ áSà3€Là!×)Ñ)€HØ'€JØ%€IØ CÑ(€DØ¨Ñ-€IØ€IØ€NØ€JØ€NØ€NØ€LØ€Kð# Ð(HÑ!Iõ #ð ñ	àðð ðð ð	ð 
óñ �rÔð %)Ø15Ø04Ø"&Ø'+Ø+/Ø&+ñ1à˜T‘kð1ð ˜D ™KÑ'¨$Ñ.ð1ð ˜4 ™;Ñ&¨Ñ-ð	1ð
 ˜4‘Kð1ð  ™ð1ð ˜Ñ(ð1ð ˜t™ð1ð 
ò1ó ð1ð0  %ñàðð ðð ð	ð
 ðð ˜D ™KÑ'ðð ˜4 ™;Ñ&ðð ðð 
óðV  %Ø ñ%*aà�^Ñ$ð*að ð*að ð	*að
 Lð*að ð*að ð*að ð*að ð*að ð*að ˜D ™KÑ'¨$Ñ.ð*að ˜4 ™;Ñ&¨Ñ-ð*að �t‘ð*að ˜T‘/ð*að  ™+ð*að  ˜jÑ(¨4Ñ/ð!*að" ð#*að$ ð%*að( 
÷)*ar   r"   )r   Ú	functoolsr   Útypingr   r<   Útorchvision.transforms.v2r   ÚtvFÚimage_processing_backendsr   Úimage_processing_utilsr   Úimage_transformsr	   r
   Úimage_utilsr   r   r   r   Úprocessing_utilsr   r   Úutilsr   r   r   r"   Ú__all__r   r   r   ú<module>rq      sl   ðñ .å Ý ã Ý 7å ;Ý 2ß E÷ó ÷ 5ß /ô	 |¸5õ 	ð ôwaÐ!3ó waó ðwaðt (Ð
(�r   