
    ^j                         d 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 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 Swin2SR.    N)
functional   )TorchvisionBackend)BatchFeature)group_images_by_shapereorder_images)
ImageInputPILImageResamplingSizeDict)ImagesKwargsUnpack)
TensorTypeauto_docstringc                       e Zd ZU dZeed<   y)Swin2SRImageProcessorKwargsz
    size_divisor (`int`, *optional*, defaults to `self.size_divisor`):
        The size to make the height and width divisible by when padding.
    size_divisorN)__name__
__module____qualname____doc__int__annotations__     /var/www/ramen.bs-engineer-server.com/venv/lib/python3.12/site-packages/transformers/models/swin2sr/image_processing_swin2sr.pyr   r      s    
 r   r   F)totalc            #       $    e Zd ZdZeZdZdZdZdZ	de
e   f fdZedede
e   def fd	       Z	 ddd
ded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f"dZ xZS )Swin2SRImageProcessorz0Torchvision backend for Swin2SR with custom pad.Tgp?   kwargsc                 p    |j                  dd       }||j                  d|       t        |   di | y )Npad_sizer   r   )pop
setdefaultsuper__init__)selfr    r"   	__class__s      r   r&   zSwin2SRImageProcessor.__init__3   s9    ::j$/nh7"6"r   imagesreturnc                 $    t        |   |fi |S )N)r%   
preprocess)r'   r)   r    r(   s      r   r,   z Swin2SRImageProcessor.preprocess:   s     w!&3F33r   ztorch.Tensorr"   Nr   c                     |j                   dd \  }}||z  dz   |z  |z
  }||z  dz   |z  |z
  }t        j                  |dd||fd      S )zVPad images to make height and width divisible by size_divisor using symmetric padding.N   r   	symmetric)padding_mode)shapetvFpad)	r'   r)   r"   r   r    heightwidth
pad_height	pad_widths	            r   r4   zSwin2SRImageProcessor.padB   sf     RS),q0L@6I
l*Q.,>F	wwv1i<;WWr   	do_resizesizeresamplez7PILImageResampling | tvF.InterpolationMode | int | Nonedo_center_crop	crop_size
do_rescalerescale_factordo_normalize
image_mean	image_stddo_paddisable_groupingreturn_tensorsc                     t        ||      \  }}i }|j                         D ]4  \  }}|r| j                  ||      }|r| j                  |||      }|||<   6 t	        ||      }t        d|i|      S )z!Custom preprocessing for Swin2SR.)rD   )r"   r   pixel_values)datatensor_type)r   itemsrescaler4   r   r   )r'   r)   r9   r:   r;   r<   r=   r>   r?   r@   rA   rB   rC   r"   rD   rE   r   r    grouped_imagesgrouped_images_indexprocessed_images_groupedr2   stacked_imagesprocessed_imagess                           r   _preprocessz!Swin2SRImageProcessor._preprocessO   s    * 0EV^n/o,,#% %3%9%9%; 	=!E>!%nn!M!%.8Zf!g.<$U+	= **BDXY.2B!CQ_``r   )r   )r   r   r   r   r   valid_kwargsr>   r?   rC   r   r   r&   r   r	   r   r,   r   r   r4   listboolfloatstrr   rQ   __classcell__)r(   s   @r   r   r   (   s   :.LJNFL#(C!D # 44 454 
	4 4 	XX T/X 	X 
X< #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r   r   )r   torchtorchvision.transforms.v2r   r3   image_processing_backendsr   image_processing_utilsr   image_transformsr   r   image_utilsr	   r
   r   processing_utilsr   r   utilsr   r   r   r   __all__r   r   r   <module>ra      sf    )  7 ; 2 E 
 5 /,e  Da. Da DaN #
#r   