
    <hk#                     :   S r SSKrSSKJrJr  SSKJr  SSKJrJ	r	  SSK
JrJr  SSKJrJrJrJrJrJr  SS	KJr  SS
KJrJrJrJrJr  \" 5       (       a  SSKr\" 5       (       a  SSKJr  O\" 5       (       a  SSK Jr   " S S\	5      r!\ " S S\5      5       r"S/r#g)z%Fast Image processor class for OWLv2.    N)OptionalUnion)OwlViTImageProcessorFast   )BatchFeatureDefaultFastImageProcessorKwargs)group_images_by_shapereorder_images)OPENAI_CLIP_MEANOPENAI_CLIP_STDChannelDimension
ImageInputPILImageResamplingSizeDict)Unpack)
TensorTypeauto_docstringis_torch_availableis_torchvision_availableis_torchvision_v2_available)
functionalc                   *    \ rS rSr% Sr\\   \S'   Srg)Owlv2FastImageProcessorKwargs7   z
do_pad (`bool`, *optional*, defaults to `True`):
    Controls whether to pad the image. Can be overridden by the `do_pad` parameter in the `preprocess`
    method. If `True`, padding will be applied to the bottom and right of the image with grey pixels.
do_pad N)	__name__
__module____qualname____firstlineno____doc__r   bool__annotations____static_attributes__r       _/var/www/html/shao/venv/lib/python3.13/site-packages/transformers/models/owlv2/modular_owlv2.pyr   r   7   s     TNr%   r   c                      \ rS rSr\R
                  r\r\	r
SSS.rSrSrSrSrSr\rSrSrS\\   4S jr\S	\S\\   4S
 j5       rS!S	SS\SS4S jjr S!S	\S   S\\   S\S\S   4S jjr  S"SSS\ S\SS4S jjr!S	\S   S\S\ S\S   S\S\S\S\S\\"\\\   4      S\\"\\\   4      S\\   S\\"\#\$4      S\%4S jr&S r'g)#Owlv2ImageProcessorFastA   i  )heightwidthgp?TNkwargsc                 8    [        5       R                  " S0 UD6  g )Nr   )r   __init__)selfr,   s     r&   r.    Owlv2ImageProcessorFast.__init__P   s     "++5f5r%   imagesc                 8    [        5       R                  " U40 UD6$ )N)r   
preprocess)r/   r1   r,   s      r&   r3   "Owlv2ImageProcessorFast.preprocessS   s    ')44VFvFFr%   ztorch.Tensorconstant_valuereturnc                     UR                   SS u  p4[        X45      nXS-
  nXT-
  nSSXv4n[        R                  " XUS9n	U	$ )z,
Pad an image with zeros to the given size.
Nr   )fill)shapemaxFpad)
r/   r1   r5   r*   r+   size
pad_bottom	pad_rightpaddingpadded_images
             r&   _pad_images#Owlv2ImageProcessorFast._pad_imagesW   sP     RS)6!]
L	a/uuV>Br%   disable_groupingc                     [        XS9u  pE0 nUR                  5        H  u  pxU R                  UUS9nXU'   M     [        Xe5      n	U	$ )NrE   )r5   )r	   itemsrC   r
   )
r/   r1   rE   r5   grouped_imagesgrouped_images_indexprocessed_images_groupedr:   stacked_imagesprocessed_imagess
             r&   r=   Owlv2ImageProcessorFast.padd   sg     0EV/o,#% %3%9%9%;!E!--- . N /=U+ &< **BYr%   imager>   anti_aliasingc                    UR                   UR                  4nUR                  n[        R                  " USS 5      R                  UR                  5      [        R                  " U5      R                  UR                  5      -  nU(       Ga#  Uc  US-
  S-  R                  SS9nO[        R                  " U5      [        R                  " U5      -  n[        R                  " US:  5      (       a  [        S5      e[        R                  " US:  US:*  -  5      (       a  [        R                  " S5        [        R                  " US:H  5      (       a  Un	O[S[        R                  " SU-  5      R                  5       -  S-   n
[         R"                  " XS   U
S   4UR%                  5       S	9n	OUn	[         R&                  " XR                   UR                  4S
S9nU$ )a  
Resize an image as per the original implementation.

Args:
    image (`Tensor`):
        Image to resize.
    size (`dict[str, int]`):
        Dictionary containing the height and width to resize the image to.
    anti_aliasing (`bool`, *optional*, defaults to `True`):
        Whether to apply anti-aliasing when downsampling the image.
    anti_aliasing_sigma (`float`, *optional*, defaults to `None`):
        Standard deviation for Gaussian kernel when downsampling the image. If `None`, it will be calculated
        automatically.
   N   r   )minzFAnti-aliasing standard deviation must be greater than or equal to zerozWAnti-aliasing standard deviation greater than zero but not down-sampling along all axesr   )sigmaF)r>   	antialias)r*   r+   r:   torchtensortodeviceclamp
atleast_1d	ones_likeany
ValueErrorwarningswarnceilintr<   gaussian_blurtolistresize)r/   rO   r>   rP   anti_aliasing_sigmar,   output_shapeinput_shapefactorsfilteredkernel_sizesouts               r&   rf   Owlv2ImageProcessorFast.resizew   s   , TZZ0kk ,,{12/225<<@5<<P\C]C`C`afamamCnn"*(/!q'8&?&?A&?&F#&+&6&67J&Keoo^eNf&f#9901455$%mnnYY 3a 7GqLIJJMMq yy,122  5::a2E.E#F#J#J#LLqP??O\!_=EXE_E_Ea
 Hhhx{{DJJ&?5Q
r%   	do_resizeinterpolationzF.InterpolationModer   
do_rescalerescale_factordo_normalize
image_mean	image_stdreturn_tensorsc           	      z   [        XS9u  p0 nUR                  5        H  u  nnU R                  UXgSX5      nUUU'   M!     [        UU5      nU(       a  U R	                  UUS9n[        UUS9u  p0 nUR                  5        H4  u  nnU(       d  M  U R                  UUU[        R                  S9nUUU'   M6     [        UU5      n[        UUS9u  p0 nUR                  5        H  u  nnU R                  USXxX5      nUUU'   M!     [        UU5      nU(       a  [        R                  " USS9OUn[        SU0US9$ )NrG   F)rO   r>   rp   input_data_formatr   )dimpixel_values)datatensor_type)r	   rH   rescale_and_normalizer
   r=   rf   r   FIRSTrW   stackr   )r/   r1   ro   r>   rp   r   rq   rr   rs   rt   ru   rE   rv   r,   rI   rJ   rK   r:   rL   rM   resized_images_groupedresized_stackresized_imagess                          r&   _preprocess#Owlv2ImageProcessorFast._preprocess   s   " 0EV/o,#% %3%9%9%;!E>!77
E:N /=$U+ &< **BDXY#xx(8K[x\/D/?0
, "$%3%9%9%;!E>y $("/&6&<&<	 !, ! 1>&u- &< ((>@TU 0E^fv/w,#% %3%9%9%;!E>!77~ZN /=$U+ &< **BDXYCQ5;;'7Q?Wg.2B!CQ_``r%   r   )g      ?)TN)(r   r   r   r    r   BILINEARresampler   rt   r   ru   r>   rr   ro   rq   rs   r   r   valid_kwargs	crop_sizedo_center_cropr   r.   r   r   r3   floatrC   listr   r"   r=   r   rf   r   strr   r   r   r$   r   r%   r&   r(   r(   A   s   !**H!JIC(DNIJLF0LIN6(E!F 6 G Gv>[7\ G G. % R` " !$	 ^$  #4.  	 
 
n	 . # 66 6 	6 
6p>a^$>a >a 	>a
   56>a >a >a >a >a U5$u+#567>a E%e"456>a #4.>a !sJ!78>a 
>ar%   r(   )$r!   r`   typingr   r   7transformers.models.owlvit.image_processing_owlvit_fastr   image_processing_utils_fastr   r   image_transformsr	   r
   image_utilsr   r   r   r   r   r   processing_utilsr   utilsr   r   r   r   r   rW   torchvision.transforms.v2r   r<   torchvision.transformsr   r(   __all__r   r%   r&   <module>r      s    ,  " \ F  '     96$C  ka6 ka ka\ %
%r%   