




from ...configuration_utils import PretrainedConfig
from ...utils import logging


UpperCAmelCase_						=logging.get_logger(__name__)

UpperCAmelCase_						={
    """microsoft/trocr-base-handwritten""": (
        """https://huggingface.co/microsoft/trocr-base-handwritten/resolve/main/config.json"""
    ),
    # See all TrOCR models at https://huggingface.co/models?filter=trocr
}


class 							__UpperCamelCase			( __UpperCAmelCase  ):





				'''simple docstring'''



				__a							: Any										="""trocr"""
				__a							: List[Any]										=["""past_key_values"""]
				__a							: Dict										={
				    """num_attention_heads""": """decoder_attention_heads""",
				    """hidden_size""": """d_model""",
				    """num_hidden_layers""": """decoder_layers""",
				}



				def __init__( self       , UpperCAmelCase_=5_02_65       , UpperCAmelCase_=10_24       , UpperCAmelCase_=12       , UpperCAmelCase_=16       , UpperCAmelCase_=40_96       , UpperCAmelCase_="gelu"       , UpperCAmelCase_=5_12       , UpperCAmelCase_=0.1       , UpperCAmelCase_=0.0       , UpperCAmelCase_=0.0       , UpperCAmelCase_=2       , UpperCAmelCase_=0.02       , UpperCAmelCase_=0.0       , UpperCAmelCase_=True       , UpperCAmelCase_=False       , UpperCAmelCase_=True       , UpperCAmelCase_=True       , UpperCAmelCase_=1       , UpperCAmelCase_=0       , UpperCAmelCase_=2       , **UpperCAmelCase_       , ):
											lowerCAmelCase   =		vocab_size
											lowerCAmelCase   =		d_model
											lowerCAmelCase   =		decoder_layers
											lowerCAmelCase   =		decoder_attention_heads
											lowerCAmelCase   =		decoder_ffn_dim
											lowerCAmelCase   =		activation_function
											lowerCAmelCase   =		max_position_embeddings
											lowerCAmelCase   =		dropout
											lowerCAmelCase   =		attention_dropout
											lowerCAmelCase   =		activation_dropout
											lowerCAmelCase   =		init_std
											lowerCAmelCase   =		decoder_layerdrop
											lowerCAmelCase   =		use_cache
											lowerCAmelCase   =		scale_embedding
											lowerCAmelCase   =		use_learned_position_embeddings
											lowerCAmelCase   =		layernorm_embedding

											super().__init__(
											    pad_token_id=UpperCAmelCase_       , bos_token_id=UpperCAmelCase_       , eos_token_id=UpperCAmelCase_       , decoder_start_token_id=UpperCAmelCase_       , **UpperCAmelCase_       , )









import unittest

from huggingface_hub import hf_hub_download

from transformers import MODEL_FOR_VIDEO_CLASSIFICATION_MAPPING, VideoMAEFeatureExtractor
from transformers.pipelines import VideoClassificationPipeline, pipeline
from transformers.testing_utils import (
    is_pipeline_test,
    nested_simplify,
    require_decord,
    require_tf,
    require_torch,
    require_torch_or_tf,
    require_vision,
)

from .test_pipelines_common import ANY


@is_pipeline_test
@require_torch_or_tf
@require_vision
@require_decord
class 							__UpperCamelCase			( unittest.TestCase  ):





				'''simple docstring'''



				__a							: str										=MODEL_FOR_VIDEO_CLASSIFICATION_MAPPING



				def       __snake_case		( self       , UpperCAmelCase_       , UpperCAmelCase_       , UpperCAmelCase_						):
											lowerCAmelCase   =		hf_hub_download(
											    repo_id='''nateraw/video-demo'''       , filename='''archery.mp4'''       , repo_type='''dataset'''						)
											lowerCAmelCase   =		VideoClassificationPipeline(model=UpperCAmelCase_       , image_processor=UpperCAmelCase_       , top_k=2						)
											lowerCAmelCase   =		[
											    example_video_filepath,
											    '''https://huggingface.co/datasets/nateraw/video-demo/resolve/main/archery.mp4''',
											]
											return video_classifier, examples



				def       __snake_case		( self       , UpperCAmelCase_       , UpperCAmelCase_						):
											for example in examples:
																		lowerCAmelCase   =		video_classifier(UpperCAmelCase_						)

																		self.assertEqual(
																		    UpperCAmelCase_       , [
																		        {'''score''': ANY(UpperCAmelCase_						), '''label''': ANY(UpperCAmelCase_						)},
																		        {'''score''': ANY(UpperCAmelCase_						), '''label''': ANY(UpperCAmelCase_						)},
																		    ]       , )



				@require_torch
				def       __snake_case		( self						):
											lowerCAmelCase   =		'''hf-internal-testing/tiny-random-VideoMAEForVideoClassification'''
											lowerCAmelCase   =		VideoMAEFeatureExtractor(
											    size={'''shortest_edge''': 10}       , crop_size={'''height''': 10, '''width''': 10}						)
											lowerCAmelCase   =		pipeline(
											    '''video-classification'''       , model=UpperCAmelCase_       , feature_extractor=UpperCAmelCase_       , frame_sampling_rate=4						)

											lowerCAmelCase   =		hf_hub_download(repo_id='''nateraw/video-demo'''       , filename='''archery.mp4'''       , repo_type='''dataset'''						)
											lowerCAmelCase   =		video_classifier(UpperCAmelCase_       , top_k=2						)
											self.assertEqual(
											    nested_simplify(UpperCAmelCase_       , decimals=4						)       , [{'''score''': 0.5199, '''label''': '''LABEL_0'''}, {'''score''': 0.4801, '''label''': '''LABEL_1'''}]       , )

											lowerCAmelCase   =		video_classifier(
											    [
											        video_file_path,
											        video_file_path,
											    ]       , top_k=2       , )
											self.assertEqual(
											    nested_simplify(UpperCAmelCase_       , decimals=4						)       , [
											        [{'''score''': 0.5199, '''label''': '''LABEL_0'''}, {'''score''': 0.4801, '''label''': '''LABEL_1'''}],
											        [{'''score''': 0.5199, '''label''': '''LABEL_0'''}, {'''score''': 0.4801, '''label''': '''LABEL_1'''}],
											    ]       , )






				@require_tf
				def       __snake_case		( self						):
											pass



