
    sgp                        U d Z ddlZddlZddlZddlZddlmZ ddlmZm	Z	m
Z
mZmZ ddlmZ ddlmZmZ ddlmZmZ dd	lmZ dd
lmZmZmZmZmZmZ ddlmZ ddl m!Z!m"Z"m#Z#m$Z$  ejJ                  e&      Z'er e       Z(ee)ee
e)   e
e)   f   f   e*d<   n
 eg d      Z(e(jW                         D ]/  \  Z,Z-e-^Z.Z/ e       sdZ.e/re/d    e       sdZ/ne/d   Z/e.e/fe(e,<   1  ee!e(      Z0de)fdZ1	 	 	 	 	 	 	 ddee)ejd                  f   de
ee)ejd                  f      de3de
e3   de
e	e)e)f      de
ee3e)f      de
e)   de3fdZ4d Z5 G d d      Z6y)zAutoImageProcessor class.    N)OrderedDict)TYPE_CHECKINGDictOptionalTupleUnion   )PretrainedConfig)get_class_from_dynamic_moduleresolve_trust_remote_code)BaseImageProcessorImageProcessingMixin)BaseImageProcessorFast)CONFIG_NAMEIMAGE_PROCESSOR_NAMEget_file_from_repois_torchvision_availableis_vision_availablelogging   )_LazyAutoMapping)CONFIG_MAPPING_NAMES
AutoConfigmodel_type_to_module_name!replace_list_option_in_docstringsIMAGE_PROCESSOR_MAPPING_NAMES)c)alignEfficientNetImageProcessor)beitBeitImageProcessor)bitBitImageProcessor)blipBlipImageProcessor)zblip-2r'   )bridgetower)BridgeTowerImageProcessor)	chameleon)ChameleonImageProcessor)chinese_clip)ChineseCLIPImageProcessor)clipCLIPImageProcessor)clipsegViTImageProcessorViTImageProcessorFast)conditional_detr)ConditionalDetrImageProcessor)convnextConvNextImageProcessor)
convnextv2r9   )cvtr9   )zdata2vec-visionr!   )deformable_detr)DeformableDetrImageProcessor DeformableDetrImageProcessorFast)deit)DeiTImageProcessor)depth_anythingDPTImageProcessor)deta)DetaImageProcessor)detr)DetrImageProcessorDetrImageProcessorFast)dinatr3   )dinov2r$   )z
donut-swin)DonutImageProcessor)dptrC   )efficientformer)EfficientFormerImageProcessor)efficientnetr   )flava)FlavaImageProcessor)focalnetr$   )fuyu)FuyuImageProcessor)gitr0   )glpn)GLPNImageProcessor)zgrounding-dino)GroundingDinoImageProcessor)groupvitr0   )hierar$   )idefics)IdeficsImageProcessor)idefics2)Idefics2ImageProcessor)idefics3)Idefics3ImageProcessor)ijepar3   )imagegpt)ImageGPTImageProcessor)instructblipr'   )instructblipvideo)InstructBlipVideoImageProcessor)zkosmos-2r0   )
layoutlmv2)LayoutLMv2ImageProcessor)
layoutlmv3LayoutLMv3ImageProcessor)levit)LevitImageProcessor)llavar0   )
llava_next)LlavaNextImageProcessor)llava_next_video)LlavaNextVideoImageProcessor)llava_onevision)LlavaOnevisionImageProcessor)mask2former)Mask2FormerImageProcessor)
maskformer)MaskFormerImageProcessor)zmgp-strr3   )mllama)MllamaImageProcessor)mobilenet_v1)MobileNetV1ImageProcessor)mobilenet_v2)MobileNetV2ImageProcessor)	mobilevitMobileViTImageProcessor)mobilevitv2r   )natr3   )nougat)NougatImageProcessor)	oneformer)OneFormerImageProcessor)owlv2)Owlv2ImageProcessor)owlvit)OwlViTImageProcessor)	paligemmaSiglipImageProcessor)	perceiver)PerceiverImageProcessor)
pix2struct)Pix2StructImageProcessor)pixtral)PixtralImageProcessorPixtralImageProcessorFast)
poolformer)PoolFormerImageProcessor)pvtPvtImageProcessor)pvt_v2r   )qwen2_vl)Qwen2VLImageProcessor)regnetr9   )resnetr9   )rt_detr)RTDetrImageProcessorRTDetrImageProcessorFast)sam)SamImageProcessor)	segformerSegformerImageProcessor)seggpt)SegGptImageProcessor)siglipr   )swiftformerr3   )swinr3   )swin2sr)Swin2SRImageProcessor)swinv2r3   )ztable-transformer)rH   )timesformerVideoMAEImageProcessor)tvlt)TvltImageProcessor)tvp)TvpImageProcessor)udoprk   )upernetr   )vanr9   )videomaer   )vilt)ViltImageProcessor)vipllavar0   )vitr3   )
vit_hybrid)ViTHybridImageProcessor)vit_maer3   )vit_msnr3   )vitmatte)VitMatteImageProcessor)xclipr0   )yolos)YolosImageProcessor)zoedepth)ZoeDepthImageProcessor
class_namec                    | dk(  rt         S t        j                         D ]<  \  }}| |v st        |      }t	        j
                  d| d      }	 t        ||       c S  t        j                  j                         D ]"  \  }}|D ]  }t        |dd       | k(  s|c c S  $ t	        j
                  d      }t        ||       rt        ||       S y # t        $ r Y w xY w)Nr   .ztransformers.models__name__transformers)r   r   itemsr   	importlibimport_modulegetattrAttributeErrorIMAGE_PROCESSOR_MAPPING_extra_contenthasattr)r   module_name
extractorsmodule_	extractormain_modules          a/var/www/html/venv/lib/python3.12/site-packages/transformers/models/auto/image_processing_auto.pyimage_processor_class_from_namer      s    --%%#@#F#F#H Z#3K@K,,q->@UVFvz22 1??EEG !:# 	!Iy*d3zA  	!! )).9K{J'{J// " s   C	CCpretrained_model_name_or_path	cache_dirforce_downloadresume_downloadproxiestokenrevisionlocal_files_onlyc                 N   |j                  dd      }	|	)t        j                  dt               |t	        d      |	}t        | t        |||||||	      }
|
t        j                  d       i S t        |
d      5 }t        j                  |      cddd       S # 1 sw Y   yxY w)	a  
    Loads the image processor configuration from a pretrained model image processor configuration.

    Args:
        pretrained_model_name_or_path (`str` or `os.PathLike`):
            This can be either:

            - a string, the *model id* of a pretrained model configuration hosted inside a model repo on
              huggingface.co.
            - a path to a *directory* containing a configuration file saved using the
              [`~PreTrainedTokenizer.save_pretrained`] method, e.g., `./my_model_directory/`.

        cache_dir (`str` or `os.PathLike`, *optional*):
            Path to a directory in which a downloaded pretrained model configuration should be cached if the standard
            cache should not be used.
        force_download (`bool`, *optional*, defaults to `False`):
            Whether or not to force to (re-)download the configuration files and override the cached versions if they
            exist.
        resume_download:
            Deprecated and ignored. All downloads are now resumed by default when possible.
            Will be removed in v5 of Transformers.
        proxies (`Dict[str, str]`, *optional*):
            A dictionary of proxy servers to use by protocol or endpoint, e.g., `{'http': 'foo.bar:3128',
            'http://hostname': 'foo.bar:4012'}.` The proxies are used on each request.
        token (`str` or *bool*, *optional*):
            The token to use as HTTP bearer authorization for remote files. If `True`, will use the token generated
            when running `huggingface-cli login` (stored in `~/.huggingface`).
        revision (`str`, *optional*, defaults to `"main"`):
            The specific model version to use. It can be a branch name, a tag name, or a commit id, since we use a
            git-based system for storing models and other artifacts on huggingface.co, so `revision` can be any
            identifier allowed by git.
        local_files_only (`bool`, *optional*, defaults to `False`):
            If `True`, will only try to load the image processor configuration from local files.

    <Tip>

    Passing `token=True` is required when you want to use a private model.

    </Tip>

    Returns:
        `Dict`: The configuration of the image processor.

    Examples:

    ```python
    # Download configuration from huggingface.co and cache.
    image_processor_config = get_image_processor_config("google-bert/bert-base-uncased")
    # This model does not have a image processor config so the result will be an empty dict.
    image_processor_config = get_image_processor_config("FacebookAI/xlm-roberta-base")

    # Save a pretrained image processor locally and you can reload its config
    from transformers import AutoTokenizer

    image_processor = AutoImageProcessor.from_pretrained("google/vit-base-patch16-224-in21k")
    image_processor.save_pretrained("image-processor-test")
    image_processor_config = get_image_processor_config("image-processor-test")
    ```use_auth_tokenNrThe `use_auth_token` argument is deprecated and will be removed in v5 of Transformers. Please use `token` instead.V`token` and `use_auth_token` are both specified. Please set only the argument `token`.)r   r   r   r   r   r   r   zbCould not locate the image processor configuration file, will try to use the model config instead.zutf-8)encoding)popwarningswarnFutureWarning
ValueErrorr   r   loggerinfoopenjsonload)r   r   r   r   r   r   r   r   kwargsr   resolved_config_filereaders               r   get_image_processor_configr      s    J ZZ 0$7N! A	
 uvv-%%')
 #p	
 		"W	5 !yy ! ! !s   <BB$c                 6    t         j                  d|  d       y )NzFast image processor class zz is available for this model. Using slow image processor class. To use the fast image processor class set `use_fast=True`.)r   warning)
fast_classs    r   '_warning_fast_image_processor_availabler   .  s!    
NN
%j\ 2g 	g    c                   V    e Zd ZdZd Ze ee      d               Ze		 	 	 	 dd       Z
y)AutoImageProcessora%  
    This is a generic image processor class that will be instantiated as one of the image processor classes of the
    library when created with the [`AutoImageProcessor.from_pretrained`] class method.

    This class cannot be instantiated directly using `__init__()` (throws an error).
    c                     t        d      )NzAutoImageProcessor is designed to be instantiated using the `AutoImageProcessor.from_pretrained(pretrained_model_name_or_path)` method.)EnvironmentError)selfs    r   __init__zAutoImageProcessor.__init__=  s    d
 	
r   c                    |j                  dd      }|<t        j                  dt               |j	                  dd      t        d      ||d<   |j                  dd      }|j                  dd      }|j                  dd      }d	|d
<   t        j                  |fi |\  }}	|j	                  dd      }
d}d|j	                  di       v r|d   d   }|
V|T|j                  dd      }||j                  dd      }
d|j	                  di       v r|d   d   }|j                  dd      }|
`|^t        |t              st        j                  |fd|i|}t        |dd      }
t        |d      rd|j                  v r|j                  d   }|
>|1|r|
j!                  d      s|
dz  }
n|s|
j!                  d      r|
dd }
t#        |
      }
|du}|
duxs t%        |      t&        v }t)        ||||      }|t        |t*              s|df}|r|r|s|d   t-        |d          |r|d   |d   }n|d   }t/        ||fi |}
|j                  dd      }	t0        j2                  j5                  |      r|
j7                           |
j8                  |fi |S |
 |
j8                  |fi |S t%        |      t&        v ret&        t%        |         }|\  }}|s|t-        |       |r|s| |j                  |g|i |S | |j                  |g|i |S t        d      t        d| dt:         dt<         dt<         ddj?                  d t@        jC                         D               
      )a  
        Instantiate one of the image processor classes of the library from a pretrained model vocabulary.

        The image processor class to instantiate is selected based on the `model_type` property of the config object
        (either passed as an argument or loaded from `pretrained_model_name_or_path` if possible), or when it's
        missing, by falling back to using pattern matching on `pretrained_model_name_or_path`:

        List options

        Params:
            pretrained_model_name_or_path (`str` or `os.PathLike`):
                This can be either:

                - a string, the *model id* of a pretrained image_processor hosted inside a model repo on
                  huggingface.co.
                - a path to a *directory* containing a image processor file saved using the
                  [`~image_processing_utils.ImageProcessingMixin.save_pretrained`] method, e.g.,
                  `./my_model_directory/`.
                - a path or url to a saved image processor JSON *file*, e.g.,
                  `./my_model_directory/preprocessor_config.json`.
            cache_dir (`str` or `os.PathLike`, *optional*):
                Path to a directory in which a downloaded pretrained model image processor should be cached if the
                standard cache should not be used.
            force_download (`bool`, *optional*, defaults to `False`):
                Whether or not to force to (re-)download the image processor files and override the cached versions if
                they exist.
            resume_download:
                Deprecated and ignored. All downloads are now resumed by default when possible.
                Will be removed in v5 of Transformers.
            proxies (`Dict[str, str]`, *optional*):
                A dictionary of proxy servers to use by protocol or endpoint, e.g., `{'http': 'foo.bar:3128',
                'http://hostname': 'foo.bar:4012'}.` The proxies are used on each request.
            token (`str` or *bool*, *optional*):
                The token to use as HTTP bearer authorization for remote files. If `True`, will use the token generated
                when running `huggingface-cli login` (stored in `~/.huggingface`).
            revision (`str`, *optional*, defaults to `"main"`):
                The specific model version to use. It can be a branch name, a tag name, or a commit id, since we use a
                git-based system for storing models and other artifacts on huggingface.co, so `revision` can be any
                identifier allowed by git.
            use_fast (`bool`, *optional*, defaults to `False`):
                Use a fast torchvision-base image processor if it is supported for a given model.
                If a fast tokenizer is not available for a given model, a normal numpy-based image processor
                is returned instead.
            return_unused_kwargs (`bool`, *optional*, defaults to `False`):
                If `False`, then this function returns just the final image processor object. If `True`, then this
                functions returns a `Tuple(image_processor, unused_kwargs)` where *unused_kwargs* is a dictionary
                consisting of the key/value pairs whose keys are not image processor attributes: i.e., the part of
                `kwargs` which has not been used to update `image_processor` and is otherwise ignored.
            trust_remote_code (`bool`, *optional*, defaults to `False`):
                Whether or not to allow for custom models defined on the Hub in their own modeling files. This option
                should only be set to `True` for repositories you trust and in which you have read the code, as it will
                execute code present on the Hub on your local machine.
            kwargs (`Dict[str, Any]`, *optional*):
                The values in kwargs of any keys which are image processor attributes will be used to override the
                loaded values. Behavior concerning key/value pairs whose keys are *not* image processor attributes is
                controlled by the `return_unused_kwargs` keyword parameter.

        <Tip>

        Passing `token=True` is required when you want to use a private model.

        </Tip>

        Examples:

        ```python
        >>> from transformers import AutoImageProcessor

        >>> # Download image processor from huggingface.co and cache.
        >>> image_processor = AutoImageProcessor.from_pretrained("google/vit-base-patch16-224-in21k")

        >>> # If image processor files are in a directory (e.g. image processor was saved using *save_pretrained('./test/saved_model/')*)
        >>> # image_processor = AutoImageProcessor.from_pretrained("./test/saved_model/")
        ```r   Nr   r   r   configuse_fasttrust_remote_codeT
_from_autoimage_processor_typer  auto_mapfeature_extractor_typeFeatureExtractorImageProcessorAutoFeatureExtractorFastr   r   code_revisionzZThis image processor cannot be instantiated. Please make sure you have `Pillow` installed.z Unrecognized image processor in z2. Should have a `image_processor_type` key in its z of z3, or one of the following `model_type` keys in its z: z, c              3       K   | ]  }|  y w)N ).0cs     r   	<genexpr>z5AutoImageProcessor.from_pretrained.<locals>.<genexpr>  s     @qq@qs   )"r   r   r   r   getr   r   get_image_processor_dictreplace
isinstancer
   r   from_pretrainedr   r   r  endswithr   typer   r   tupler   r   ospathisdirregister_for_auto_class	from_dictr   r   joinr   keys)clsr   inputsr   r   r  r  r	  config_dictr   image_processor_classimage_processor_auto_mapfeature_extractor_classfeature_extractor_auto_maphas_remote_codehas_local_code	class_refimage_processor_tupleimage_processor_class_pyimage_processor_class_fasts                       r   r  z"AutoImageProcessor.from_pretrainedC  s;   Z  $4d;%MM E zz'4(4 l  -F7OHd+::j$/"JJ':DA#|-FFGdohnoQ +0F M#' ;??:r#BB'2:'>?S'T$ !(-E-M&1oo6NPT&U#&2(?(G(GHZ\l(m%%R)HH-8-DE[-\*+E+M+MN`br+s( !(-E-Mf&67#331&7  %,F4JD$Q!vz*/Cv/V+1??;O+P( ,#$9$B$B6$J)V3)!&;&D&DV&L,A#2,F)$CDY$Z!2$>.d:ed6lNe>e5<no
 $/
C[]b8c(@$'G$0 8 ; G78PQR8ST4Q7C4Q7	4Q7	$A)Mj$unt$u!

?D1Aww}}:;%==?2(22;I&II".2(22;I&II&\44$;DL$I!CX@$&@ : F78RS)x;S;[A1AAB_sbhslrss+7C3CCDaudjuntuu$t  ./L.M N11E0Fd;- X((3}Btyy@qLiLnLnLp@q7q6rt
 	
r   Nc                    |)|t        d      t        j                  dt               |}||t        d      |t	        |t
              rt        d      |t	        |t              rt        d      |=|;t	        |t
              r+|j                  |k7  rt        d|j                   d| d	      | t        j                  v rt        |    \  }}||}||}t        j                  | ||f|
       y)a)  
        Register a new image processor for this class.

        Args:
            config_class ([`PretrainedConfig`]):
                The configuration corresponding to the model to register.
            image_processor_class ([`ImageProcessingMixin`]): The image processor to register.
        NzHCannot specify both image_processor_class and slow_image_processor_classzThe image_processor_class argument is deprecated and will be removed in v4.42. Please use `slow_image_processor_class`, or `fast_image_processor_class` insteadzSYou need to specify either slow_image_processor_class or fast_image_processor_classzIYou passed a fast image processor in as the `slow_image_processor_class`.zIYou passed a slow image processor in as the `fast_image_processor_class`.zThe fast processor class you are passing has a `slow_image_processor_class` attribute that is not consistent with the slow processor class you passed (fast tokenizer has z and you passed z!. Fix one of those so they match!)exist_ok)r   r   r   r   
issubclassr   r   slow_image_processor_classr   r   register)config_classr+  r8  fast_image_processor_classr6  existing_slowexisting_fasts          r   r9  zAutoImageProcessor.register  sA     !,)5 !kllMM r *?&%-2L2Trss%1jA[]s6thii%1jA[]o6phii '2*657MN*EEIcc[-HHIIYZtYu v!!  2AAA+B<+P(M=)1-:*)1-:*((57QR]e 	) 	
r   )NNNF)r   
__module____qualname____doc__r  classmethodr   r   r  staticmethodr9  r  r   r   r  r  5  sT    
 &'DEr
 F r
h  ##'#'6
 6
r   r  )NFNNNNF)7r@  r   r   r!  r   collectionsr   typingr   r   r   r   r   configuration_utilsr
   dynamic_module_utilsr   r   image_processing_utilsr   r   image_processing_utils_fastr   utilsr   r   r   r   r   r   auto_factoryr   configuration_autor   r   r   r   
get_loggerr   r   r   str__annotations__r   
model_typeimage_processorsr8  r;  r   r   PathLikeboolr   r   r  r  r   r   <module>rS     s       	  # > > 4 \ N A  +  
		H	%  \g[h!;sE(3-RU:V4W/W#Xh$/d	
f%!P %B$G$G$I i J >N;!; %)" &)CA)F)NVnVp%)"%?%B"1KMg0h!*-i ++?A^_  < 48 &*(,(,""a!#(bkk)9#:a!c2;;./0a! a! d^	a!
 d38n%a! E$)$%a! sma! a!H{
 {
r   