




"""simple docstring"""



import warnings
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


SCREAMING_SNAKE_CASE    =	logging.get_logger(__name__)

SCREAMING_SNAKE_CASE    =	{
    "nvidia/segformer-b0-finetuned-ade-512-512": (
        "https://huggingface.co/nvidia/segformer-b0-finetuned-ade-512-512/resolve/main/config.json"
    ),
    # See all SegFormer models at https://huggingface.co/models?filter=segformer
}




class      UpperCAmelCase_  (						lowerCamelCase__							):
    lowercase__						 =				"""segformer"""




    def __init__(   self						:	Optional[Any]     ,			snake_case_						:	Dict=3     ,			snake_case_						:	Union[str, Any]=4     ,			snake_case_						:	Dict=[2, 2, 2, 2]     ,			snake_case_						:	str=[8, 4, 2, 1]     ,			snake_case_						:	Tuple=[32, 64, 160, 256]     ,			snake_case_						:	List[Any]=[7, 3, 3, 3]     ,			snake_case_						:	int=[4, 2, 2, 2]     ,			snake_case_						:	Any=[1, 2, 5, 8]     ,			snake_case_						:	Optional[Any]=[4, 4, 4, 4]     ,			snake_case_						:	List[Any]="gelu"     ,			snake_case_						:	Any=0.0     ,			snake_case_						:	Any=0.0     ,			snake_case_						:	Any=0.1     ,			snake_case_						:	Union[str, Any]=0.02     ,			snake_case_						:	List[Any]=0.1     ,			snake_case_						:	List[Any]=1e-6     ,			snake_case_						:	Union[str, Any]=256     ,			snake_case_						:	Dict=255     ,			**snake_case_						:	List[str]     ,			)				->							Dict:




     '''simple docstring'''

     super().__init__(**snake_case__				)

     if "reshape_last_stage" in kwargs and kwargs["reshape_last_stage"] is False:
      warnings.warn(
          "Reshape_last_stage is set to False in this config. This argument is deprecated and will soon be"
          " removed, as the behaviour will default to that of reshape_last_stage = True."     ,			snake_case__     ,			)

     A__	=    num_channels
     A__	=    num_encoder_blocks
     A__	=    depths
     A__	=    sr_ratios
     A__	=    hidden_sizes
     A__	=    patch_sizes
     A__	=    strides
     A__	=    mlp_ratios
     A__	=    num_attention_heads
     A__	=    hidden_act
     A__	=    hidden_dropout_prob
     A__	=    attention_probs_dropout_prob
     A__	=    classifier_dropout_prob
     A__	=    initializer_range
     A__	=    drop_path_rate
     A__	=    layer_norm_eps
     A__	=    decoder_hidden_size
     A__	=    kwargs.get("reshape_last_stage"     ,			snake_case__				)
     A__	=    semantic_loss_ignore_index






class      UpperCAmelCase_  (						lowerCamelCase__							):
    lowercase__						 =				version.parse('''1.11'''							)




    @property
    def 							__magic_name__							(   self						:	Tuple				)				->							Mapping[str, Mapping[int, str]]:




     '''simple docstring'''

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




    @property
    def 							__magic_name__							(   self						:	str				)				->							float:




     '''simple docstring'''

     return 1e-4




    @property
    def 							__magic_name__							(   self						:	List[str]				)				->							int:




     '''simple docstring'''

     return 12











"""simple docstring"""



import shutil
import tempfile
import unittest

import numpy as np
import pytest

from transformers import is_speech_available, is_vision_available
from transformers.testing_utils import require_torch


if is_vision_available():
      from transformers import TvltImageProcessor

if is_speech_available():
      from transformers import TvltFeatureExtractor

from transformers import TvltProcessor




@require_torch
class      UpperCAmelCase_  (						unittest.TestCase							):




    def 							__magic_name__							(   self						:	str				)				->							Dict:




     '''simple docstring'''

     A__	=    "ZinengTang/tvlt-base"
     A__	=    tempfile.mkdtemp()




    def 							__magic_name__							(   self						:	int     ,			**snake_case_						:	Dict				)				->							Union[str, Any]:




     '''simple docstring'''

     return TvltImageProcessor.from_pretrained(self.checkpoint     ,			**snake_case_				)




    def 							__magic_name__							(   self						:	Optional[int]     ,			**snake_case_						:	str				)				->							List[str]:




     '''simple docstring'''

     return TvltFeatureExtractor.from_pretrained(self.checkpoint     ,			**snake_case_				)




    def 							__magic_name__							(   self						:	Optional[int]				)				->							str:




     '''simple docstring'''

     shutil.rmtree(self.tmpdirname				)




    def 							__magic_name__							(   self						:	Tuple				)				->							Any:




     '''simple docstring'''

     A__	=    self.get_image_processor()
     A__	=    self.get_feature_extractor()

     A__	=    TvltProcessor(image_processor=snake_case_     ,			feature_extractor=snake_case_				)
     processor.save_pretrained(self.tmpdirname				)
     A__	=    TvltProcessor.from_pretrained(self.tmpdirname				)

     self.assertIsInstance(processor.feature_extractor     ,			snake_case_				)
     self.assertIsInstance(processor.image_processor     ,			snake_case_				)




    def 							__magic_name__							(   self						:	Optional[Any]				)				->							Union[str, Any]:




     '''simple docstring'''

     A__	=    self.get_image_processor()
     A__	=    self.get_feature_extractor()

     A__	=    TvltProcessor(image_processor=snake_case_     ,			feature_extractor=snake_case_				)

     A__	=    np.ones([12_000]				)

     A__	=    feature_extractor(snake_case_     ,			return_tensors="np"				)
     A__	=    processor(audio=snake_case_     ,			return_tensors="np"				)

     for key in audio_dict.keys():
      self.assertAlmostEqual(audio_dict[key].sum()     ,			input_processor[key].sum()     ,			delta=1e-2				)




    def 							__magic_name__							(   self						:	Tuple				)				->							Tuple:




     '''simple docstring'''

     A__	=    self.get_image_processor()
     A__	=    self.get_feature_extractor()

     A__	=    TvltProcessor(image_processor=snake_case_     ,			feature_extractor=snake_case_				)

     A__	=    np.ones([3, 224, 224]				)

     A__	=    image_processor(snake_case_     ,			return_tensors="np"				)
     A__	=    processor(images=snake_case_     ,			return_tensors="np"				)

     for key in image_dict.keys():
      self.assertAlmostEqual(image_dict[key].sum()     ,			input_processor[key].sum()     ,			delta=1e-2				)




    def 							__magic_name__							(   self						:	Tuple				)				->							Optional[int]:




     '''simple docstring'''

     A__	=    self.get_image_processor()
     A__	=    self.get_feature_extractor()

     A__	=    TvltProcessor(image_processor=snake_case_     ,			feature_extractor=snake_case_				)

     A__	=    np.ones([12_000]				)
     A__	=    np.ones([3, 224, 224]				)

     A__	=    processor(audio=snake_case_     ,			images=snake_case_				)

     self.assertListEqual(list(inputs.keys()				)     ,			["audio_values", "audio_mask", "pixel_values", "pixel_mask"]				)

     # test if it raises when no input is passed
     with pytest.raises(snake_case_				):
      processor()




    def 							__magic_name__							(   self						:	Optional[Any]				)				->							Tuple:




     '''simple docstring'''

     A__	=    self.get_image_processor()
     A__	=    self.get_feature_extractor()

     A__	=    TvltProcessor(image_processor=snake_case_     ,			feature_extractor=snake_case_				)

     self.assertListEqual(
         processor.model_input_names     ,			image_processor.model_input_names + feature_extractor.model_input_names     ,			msg="`processor` and `image_processor`+`feature_extractor` model input names do not match"     ,			)





