

import logging
import math
from functools import partial
from typing import Any, Callable, Dict, Iterable, List, Optional, Sequence, Tuple, Union

import torch

from .tensor_utils import tensor_tree_map, tree_map






def        snake_case__		(    lowerCamelCase_		):
							A      :					List[Any]      		=					[]
							if isinstance(lowerCamelCase_     ,				lowerCamelCase_		):
														for v in tree.values():
																					shapes.extend(_fetch_dims(lowerCamelCase_		)		)
							elif isinstance(lowerCamelCase_     ,				(list, tuple)		):
														for t in tree:
																					shapes.extend(_fetch_dims(lowerCamelCase_		)		)
							elif isinstance(lowerCamelCase_     ,				torch.Tensor		):
														shapes.append(tree.shape		)
							else:
														raise ValueError('''Not supported'''		)

							return shapes






@torch.jit.ignore
def        snake_case__		(    lowerCamelCase_     ,				lowerCamelCase_		):
							A      :					Optional[int]      		=					[]
							for d in reversed(lowerCamelCase_		):
														idx.append(flat_idx % d		)
														A      :					List[Any]      		=					flat_idx // d

							return tuple(reversed(lowerCamelCase_		)		)






@torch.jit.ignore
def        snake_case__		(    lowerCamelCase_     ,				lowerCamelCase_     ,				lowerCamelCase_     ,				lowerCamelCase_ = None     ,				lowerCamelCase_ = None     ,				):

							# start_edges and end_edges both indicate whether, starting from any given
							# dimension, the start/end index is at the top/bottom edge of the
							# corresponding tensor, modeled as a tree
							def reduce_edge_list(lowerCamelCase_		) -> None:
														A      :					Dict      		=					True
														for i in range(len(lowerCamelCase_		)		):
																					A      :					Optional[Any]      		=					-1 * (i + 1)
																					l[reversed_idx] &= tally
																					A      :					int      		=					l[reversed_idx]

							if start_edges is None:
														A      :					str      		=					[s == 0 for s in start]
														reduce_edge_list(lowerCamelCase_		)
							if end_edges is None:
														A      :					Union[str, Any]      		=					[e == (d - 1) for e, d in zip(lowerCamelCase_     ,				lowerCamelCase_		)]
														reduce_edge_list(lowerCamelCase_		)

							# Base cases. Either start/end are empty and we're done, or the final,
							# one-dimensional tensor can be simply sliced
							if len(lowerCamelCase_		) == 0:
														return [()]
							elif len(lowerCamelCase_		) == 1:
														return [(slice(start[0]     ,				end[0] + 1		),)]

							A      :					List[Tuple[slice, ...]]      		=					[]
							A      :					List[slice]      		=					[]

							# Dimensions common to start and end can be selected directly
							for s, e in zip(lowerCamelCase_     ,				lowerCamelCase_		):
														if s == e:
																					path_list.append(slice(lowerCamelCase_     ,				s + 1		)		)
														else:
																					break

							A      :					Tuple[slice, ...]      		=					tuple(lowerCamelCase_		)
							A      :					List[str]      		=					len(lowerCamelCase_		)

							# start == end, and we're done
							if divergence_idx == len(lowerCamelCase_		):
														return [path]

							def upper() -> Tuple[Tuple[slice, ...], ...]:
														assert start_edges is not None
														assert end_edges is not None

														A      :					Optional[int]      		=					start[divergence_idx]
														return tuple(
														    path + (slice(lowerCamelCase_     ,				sdi + 1		),) + s
														    for s in _get_minimal_slice_set(
														        start[divergence_idx + 1 :]     ,				[d - 1 for d in dims[divergence_idx + 1 :]]     ,				dims[divergence_idx + 1 :]     ,				start_edges=start_edges[divergence_idx + 1 :]     ,				end_edges=[True for _ in end_edges[divergence_idx + 1 :]]     ,				)		)

							def lower() -> Tuple[Tuple[slice, ...], ...]:
														assert start_edges is not None
														assert end_edges is not None

														A      :					List[str]      		=					end[divergence_idx]
														return tuple(
														    path + (slice(lowerCamelCase_     ,				edi + 1		),) + s
														    for s in _get_minimal_slice_set(
														        [0 for _ in start[divergence_idx + 1 :]]     ,				end[divergence_idx + 1 :]     ,				dims[divergence_idx + 1 :]     ,				start_edges=[True for _ in start_edges[divergence_idx + 1 :]]     ,				end_edges=end_edges[divergence_idx + 1 :]     ,				)		)

							# If both start and end are at the edges of the subtree rooted at
							# divergence_idx, we can just select the whole subtree at once
							if start_edges[divergence_idx] and end_edges[divergence_idx]:
														slices.append(path + (slice(start[divergence_idx]     ,				end[divergence_idx] + 1		),)		)
							# If just start is at the edge, we can grab almost all of the subtree,
							# treating only the ragged bottom edge as an edge case
							elif start_edges[divergence_idx]:
														slices.append(path + (slice(start[divergence_idx]     ,				end[divergence_idx]		),)		)
														slices.extend(lower()		)
							# Analogous to the previous case, but the top is ragged this time
							elif end_edges[divergence_idx]:
														slices.extend(upper()		)
														slices.append(path + (slice(start[divergence_idx] + 1     ,				end[divergence_idx] + 1		),)		)
							# If both sides of the range are ragged, we need to handle both sides
							# separately. If there's contiguous meat in between them, we can index it
							# in one big chunk
							else:
														slices.extend(upper()		)
														A      :					Dict      		=					end[divergence_idx] - start[divergence_idx]
														if middle_ground > 1:
																					slices.append(path + (slice(start[divergence_idx] + 1     ,				end[divergence_idx]		),)		)
														slices.extend(lower()		)

							return slices






@torch.jit.ignore
def        snake_case__		(    lowerCamelCase_     ,				lowerCamelCase_     ,				lowerCamelCase_     ,				lowerCamelCase_		):
							A      :					Tuple      		=					t.shape[:no_batch_dims]
							A      :					Union[str, Any]      		=					list(_flat_idx_to_idx(lowerCamelCase_     ,				lowerCamelCase_		)		)
							# _get_minimal_slice_set is inclusive
							A      :					List[str]      		=					list(_flat_idx_to_idx(flat_end - 1     ,				lowerCamelCase_		)		)

							# Get an ordered list of slices to perform
							A      :					List[Any]      		=					_get_minimal_slice_set(
							    lowerCamelCase_     ,				lowerCamelCase_     ,				lowerCamelCase_     ,				)

							A      :					Any      		=					[t[s] for s in slices]

							return torch.cat([s.view((-1,) + t.shape[no_batch_dims:]		) for s in sliced_tensors]		)






def        snake_case__		(    lowerCamelCase_     ,				lowerCamelCase_     ,				lowerCamelCase_     ,				lowerCamelCase_     ,				lowerCamelCase_ = False     ,				lowerCamelCase_ = None     ,				lowerCamelCase_ = False     ,				):
							if not (len(lowerCamelCase_		) > 0):
														raise ValueError('''Must provide at least one input'''		)

							A      :					Any      		=					[shape[:no_batch_dims] for shape in _fetch_dims(lowerCamelCase_		)]
							A      :					List[Any]      		=					tuple([max(lowerCamelCase_		) for s in zip(*lowerCamelCase_		)]		)

							def _prep_inputs(lowerCamelCase_		) -> torch.Tensor:
														if not low_mem:
																					if not sum(t.shape[:no_batch_dims]		) == no_batch_dims:
																												A      :					Optional[Any]      		=					t.expand(orig_batch_dims + t.shape[no_batch_dims:]		)
																					A      :					Union[str, Any]      		=					t.reshape(-1     ,				*t.shape[no_batch_dims:]		)
														else:
																					A      :					str      		=					t.expand(orig_batch_dims + t.shape[no_batch_dims:]		)
														return t

							A      :					Dict[str, Any]      		=					tensor_tree_map(_prep_inputs     ,				lowerCamelCase_		)
							A      :					Tuple      		=					None
							if _out is not None:
														A      :					List[str]      		=					tensor_tree_map(lambda lowerCamelCase_		: t.view([-1] + list(t.shape[no_batch_dims:]		)		)     ,				_out		)

							A      :					Dict      		=					1
							for d in orig_batch_dims:
														flat_batch_dim *= d

							A      :					List[str]      		=					flat_batch_dim // chunk_size + (flat_batch_dim % chunk_size != 0)

							def _select_chunk(lowerCamelCase_		) -> torch.Tensor:
														return t[i : i + chunk_size] if t.shape[0] != 1 else t

							A      :					Optional[Any]      		=					0
							A      :					Any      		=					prepped_outputs
							for _ in range(lowerCamelCase_		):
														# Chunk the input
														if not low_mem:
																					A      :					str      		=					_select_chunk
														else:
																					A      :					int      		=					partial(
																					    _chunk_slice     ,				flat_start=lowerCamelCase_     ,				flat_end=min(lowerCamelCase_     ,				i + chunk_size		)     ,				no_batch_dims=len(lowerCamelCase_		)     ,				)

														A      :					Dict[str, Any]      		=					tensor_tree_map(lowerCamelCase_     ,				lowerCamelCase_		)

														# Run the layer on the chunk
														A      :					Optional[Any]      		=					layer(**lowerCamelCase_		)

														# Allocate space for the output
														if out is None:
																					A      :					Any      		=					tensor_tree_map(lambda lowerCamelCase_		: t.new_zeros((flat_batch_dim,) + t.shape[1:]		)     ,				lowerCamelCase_		)

														# Put the chunk in its pre-allocated space
														if isinstance(lowerCamelCase_     ,				lowerCamelCase_		):

																					def assign(lowerCamelCase_     ,				lowerCamelCase_		) -> None:
																												for k, v in da.items():
																																			if isinstance(lowerCamelCase_     ,				lowerCamelCase_		):
																																										assign(lowerCamelCase_     ,				da[k]		)
																																			else:
																																										if _add_into_out:
																																																	v[i : i + chunk_size] += da[k]
																																										else:
																																																	A      :					str      		=					da[k]

																					assign(lowerCamelCase_     ,				lowerCamelCase_		)
														elif isinstance(lowerCamelCase_     ,				lowerCamelCase_		):
																					for xa, xa in zip(lowerCamelCase_     ,				lowerCamelCase_		):
																												if _add_into_out:
																																			xa[i : i + chunk_size] += xa
																												else:
																																			A      :					Optional[int]      		=					xa
														elif isinstance(lowerCamelCase_     ,				torch.Tensor		):
																					if _add_into_out:
																												out[i : i + chunk_size] += output_chunk
																					else:
																												A      :					Union[str, Any]      		=					output_chunk
														else:
																					raise ValueError('''Not supported'''		)

														i += chunk_size

							A      :					List[str]      		=					tensor_tree_map(lambda lowerCamelCase_		: t.view(orig_batch_dims + t.shape[1:]		)     ,				lowerCamelCase_		)

							return out







class 					__lowercase  :





							"""simple docstring"""

							def __init__(					self    ,						__UpperCAmelCase = 5_12    ,						)		->       Tuple:
														A      :					Optional[Any]      		=					max_chunk_size
														A      :					Optional[int]      		=					None
														A      :					Optional[tuple]      		=					None




							def       snake_case			(					self    ,						__UpperCAmelCase    ,						__UpperCAmelCase    ,						__UpperCAmelCase						)		->       int:
														logging.info('''Tuning chunk size...'''						)

														if min_chunk_size >= self.max_chunk_size:
																					return min_chunk_size

														A      :					List[int]      		=					[2**l for l in range(int(math.log(self.max_chunk_size    ,						2						)						) + 1						)]
														A      :					str      		=					[c for c in candidates if c > min_chunk_size]
														A      :					Any      		=					[min_chunk_size] + candidates
														candidates[-1] += 4

														def test_chunk_size(__UpperCAmelCase						) -> bool:
																					try:
																												with torch.no_grad():
																																			fn(*__UpperCAmelCase    ,						chunk_size=__UpperCAmelCase						)
																												return True
																					except RuntimeError:
																												return False

														A      :					Union[str, Any]      		=					0
														A      :					int      		=					len(__UpperCAmelCase						) - 1
														while i > min_viable_chunk_size_index:
																					A      :					List[str]      		=					test_chunk_size(candidates[i]						)
																					if not viable:
																												A      :					int      		=					(min_viable_chunk_size_index + i) // 2
																					else:
																												A      :					str      		=					i
																												A      :					Union[str, Any]      		=					(i + len(__UpperCAmelCase						) - 1) // 2

														return candidates[min_viable_chunk_size_index]




							def       snake_case			(					self    ,						__UpperCAmelCase    ,						__UpperCAmelCase						)		->       bool:
														A      :					List[Any]      		=					True
														for aa, aa in zip(__UpperCAmelCase    ,						__UpperCAmelCase						):
																					assert type(__UpperCAmelCase						) == type(__UpperCAmelCase						)
																					if isinstance(__UpperCAmelCase    ,						(list, tuple)						):
																												consistent &= self._compare_arg_caches(__UpperCAmelCase    ,						__UpperCAmelCase						)
																					elif isinstance(__UpperCAmelCase    ,						__UpperCAmelCase						):
																												A      :					List[str]      		=					[v for _, v in sorted(aa.items()    ,						key=lambda __UpperCAmelCase						: x[0]						)]
																												A      :					List[str]      		=					[v for _, v in sorted(aa.items()    ,						key=lambda __UpperCAmelCase						: x[0]						)]
																												consistent &= self._compare_arg_caches(__UpperCAmelCase    ,						__UpperCAmelCase						)
																					else:
																												consistent &= aa == aa

														return consistent






							def       snake_case			(					self    ,						__UpperCAmelCase    ,						__UpperCAmelCase    ,						__UpperCAmelCase    ,						)		->       int:
														A      :					Any      		=					True
														A      :					tuple      		=					tree_map(lambda __UpperCAmelCase						: a.shape if isinstance(__UpperCAmelCase    ,						torch.Tensor						) else a    ,						__UpperCAmelCase    ,						__UpperCAmelCase						)
														if self.cached_arg_data is not None:
																					# If args have changed shape/value, we need to re-tune
																					assert len(self.cached_arg_data						) == len(__UpperCAmelCase						)
																					A      :					int      		=					self._compare_arg_caches(self.cached_arg_data    ,						__UpperCAmelCase						)
														else:
																					# Otherwise, we can reuse the precomputed value
																					A      :					Optional[int]      		=					False

														if not consistent:
																					A      :					Union[str, Any]      		=					self._determine_favorable_chunk_size(
																					    __UpperCAmelCase    ,						__UpperCAmelCase    ,						__UpperCAmelCase    ,						)
																					A      :					Optional[Any]      		=					arg_data

														assert self.cached_chunk_size is not None

														return self.cached_chunk_size









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,
)


lowercase			:				Dict   =     logging.get_logger(__name__)

lowercase			:				Dict   =     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"),
    ]
)

lowercase			:				Tuple   =     _LazyAutoMapping(CONFIG_MAPPING_NAMES, IMAGE_PROCESSOR_MAPPING_NAMES)






def        snake_case__		(    lowerCamelCase_		):
							for module_name, extractors in IMAGE_PROCESSOR_MAPPING_NAMES.items():
														if class_name in extractors:
																					A      :					Optional[Any]      		=					model_type_to_module_name(lowerCamelCase_		)

																					A      :					Optional[int]      		=					importlib.import_module(F'.{module_name}'     ,				'''transformers.models'''		)
																					try:
																												return getattr(lowerCamelCase_     ,				lowerCamelCase_		)
																					except AttributeError:
																												continue

							for _, extractor in IMAGE_PROCESSOR_MAPPING._extra_content.items():
														if getattr(lowerCamelCase_     ,				'''__name__'''     ,				lowerCamelCase_		) == 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.
							A      :					Any      		=					importlib.import_module('''transformers'''		)
							if hasattr(lowerCamelCase_     ,				lowerCamelCase_		):
														return getattr(lowerCamelCase_     ,				lowerCamelCase_		)

							return None






def        snake_case__		(    lowerCamelCase_     ,				lowerCamelCase_ = None     ,				lowerCamelCase_ = False     ,				lowerCamelCase_ = False     ,				lowerCamelCase_ = None     ,				lowerCamelCase_ = None     ,				lowerCamelCase_ = None     ,				lowerCamelCase_ = False     ,				**lowerCamelCase_     ,				):
							A      :					Optional[Any]      		=					get_file_from_repo(
							    lowerCamelCase_     ,				lowerCamelCase_     ,				cache_dir=lowerCamelCase_     ,				force_download=lowerCamelCase_     ,				resume_download=lowerCamelCase_     ,				proxies=lowerCamelCase_     ,				use_auth_token=lowerCamelCase_     ,				revision=lowerCamelCase_     ,				local_files_only=lowerCamelCase_     ,				)
							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(lowerCamelCase_     ,				encoding='''utf-8'''		) as reader:
														return json.load(lowerCamelCase_		)







class 					__lowercase  :





							"""simple docstring"""

							def __init__(					self						)		->       int:
														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       snake_case			(					cls    ,						__UpperCAmelCase    ,						**__UpperCAmelCase						)		->       Tuple:
														A      :					Tuple      		=					kwargs.pop('''config'''    ,						__UpperCAmelCase						)
														A      :					Union[str, Any]      		=					kwargs.pop('''trust_remote_code'''    ,						__UpperCAmelCase						)
														A      :					str      		=					True

														A		,		A      :					str      		=					ImageProcessingMixin.get_image_processor_dict(__UpperCAmelCase    ,						**__UpperCAmelCase						)
														A      :					List[Any]      		=					config_dict.get('''image_processor_type'''    ,						__UpperCAmelCase						)
														A      :					List[Any]      		=					None
														if "AutoImageProcessor" in config_dict.get('''auto_map'''    ,						{}						):
																					A      :					List[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:
																					A      :					List[str]      		=					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.'''						)
																												A      :					Tuple      		=					feature_extractor_class.replace('''FeatureExtractor'''    ,						'''ImageProcessor'''						)
																					if "AutoFeatureExtractor" in config_dict.get('''auto_map'''    ,						{}						):
																												A      :					Any      		=					config_dict['''auto_map''']['''AutoFeatureExtractor''']
																												A      :					int      		=					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						):
																												A      :					List[str]      		=					AutoConfig.from_pretrained(__UpperCAmelCase    ,						**__UpperCAmelCase						)
																					# It could be in `config.image_processor_type``
																					A      :					Any      		=					getattr(__UpperCAmelCase    ,						'''image_processor_type'''    ,						__UpperCAmelCase						)
																					if hasattr(__UpperCAmelCase    ,						'''auto_map'''						) and "AutoImageProcessor" in config.auto_map:
																												A      :					List[Any]      		=					config.auto_map['''AutoImageProcessor''']

														if image_processor_class is not None:
																					A      :					str      		=					image_processor_class_from_name(__UpperCAmelCase						)

														A      :					int      		=					image_processor_auto_map is not None
														A      :					List[str]      		=					image_processor_class is not None or type(__UpperCAmelCase						) in IMAGE_PROCESSOR_MAPPING
														A      :					Optional[Any]      		=					resolve_trust_remote_code(
														    __UpperCAmelCase    ,						__UpperCAmelCase    ,						__UpperCAmelCase    ,						__UpperCAmelCase						)

														if has_remote_code and trust_remote_code:
																					A      :					Tuple      		=					get_class_from_dynamic_module(
																					    __UpperCAmelCase    ,						__UpperCAmelCase    ,						**__UpperCAmelCase						)
																					A      :					Optional[Any]      		=					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:
																					A      :					Tuple      		=					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       snake_case			(					__UpperCAmelCase    ,						__UpperCAmelCase						)		->       Any:
														IMAGE_PROCESSOR_MAPPING.register(__UpperCAmelCase    ,						__UpperCAmelCase						)






