






"""simple docstring"""





import unittest

import numpy as np

from transformers.testing_utils import require_torch, require_vision
from transformers.utils import is_torch_available, is_vision_available

from ...test_image_processing_common import ImageProcessingSavingTestMixin, prepare_video_inputs


if is_torch_available():
							import torch

if is_vision_available():
							from PIL import Image

							from transformers import VivitImageProcessor



class       __A		(   unittest.TestCase			):

					def __init__(			self  :      Union[str, Any]     ,		__snake_case  :      int     ,		__snake_case  :      Union[str, Any]=7     ,		__snake_case  :      Optional[int]=3     ,		__snake_case  :      Optional[Any]=1_0     ,		__snake_case  :      Dict=1_8     ,		__snake_case  :      Dict=3_0     ,		__snake_case  :      List[Any]=4_0_0     ,		__snake_case  :      Optional[Any]=True     ,		__snake_case  :      List[Any]=None     ,		__snake_case  :      Tuple=True     ,		__snake_case  :      Optional[int]=[0.5, 0.5, 0.5]     ,		__snake_case  :      Union[str, Any]=[0.5, 0.5, 0.5]     ,		__snake_case  :      Tuple=None     ,		)			->							int:
											__magic_name__:	Dict							=       size if size is not None else {"""shortest_edge""": 1_8}
											__magic_name__:	Any							=       crop_size if crop_size is not None else {"""height""": 1_8, """width""": 1_8}

											__magic_name__:	Tuple							=       parent
											__magic_name__:	Any							=       batch_size
											__magic_name__:	Optional[Any]							=       num_channels
											__magic_name__:	str							=       num_frames
											__magic_name__:	Dict							=       image_size
											__magic_name__:	Dict							=       min_resolution
											__magic_name__:	List[Any]							=       max_resolution
											__magic_name__:	Union[str, Any]							=       do_resize
											__magic_name__:	Dict							=       size
											__magic_name__:	Optional[Any]							=       do_normalize
											__magic_name__:	List[str]							=       image_mean
											__magic_name__:	Any							=       image_std
											__magic_name__:	Tuple							=       crop_size






					def   lowerCamelCase__   (			self  :      int					)			->							str:
											return {
											    "image_mean": self.image_mean,
											    "image_std": self.image_std,
											    "do_normalize": self.do_normalize,
											    "do_resize": self.do_resize,
											    "size": self.size,
											    "crop_size": self.crop_size,
											}



@require_torch
@require_vision
class       __A		(   SCREAMING_SNAKE_CASE_     ,unittest.TestCase			):
					UpperCAmelCase__								=				VivitImageProcessor if is_vision_available() else None

					def   lowerCamelCase__   (			self  :      Tuple					)			->							Any:
											__magic_name__:	Union[str, Any]							=       VivitImageProcessingTester(self					)

					@property
					def   lowerCamelCase__   (			self  :      List[Any]					)			->							int:
											return self.image_processor_tester.prepare_image_processor_dict()

					def   lowerCamelCase__   (			self  :      Optional[int]					)			->							Union[str, Any]:
											__magic_name__:	Any							=       self.image_processing_class(**self.image_processor_dict					)
											self.assertTrue(hasattr(__snake_case     ,		"""image_mean"""					)					)
											self.assertTrue(hasattr(__snake_case     ,		"""image_std"""					)					)
											self.assertTrue(hasattr(__snake_case     ,		"""do_normalize"""					)					)
											self.assertTrue(hasattr(__snake_case     ,		"""do_resize"""					)					)
											self.assertTrue(hasattr(__snake_case     ,		"""do_center_crop"""					)					)
											self.assertTrue(hasattr(__snake_case     ,		"""size"""					)					)

					def   lowerCamelCase__   (			self  :      List[Any]					)			->							Dict:
											__magic_name__:	List[str]							=       self.image_processing_class.from_dict(self.image_processor_dict					)
											self.assertEqual(image_processor.size     ,		{"""shortest_edge""": 1_8}					)
											self.assertEqual(image_processor.crop_size     ,		{"""height""": 1_8, """width""": 1_8}					)

											__magic_name__:	Dict							=       self.image_processing_class.from_dict(self.image_processor_dict     ,		size=4_2     ,		crop_size=8_4					)
											self.assertEqual(image_processor.size     ,		{"""shortest_edge""": 4_2}					)
											self.assertEqual(image_processor.crop_size     ,		{"""height""": 8_4, """width""": 8_4}					)

					def   lowerCamelCase__   (			self  :      Dict					)			->							Optional[int]:
											# Initialize image_processing
											__magic_name__:	int							=       self.image_processing_class(**self.image_processor_dict					)
											# create random PIL videos
											__magic_name__:	Optional[Any]							=       prepare_video_inputs(self.image_processor_tester     ,		equal_resolution=__snake_case					)
											for video in video_inputs:
																	self.assertIsInstance(__snake_case     ,		__snake_case					)
																	self.assertIsInstance(video[0]     ,		Image.Image					)

											# Test not batched input
											__magic_name__:	Any							=       image_processing(video_inputs[0]     ,		return_tensors="""pt"""					).pixel_values
											self.assertEqual(
											    encoded_videos.shape     ,		(
											        1,
											        self.image_processor_tester.num_frames,
											        self.image_processor_tester.num_channels,
											        self.image_processor_tester.crop_size["""height"""],
											        self.image_processor_tester.crop_size["""width"""],
											    )     ,		)

											# Test batched
											__magic_name__:	Dict							=       image_processing(__snake_case     ,		return_tensors="""pt"""					).pixel_values
											self.assertEqual(
											    encoded_videos.shape     ,		(
											        self.image_processor_tester.batch_size,
											        self.image_processor_tester.num_frames,
											        self.image_processor_tester.num_channels,
											        self.image_processor_tester.crop_size["""height"""],
											        self.image_processor_tester.crop_size["""width"""],
											    )     ,		)

					def   lowerCamelCase__   (			self  :      Tuple					)			->							str:
											# Initialize image_processing
											__magic_name__:	Dict							=       self.image_processing_class(**self.image_processor_dict					)
											# create random numpy tensors
											__magic_name__:	Optional[int]							=       prepare_video_inputs(self.image_processor_tester     ,		equal_resolution=__snake_case     ,		numpify=__snake_case					)
											for video in video_inputs:
																	self.assertIsInstance(__snake_case     ,		__snake_case					)
																	self.assertIsInstance(video[0]     ,		np.ndarray					)

											# Test not batched input
											__magic_name__:	Union[str, Any]							=       image_processing(video_inputs[0]     ,		return_tensors="""pt"""					).pixel_values
											self.assertEqual(
											    encoded_videos.shape     ,		(
											        1,
											        self.image_processor_tester.num_frames,
											        self.image_processor_tester.num_channels,
											        self.image_processor_tester.crop_size["""height"""],
											        self.image_processor_tester.crop_size["""width"""],
											    )     ,		)

											# Test batched
											__magic_name__:	Any							=       image_processing(__snake_case     ,		return_tensors="""pt"""					).pixel_values
											self.assertEqual(
											    encoded_videos.shape     ,		(
											        self.image_processor_tester.batch_size,
											        self.image_processor_tester.num_frames,
											        self.image_processor_tester.num_channels,
											        self.image_processor_tester.crop_size["""height"""],
											        self.image_processor_tester.crop_size["""width"""],
											    )     ,		)






					def   lowerCamelCase__   (			self  :      Tuple					)			->							Tuple:
											# Initialize image_processing
											__magic_name__:	Union[str, Any]							=       self.image_processing_class(**self.image_processor_dict					)
											# create random PyTorch tensors
											__magic_name__:	Optional[int]							=       prepare_video_inputs(self.image_processor_tester     ,		equal_resolution=__snake_case     ,		torchify=__snake_case					)
											for video in video_inputs:
																	self.assertIsInstance(__snake_case     ,		__snake_case					)
																	self.assertIsInstance(video[0]     ,		torch.Tensor					)

											# Test not batched input
											__magic_name__:	List[Any]							=       image_processing(video_inputs[0]     ,		return_tensors="""pt"""					).pixel_values
											self.assertEqual(
											    encoded_videos.shape     ,		(
											        1,
											        self.image_processor_tester.num_frames,
											        self.image_processor_tester.num_channels,
											        self.image_processor_tester.crop_size["""height"""],
											        self.image_processor_tester.crop_size["""width"""],
											    )     ,		)

											# Test batched
											__magic_name__:	Optional[Any]							=       image_processing(__snake_case     ,		return_tensors="""pt"""					).pixel_values
											self.assertEqual(
											    encoded_videos.shape     ,		(
											        self.image_processor_tester.batch_size,
											        self.image_processor_tester.num_frames,
											        self.image_processor_tester.num_channels,
											        self.image_processor_tester.crop_size["""height"""],
											        self.image_processor_tester.crop_size["""width"""],
											    )     ,		)











"""simple docstring"""





from collections import OrderedDict
from typing import List, Mapping

from packaging import version

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


__lowerCamelCase							=  logging.get_logger(__name__)

__lowerCamelCase							=  {
    'google/efficientnet-b7': 'https://huggingface.co/google/efficientnet-b7/resolve/main/config.json',
}



class       __A		(   SCREAMING_SNAKE_CASE_			):
					UpperCAmelCase__								=				"efficientnet"

					def __init__(			self  :      Optional[Any]     ,		__snake_case  :      int = 3     ,		__snake_case  :      int = 6_0_0     ,		__snake_case  :      float = 2.0     ,		__snake_case  :      float = 3.1     ,		__snake_case  :      int = 8     ,		__snake_case  :      List[int] = [3, 3, 5, 3, 5, 5, 3]     ,		__snake_case  :      List[int] = [3_2, 1_6, 2_4, 4_0, 8_0, 1_1_2, 1_9_2]     ,		__snake_case  :      List[int] = [1_6, 2_4, 4_0, 8_0, 1_1_2, 1_9_2, 3_2_0]     ,		__snake_case  :      List[int] = []     ,		__snake_case  :      List[int] = [1, 2, 2, 2, 1, 2, 1]     ,		__snake_case  :      List[int] = [1, 2, 2, 3, 3, 4, 1]     ,		__snake_case  :      List[int] = [1, 6, 6, 6, 6, 6, 6]     ,		__snake_case  :      float = 0.25     ,		__snake_case  :      str = "swish"     ,		__snake_case  :      int = 2_5_6_0     ,		__snake_case  :      str = "mean"     ,		__snake_case  :      float = 0.02     ,		__snake_case  :      float = 0.001     ,		__snake_case  :      float = 0.99     ,		__snake_case  :      float = 0.5     ,		__snake_case  :      float = 0.2     ,		**__snake_case  :      List[Any]     ,		)			->							List[Any]:
											super().__init__(**__snake_case					)

											__magic_name__:	str							=       num_channels
											__magic_name__:	List[str]							=       image_size
											__magic_name__:	List[str]							=       width_coefficient
											__magic_name__:	Optional[Any]							=       depth_coefficient
											__magic_name__:	Tuple							=       depth_divisor
											__magic_name__:	Dict							=       kernel_sizes
											__magic_name__:	int							=       in_channels
											__magic_name__:	str							=       out_channels
											__magic_name__:	Dict							=       depthwise_padding
											__magic_name__:	Union[str, Any]							=       strides
											__magic_name__:	Dict							=       num_block_repeats
											__magic_name__:	Tuple							=       expand_ratios
											__magic_name__:	List[str]							=       squeeze_expansion_ratio
											__magic_name__:	Any							=       hidden_act
											__magic_name__:	Tuple							=       hidden_dim
											__magic_name__:	int							=       pooling_type
											__magic_name__:	int							=       initializer_range
											__magic_name__:	List[str]							=       batch_norm_eps
											__magic_name__:	str							=       batch_norm_momentum
											__magic_name__:	List[str]							=       dropout_rate
											__magic_name__:	Dict							=       drop_connect_rate
											__magic_name__:	Optional[Any]							=       sum(__snake_case					) * 4



class       __A		(   SCREAMING_SNAKE_CASE_			):
					UpperCAmelCase__								=				version.parse("1.11"			)

					@property
					def   lowerCamelCase__   (			self  :      List[str]					)			->							Mapping[str, Mapping[int, str]]:
											return OrderedDict(
											    [
											        ("""pixel_values""", {0: """batch""", 1: """num_channels""", 2: """height""", 3: """width"""}),
											    ]					)






					@property
					def   lowerCamelCase__   (			self  :      List[Any]					)			->							float:
											return 1E-5



