
    cCi1                     ,   S r SSKJrJrJr  SSKJr  \(       a  SSKJr  SSK	r
SSK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JrJrJrJr  SS
KJrJ r J!r!J"r"  \" 5       (       a  SSK#r#\!RH                  " \%5      r&\" SS9 " S S\5      5       r'S/r(g)zImage processor class for GLPN.    )TYPE_CHECKINGOptionalUnion   )requires)DepthEstimatorOutputN)BaseImageProcessorBatchFeature)resizeto_channel_dimension_format)
ChannelDimensionPILImageResamplingget_image_sizeinfer_channel_dimension_formatis_scaled_imageis_torch_availablemake_flat_list_of_imagesto_numpy_arrayvalid_imagesvalidate_preprocess_arguments)
TensorTypefilter_out_non_signature_kwargsloggingrequires_backends)vision)backendsc                     ^  \ rS rSrSrS/rSS\R                  S4S\S\	S\S	S
4U 4S jjjr
\R                  S
S
4S\R                  S\	S\S\\   S\\\\4      S	\R                  4S jjr\" 5       S
S
S
S
S
\R&                  S
4S\S\\S   \\   4   S\\   S\\	   S\\   S\\\\4      S\S\\\\4      S	\4S jj5       r SSSS\\\\\\	\	4      S
4      S	\\\\4      4S jjrSrU =r$ )GLPNImageProcessor4   a  
Constructs a GLPN image processor.

Args:
    do_resize (`bool`, *optional*, defaults to `True`):
        Whether to resize the image's (height, width) dimensions, rounding them down to the closest multiple of
        `size_divisor`. Can be overridden by `do_resize` in `preprocess`.
    size_divisor (`int`, *optional*, defaults to 32):
        When `do_resize` is `True`, images are resized so their height and width are rounded down to the closest
        multiple of `size_divisor`. Can be overridden by `size_divisor` in `preprocess`.
    resample (`PIL.Image` resampling filter, *optional*, defaults to `Resampling.BILINEAR`):
        Resampling filter to use if resizing the image. Can be overridden by `resample` in `preprocess`.
    do_rescale (`bool`, *optional*, defaults to `True`):
        Whether or not to apply the scaling factor (to make pixel values floats between 0. and 1.). Can be
        overridden by `do_rescale` in `preprocess`.
pixel_valuesT    	do_resizesize_divisor
do_rescalereturnNc                 V   > Xl         X@l        X l        X0l        [        TU ]  " S0 UD6  g )N )r"   r$   r#   resamplesuper__init__)selfr"   r#   r(   r$   kwargs	__class__s         h/home/james-whalen/.local/lib/python3.13/site-packages/transformers/models/glpn/image_processing_glpn.pyr*   GLPNImageProcessor.__init__I   s*     #$( "6"    imager(   data_formatinput_data_formatc                 \    [        XS9u  pxXr-  U-  n	X-  U-  n
[        UX44UUUS.UD6nU$ )ar  
Resize the image, rounding the (height, width) dimensions down to the closest multiple of size_divisor.

If the image is of dimension (3, 260, 170) and size_divisor is 32, the image will be resized to (3, 256, 160).

Args:
    image (`np.ndarray`):
        The image to resize.
    size_divisor (`int`):
        The image is resized so its height and width are rounded down to the closest multiple of
        `size_divisor`.
    resample:
        `PIL.Image` resampling filter to use when resizing the image e.g. `PILImageResampling.BILINEAR`.
    data_format (`ChannelDimension` or `str`, *optional*):
        The channel dimension format for the output image. If `None`, the channel dimension format of the input
        image is used. Can be one of:
        - `ChannelDimension.FIRST`: image in (num_channels, height, width) format.
        - `ChannelDimension.LAST`: image in (height, width, num_channels) format.
    input_data_format (`ChannelDimension` or `str`, *optional*):
        The channel dimension format of the input image. If not set, the channel dimension format is inferred
        from the input image. Can be one of:
        - `"channels_first"` or `ChannelDimension.FIRST`: image in (num_channels, height, width) format.
        - `"channels_last"` or `ChannelDimension.LAST`: image in (height, width, num_channels) format.

Returns:
    `np.ndarray`: The resized image.
)channel_dim)r(   r2   r3   )r   r   )r+   r1   r#   r(   r2   r3   r,   heightwidthnew_hnew_ws              r.   r   GLPNImageProcessor.resizeW   s^    H 'uL&5%4N
 #/
 
 r0   imageszPIL.Image.Imagereturn_tensorsc	           
         Ub  UOU R                   nUb  UOU R                  nUb  UOU R                  nUb  UOU R                  n[	        U5      n[        U5      (       d  [        S5      e[        UUUS9  U V	s/ s H  n	[        U	5      PM     nn	U(       a(  [        US   5      (       a  [        R                  S5        Uc  [        US   5      nU(       a   U V
s/ s H  n
U R                  XXHS9PM     nn
U(       a   U V
s/ s H  oR                  U
SUS9PM     nn
U V
s/ s H  n
[        XUS9PM     nn
S	U0n[!        XS
9$ s  sn	f s  sn
f s  sn
f s  sn
f )a	  
Preprocess the given images.

Args:
    images (`PIL.Image.Image` or `TensorType` or `list[np.ndarray]` or `list[TensorType]`):
        Images to preprocess. Expects a single or batch of images with pixel values ranging from 0 to 255. If
        passing in images with pixel values between 0 and 1, set `do_normalize=False`.
    do_resize (`bool`, *optional*, defaults to `self.do_resize`):
        Whether to resize the input such that the (height, width) dimensions are a multiple of `size_divisor`.
    size_divisor (`int`, *optional*, defaults to `self.size_divisor`):
        When `do_resize` is `True`, images are resized so their height and width are rounded down to the
        closest multiple of `size_divisor`.
    resample (`PIL.Image` resampling filter, *optional*, defaults to `self.resample`):
        `PIL.Image` resampling filter to use if resizing the image e.g. `PILImageResampling.BILINEAR`. Only has
        an effect if `do_resize` is set to `True`.
    do_rescale (`bool`, *optional*, defaults to `self.do_rescale`):
        Whether or not to apply the scaling factor (to make pixel values floats between 0. and 1.).
    return_tensors (`str` or `TensorType`, *optional*):
        The type of tensors to return. Can be one of:
            - `None`: Return a list of `np.ndarray`.
            - `TensorType.TENSORFLOW` or `'tf'`: Return a batch of type `tf.Tensor`.
            - `TensorType.PYTORCH` or `'pt'`: Return a batch of type `torch.Tensor`.
            - `TensorType.NUMPY` or `'np'`: Return a batch of type `np.ndarray`.
            - `TensorType.JAX` or `'jax'`: Return a batch of type `jax.numpy.ndarray`.
    data_format (`ChannelDimension` or `str`, *optional*, defaults to `ChannelDimension.FIRST`):
        The channel dimension format for the output image. Can be one of:
            - `ChannelDimension.FIRST`: image in (num_channels, height, width) format.
            - `ChannelDimension.LAST`: image in (height, width, num_channels) format.
    input_data_format (`ChannelDimension` or `str`, *optional*):
        The channel dimension format for the input image. If unset, the channel dimension format is inferred
        from the input image. Can be one of:
        - `"channels_first"` or `ChannelDimension.FIRST`: image in (num_channels, height, width) format.
        - `"channels_last"` or `ChannelDimension.LAST`: image in (height, width, num_channels) format.
        - `"none"` or `ChannelDimension.NONE`: image in (height, width) format.
zkInvalid image type. Must be of type PIL.Image.Image, numpy.ndarray, torch.Tensor, tf.Tensor or jax.ndarray.)r"   sizer(   r   zIt looks like you are trying to rescale already rescaled images. If the input images have pixel values between 0 and 1, set `do_rescale=False` to avoid rescaling them again.)r#   r(   r3   gp?)scaler3   )input_channel_dimr    )datatensor_type)r"   r$   r#   r(   r   r   
ValueErrorr   r   r   loggerwarning_oncer   r   rescaler   r
   )r+   r;   r"   r#   r(   r$   r<   r2   r3   imgr1   rA   s               r.   
preprocessGLPNImageProcessor.preprocess   s   ^ "+!6IDNN	#-#9Zt
'3'?|TEVEV'38)&1F##:  	&	
 288#.%8/&)44s
 $ >vay I $#E Exu#  
 kqrkqbgll5K\l]kqFr ou
ntej'N_`nt 	 
 'BB5 9 s
s   :EEE#Eoutputsr   target_sizesc                 ~   [        U S5        UR                  nUb#  [        U5      [        U5      :w  a  [        S5      e/ nUc  S/[        U5      -  OUn[	        X25       HY  u  pVUb>  US   n[
        R                  R                  R                  XVSSS9nUR                  5       nUR                  SU05        M[     U$ )	aj  
Converts the raw output of [`DepthEstimatorOutput`] into final depth predictions and depth PIL images.
Only supports PyTorch.

Args:
    outputs ([`DepthEstimatorOutput`]):
        Raw outputs of the model.
    target_sizes (`TensorType` or `list[tuple[int, int]]`, *optional*):
        Tensor of shape `(batch_size, 2)` or list of tuples (`tuple[int, int]`) containing the target size
        (height, width) of each image in the batch. If left to None, predictions will not be resized.

Returns:
    `list[dict[str, TensorType]]`: A list of dictionaries of tensors representing the processed depth
    predictions.
torchNz]Make sure that you pass in as many target sizes as the batch dimension of the predicted depth)NN.bicubicF)r>   modealign_cornerspredicted_depth)r   rQ   lenrC   ziprM   nn
functionalinterpolatesqueezeappend)r+   rJ   rK   rQ   resultsdepthtarget_sizes          r.   post_process_depth_estimation0GLPNImageProcessor.post_process_depth_estimation   s    ( 	$(!11$3+?3|CT+To  8D8LvO 44R^"%o"DE&o.++77V_ot7uNN-u56 #E r0   )r$   r"   r(   r#   )N)__name__
__module____qualname____firstlineno____doc__model_input_namesr   BILINEARboolintr*   npndarrayr   r   r   strr   r   FIRSTr   listr
   rH   tupledictr\   __static_attributes____classcell__)r-   s   @r.   r   r   4   s   " (( #,,## #
 # 
# #$ (:'B'B26DH0zz0 0 %	0
 ./0 $E#/?*?$@A0 
0d %& %)&*%);?(8(>(>DH^C'T:K5LdS]N^^_^C D>^C sm	^C TN^C !z3!78^C &^C $E#/?*?$@A^C 
^C '^CF RV''' uZeCHo1F%LMN' 
d3
?#	$	' 'r0   r   ))rb   typingr   r   r   utils.import_utilsr   modeling_outputsr   numpyrg   	PIL.ImagePILimage_processing_utilsr	   r
   image_transformsr   r   image_utilsr   r   r   r   r   r   r   r   r   r   utilsr   r   r   r   rM   
get_loggerr^   rD   r   __all__r'   r0   r.   <module>r|      s    & 1 1 * 8   F C   ] \  
		H	% 
;\+ \  \~  
 r0   