

"""simple docstring"""


import importlib
import json
import os
from collections import OrderedDict
from typing import Dict, Optional, Union

# Build the list of all image processors
from ...configuration_utils import PretrainedConfig
from ...dynamic_module_utils import get_class_from_dynamic_module, resolve_trust_remote_code
from ...image_processing_utils import ImageProcessingMixin
from ...utils import CONFIG_NAME, IMAGE_PROCESSOR_NAME, get_file_from_repo, logging
from .auto_factory import _LazyAutoMapping
from .configuration_auto import (
    CONFIG_MAPPING_NAMES,
    AutoConfig,
    model_type_to_module_name,
    replace_list_option_in_docstrings,
)


__A						       =      logging.get_logger(__name__)

__A						       =      OrderedDict(
    [
        ("align", "EfficientNetImageProcessor"),
        ("beit", "BeitImageProcessor"),
        ("bit", "BitImageProcessor"),
        ("blip", "BlipImageProcessor"),
        ("blip-2", "BlipImageProcessor"),
        ("bridgetower", "BridgeTowerImageProcessor"),
        ("chinese_clip", "ChineseCLIPImageProcessor"),
        ("clip", "CLIPImageProcessor"),
        ("clipseg", "ViTImageProcessor"),
        ("conditional_detr", "ConditionalDetrImageProcessor"),
        ("convnext", "ConvNextImageProcessor"),
        ("convnextv2", "ConvNextImageProcessor"),
        ("cvt", "ConvNextImageProcessor"),
        ("data2vec-vision", "BeitImageProcessor"),
        ("deformable_detr", "DeformableDetrImageProcessor"),
        ("deit", "DeiTImageProcessor"),
        ("deta", "DetaImageProcessor"),
        ("detr", "DetrImageProcessor"),
        ("dinat", "ViTImageProcessor"),
        ("donut-swin", "DonutImageProcessor"),
        ("dpt", "DPTImageProcessor"),
        ("efficientformer", "EfficientFormerImageProcessor"),
        ("efficientnet", "EfficientNetImageProcessor"),
        ("flava", "FlavaImageProcessor"),
        ("focalnet", "BitImageProcessor"),
        ("git", "CLIPImageProcessor"),
        ("glpn", "GLPNImageProcessor"),
        ("groupvit", "CLIPImageProcessor"),
        ("imagegpt", "ImageGPTImageProcessor"),
        ("instructblip", "BlipImageProcessor"),
        ("layoutlmv2", "LayoutLMv2ImageProcessor"),
        ("layoutlmv3", "LayoutLMv3ImageProcessor"),
        ("levit", "LevitImageProcessor"),
        ("mask2former", "Mask2FormerImageProcessor"),
        ("maskformer", "MaskFormerImageProcessor"),
        ("mgp-str", "ViTImageProcessor"),
        ("mobilenet_v1", "MobileNetV1ImageProcessor"),
        ("mobilenet_v2", "MobileNetV2ImageProcessor"),
        ("mobilevit", "MobileViTImageProcessor"),
        ("mobilevit", "MobileViTImageProcessor"),
        ("mobilevitv2", "MobileViTImageProcessor"),
        ("nat", "ViTImageProcessor"),
        ("oneformer", "OneFormerImageProcessor"),
        ("owlvit", "OwlViTImageProcessor"),
        ("perceiver", "PerceiverImageProcessor"),
        ("pix2struct", "Pix2StructImageProcessor"),
        ("poolformer", "PoolFormerImageProcessor"),
        ("regnet", "ConvNextImageProcessor"),
        ("resnet", "ConvNextImageProcessor"),
        ("sam", "SamImageProcessor"),
        ("segformer", "SegformerImageProcessor"),
        ("swiftformer", "ViTImageProcessor"),
        ("swin", "ViTImageProcessor"),
        ("swin2sr", "Swin2SRImageProcessor"),
        ("swinv2", "ViTImageProcessor"),
        ("table-transformer", "DetrImageProcessor"),
        ("timesformer", "VideoMAEImageProcessor"),
        ("tvlt", "TvltImageProcessor"),
        ("upernet", "SegformerImageProcessor"),
        ("van", "ConvNextImageProcessor"),
        ("videomae", "VideoMAEImageProcessor"),
        ("vilt", "ViltImageProcessor"),
        ("vit", "ViTImageProcessor"),
        ("vit_hybrid", "ViTHybridImageProcessor"),
        ("vit_mae", "ViTImageProcessor"),
        ("vit_msn", "ViTImageProcessor"),
        ("xclip", "CLIPImageProcessor"),
        ("yolos", "YolosImageProcessor"),
    ]
)

__A						       =      _LazyAutoMapping(CONFIG_MAPPING_NAMES, IMAGE_PROCESSOR_MAPPING_NAMES)






def    a__   (   __SCREAMING_SNAKE_CASE			)     ->     Tuple:
		for module_name, extractors in IMAGE_PROCESSOR_MAPPING_NAMES.items():
				if class_name in extractors:
						__lowerCAmelCase:	Any   				=      model_type_to_module_name(__SCREAMING_SNAKE_CASE			)

						__lowerCAmelCase:	Dict   				=      importlib.import_module(F".{module_name}" ,			"transformers.models"			)
						try:
								return getattr(__SCREAMING_SNAKE_CASE ,			__SCREAMING_SNAKE_CASE			)
						except AttributeError:
								continue

		for _, extractor in IMAGE_PROCESSOR_MAPPING._extra_content.items():
				if getattr(__SCREAMING_SNAKE_CASE ,			"__name__" ,			__SCREAMING_SNAKE_CASE			) == class_name:
						return extractor

    # We did not fine the class, but maybe it's because a dep is missing. In that case, the class will be in the main
    # init and we return the proper dummy to get an appropriate error message.
		__lowerCAmelCase:	str   				=      importlib.import_module("transformers"			)
		if hasattr(__SCREAMING_SNAKE_CASE ,			__SCREAMING_SNAKE_CASE			):
				return getattr(__SCREAMING_SNAKE_CASE ,			__SCREAMING_SNAKE_CASE			)

		return None






def    a__   (   __SCREAMING_SNAKE_CASE ,			__SCREAMING_SNAKE_CASE = None ,			__SCREAMING_SNAKE_CASE = False ,			__SCREAMING_SNAKE_CASE = False ,			__SCREAMING_SNAKE_CASE = None ,			__SCREAMING_SNAKE_CASE = None ,			__SCREAMING_SNAKE_CASE = None ,			__SCREAMING_SNAKE_CASE = False ,			**__SCREAMING_SNAKE_CASE ,			)     ->     Any:
		__lowerCAmelCase:	List[Any]   				=      get_file_from_repo(
		    __SCREAMING_SNAKE_CASE ,			__SCREAMING_SNAKE_CASE ,			cache_dir=__SCREAMING_SNAKE_CASE ,			force_download=__SCREAMING_SNAKE_CASE ,			resume_download=__SCREAMING_SNAKE_CASE ,			proxies=__SCREAMING_SNAKE_CASE ,			use_auth_token=__SCREAMING_SNAKE_CASE ,			revision=__SCREAMING_SNAKE_CASE ,			local_files_only=__SCREAMING_SNAKE_CASE ,			)
		if resolved_config_file is None:
				logger.info(
				    "Could not locate the image processor configuration file, will try to use the model config instead."			)
				return {}

		with open(__SCREAMING_SNAKE_CASE ,			encoding="utf-8"			) as reader:
				return json.load(__SCREAMING_SNAKE_CASE			)





class    snake_case     :

				def __init__(     self							:    List[str])->       str:



						'''simple docstring'''


						raise EnvironmentError(
						    "AutoImageProcessor is designed to be instantiated "
						    "using the `AutoImageProcessor.from_pretrained(pretrained_model_name_or_path)` method.")

				@classmethod
				@replace_list_option_in_docstrings(UpperCamelCase__)
				def 							lowercase_					(     cls							:    Tuple					,  UpperCamelCase__							:    str					,  **UpperCamelCase__							:    Optional[int])->       List[Any]:



						'''simple docstring'''


						__lowerCAmelCase:	Any   				=      kwargs.pop("config"					,  UpperCamelCase__)
						__lowerCAmelCase:	Tuple   				=      kwargs.pop("trust_remote_code"					,  UpperCamelCase__)
						__lowerCAmelCase:	List[str]   				=      True

						__lowerCAmelCase:	List[str]   				=      ImageProcessingMixin.get_image_processor_dict(UpperCamelCase__					,  **UpperCamelCase__)
						__lowerCAmelCase:	Optional[int]   				=      config_dict.get("image_processor_type"					,  UpperCamelCase__)
						__lowerCAmelCase:	int   				=      None
						if "AutoImageProcessor" in config_dict.get("auto_map"					,  {}):
								__lowerCAmelCase:	str   				=      config_dict["auto_map"]["AutoImageProcessor"]

						# If we still don't have the image processor class, check if we're loading from a previous feature extractor config
						# and if so, infer the image processor class from there.
						if image_processor_class is None and image_processor_auto_map is None:
								__lowerCAmelCase:	Dict   				=      config_dict.pop("feature_extractor_type"					,  UpperCamelCase__)
								if feature_extractor_class is not None:
										logger.warning(
										    "Could not find image processor class in the image processor config or the model config. Loading"
										    " based on pattern matching with the model's feature extractor configuration.")
										__lowerCAmelCase:	Tuple   				=      feature_extractor_class.replace("FeatureExtractor"					,  "ImageProcessor")
								if "AutoFeatureExtractor" in config_dict.get("auto_map"					,  {}):
										__lowerCAmelCase:	List[str]   				=      config_dict["auto_map"]["AutoFeatureExtractor"]
										__lowerCAmelCase:	Dict   				=      feature_extractor_auto_map.replace("FeatureExtractor"					,  "ImageProcessor")
										logger.warning(
										    "Could not find image processor auto map in the image processor config or the model config."
										    " Loading based on pattern matching with the model's feature extractor configuration.")

        # If we don't find the image processor class in the image processor config, let's try the model config.
						if image_processor_class is None and image_processor_auto_map is None:
								if not isinstance(UpperCamelCase__					,  UpperCamelCase__):
										__lowerCAmelCase:	Any   				=      AutoConfig.from_pretrained(UpperCamelCase__					,  **UpperCamelCase__)
								# It could be in `config.image_processor_type``
								__lowerCAmelCase:	str   				=      getattr(UpperCamelCase__					,  "image_processor_type"					,  UpperCamelCase__)
								if hasattr(UpperCamelCase__					,  "auto_map") and "AutoImageProcessor" in config.auto_map:
										__lowerCAmelCase:	List[str]   				=      config.auto_map["AutoImageProcessor"]

						if image_processor_class is not None:
								__lowerCAmelCase:	Tuple   				=      image_processor_class_from_name(UpperCamelCase__)

						__lowerCAmelCase:	int   				=      image_processor_auto_map is not None
						__lowerCAmelCase:	str   				=      image_processor_class is not None or type(UpperCamelCase__) in IMAGE_PROCESSOR_MAPPING
						__lowerCAmelCase:	List[str]   				=      resolve_trust_remote_code(
						    UpperCamelCase__					,  UpperCamelCase__					,  UpperCamelCase__					,  UpperCamelCase__)

						if has_remote_code and trust_remote_code:
								__lowerCAmelCase:	List[Any]   				=      get_class_from_dynamic_module(
								    UpperCamelCase__					,  UpperCamelCase__					,  **UpperCamelCase__)
								__lowerCAmelCase:	Optional[int]   				=      kwargs.pop("code_revision"					,  UpperCamelCase__)
								if os.path.isdir(UpperCamelCase__):
										image_processor_class.register_for_auto_class()
								return image_processor_class.from_dict(UpperCamelCase__					,  **UpperCamelCase__)
						elif image_processor_class is not None:
								return image_processor_class.from_dict(UpperCamelCase__					,  **UpperCamelCase__)
						# Last try: we use the IMAGE_PROCESSOR_MAPPING.
						elif type(UpperCamelCase__) in IMAGE_PROCESSOR_MAPPING:
								__lowerCAmelCase:	Dict   				=      IMAGE_PROCESSOR_MAPPING[type(UpperCamelCase__)]
								return image_processor_class.from_dict(UpperCamelCase__					,  **UpperCamelCase__)

						raise ValueError(
						    f"Unrecognized image processor in {pretrained_model_name_or_path}. Should have a "
						    f"`image_processor_type` key in its {IMAGE_PROCESSOR_NAME} of {CONFIG_NAME}, or one of the following "
						    f"`model_type` keys in its {CONFIG_NAME}: {', '.join(c for c in IMAGE_PROCESSOR_MAPPING_NAMES.keys())}")




				@staticmethod
				def 							lowercase_					(     UpperCamelCase__							:    str					,  UpperCamelCase__							:    Optional[Any])->       Any:



						'''simple docstring'''


						IMAGE_PROCESSOR_MAPPING.register(UpperCamelCase__					,  UpperCamelCase__)





"""simple docstring"""


from collections import OrderedDict
from typing import Mapping

from packaging import version

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging


__A						       =      logging.get_logger(__name__)

__A						       =      {
    "facebook/data2vec-vision-base-ft": (
        "https://huggingface.co/facebook/data2vec-vision-base-ft/resolve/main/config.json"
    ),
}





class    snake_case     (    __snake_case  ):
				SCREAMING_SNAKE_CASE_       :				Union[str, Any]       				=  """data2vec-vision"""

				def __init__(     self							:    Optional[int]					,  UpperCamelCase__							:    str=7_6_8					,  UpperCamelCase__							:    Any=1_2					,  UpperCamelCase__							:    str=1_2					,  UpperCamelCase__							:    Optional[Any]=3_0_7_2					,  UpperCamelCase__							:    Union[str, Any]="gelu"					,  UpperCamelCase__							:    List[Any]=0.0					,  UpperCamelCase__							:    Dict=0.0					,  UpperCamelCase__							:    Union[str, Any]=0.02					,  UpperCamelCase__							:    str=1e-12					,  UpperCamelCase__							:    Dict=2_2_4					,  UpperCamelCase__							:    List[Any]=1_6					,  UpperCamelCase__							:    Optional[Any]=3					,  UpperCamelCase__							:    List[str]=False					,  UpperCamelCase__							:    List[Any]=False					,  UpperCamelCase__							:    str=False					,  UpperCamelCase__							:    List[str]=False					,  UpperCamelCase__							:    int=0.1					,  UpperCamelCase__							:    List[Any]=0.1					,  UpperCamelCase__							:    Optional[Any]=True					,  UpperCamelCase__							:    List[Any]=[3, 5, 7, 1_1]					,  UpperCamelCase__							:    List[str]=[1, 2, 3, 6]					,  UpperCamelCase__							:    Union[str, Any]=True					,  UpperCamelCase__							:    Any=0.4					,  UpperCamelCase__							:    Union[str, Any]=2_5_6					,  UpperCamelCase__							:    List[Any]=1					,  UpperCamelCase__							:    str=False					,  UpperCamelCase__							:    Optional[int]=2_5_5					,  **UpperCamelCase__							:    Dict					,  )->       List[str]:



						'''simple docstring'''


						super().__init__(**UpperCamelCase__)

						__lowerCAmelCase:	List[str]   				=      hidden_size
						__lowerCAmelCase:	Union[str, Any]   				=      num_hidden_layers
						__lowerCAmelCase:	Dict   				=      num_attention_heads
						__lowerCAmelCase:	Optional[int]   				=      intermediate_size
						__lowerCAmelCase:	int   				=      hidden_act
						__lowerCAmelCase:	Union[str, Any]   				=      hidden_dropout_prob
						__lowerCAmelCase:	Any   				=      attention_probs_dropout_prob
						__lowerCAmelCase:	Dict   				=      initializer_range
						__lowerCAmelCase:	Any   				=      layer_norm_eps

						__lowerCAmelCase:	Union[str, Any]   				=      image_size
						__lowerCAmelCase:	Tuple   				=      patch_size
						__lowerCAmelCase:	List[str]   				=      num_channels
						__lowerCAmelCase:	Optional[Any]   				=      use_mask_token
						__lowerCAmelCase:	str   				=      use_absolute_position_embeddings
						__lowerCAmelCase:	Optional[int]   				=      use_relative_position_bias
						__lowerCAmelCase:	str   				=      use_shared_relative_position_bias
						__lowerCAmelCase:	Union[str, Any]   				=      layer_scale_init_value
						__lowerCAmelCase:	Any   				=      drop_path_rate
						__lowerCAmelCase:	Dict   				=      use_mean_pooling
						# decode head attributes (semantic segmentation)
						__lowerCAmelCase:	int   				=      out_indices
						__lowerCAmelCase:	Any   				=      pool_scales
						# auxiliary head attributes (semantic segmentation)
						__lowerCAmelCase:	List[Any]   				=      use_auxiliary_head
						__lowerCAmelCase:	int   				=      auxiliary_loss_weight
						__lowerCAmelCase:	Dict   				=      auxiliary_channels
						__lowerCAmelCase:	Any   				=      auxiliary_num_convs
						__lowerCAmelCase:	Any   				=      auxiliary_concat_input
						__lowerCAmelCase:	Any   				=      semantic_loss_ignore_index





class    snake_case     (    __snake_case  ):
				SCREAMING_SNAKE_CASE_       :				Dict       				=  version.parse("""1.11"""  )

				@property
				def 							lowercase_					(     self							:    Optional[Any])->       Mapping[str, Mapping[int, str]]:



						'''simple docstring'''


						return OrderedDict(
						    [
						        ("pixel_values", {0: "batch", 1: "num_channels", 2: "height", 3: "width"}),
						    ])




				@property
				def 							lowercase_					(     self							:    Any)->       float:



						'''simple docstring'''


						return 1e-4


