
'''simple docstring'''






import inspect
import unittest

from transformers import MobileNetVaConfig
from transformers.testing_utils import require_torch, require_vision, slow, torch_device
from transformers.utils import cached_property, is_torch_available, is_vision_available

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
					import torch

					from transformers import MobileNetVaForImageClassification, MobileNetVaModel
					from transformers.models.mobilenet_va.modeling_mobilenet_va import MOBILENET_V1_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
					from PIL import Image

					from transformers import MobileNetVaImageProcessor




class     __snake_case		(   a__):
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									lowerCamelCase					:			Dict									= self.config_class(**self.inputs_dict      )
									self.parent.assertTrue(hasattr(A,    'tf_padding'      )      )
									self.parent.assertTrue(hasattr(A,    'depth_multiplier'      )      )





class     __snake_case		:
					def __init__(     self,    A,    A=13,    A=3,    A=32,    A=0.25,    A=8,    A=True,    A=1024,    A=32,    A="relu6",    A=0.1,    A=0.02,    A=True,    A=True,    A=10,    A=None,    ):

									"""simple docstring"""


									lowerCamelCase					:			Optional[Any]									= parent
									lowerCamelCase					:			str									= batch_size
									lowerCamelCase					:			Optional[Any]									= num_channels
									lowerCamelCase					:			Union[str, Any]									= image_size
									lowerCamelCase					:			Any									= depth_multiplier
									lowerCamelCase					:			Any									= min_depth
									lowerCamelCase					:			Union[str, Any]									= tf_padding
									lowerCamelCase					:			Dict									= int(last_hidden_size * depth_multiplier      )
									lowerCamelCase					:			Optional[Any]									= output_stride
									lowerCamelCase					:			List[Any]									= hidden_act
									lowerCamelCase					:			Optional[Any]									= classifier_dropout_prob
									lowerCamelCase					:			Tuple									= use_labels
									lowerCamelCase					:			Optional[int]									= is_training
									lowerCamelCase					:			Optional[int]									= num_labels
									lowerCamelCase					:			Optional[Any]									= initializer_range
									lowerCamelCase					:			Union[str, Any]									= scope
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									lowerCamelCase					:			List[str]									= floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]      )

									lowerCamelCase					:			List[Any]									= None
									lowerCamelCase					:			Tuple									= None
									if self.use_labels:
													lowerCamelCase					:			str									= ids_tensor([self.batch_size],    self.num_labels      )
													lowerCamelCase					:			Dict									= ids_tensor([self.batch_size, self.image_size, self.image_size],    self.num_labels      )

									lowerCamelCase					:			Tuple									= self.get_config()

									return config, pixel_values, labels, pixel_labels
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									return MobileNetVaConfig(
									    num_channels=self.num_channels,    image_size=self.image_size,    depth_multiplier=self.depth_multiplier,    min_depth=self.min_depth,    tf_padding=self.tf_padding,    hidden_act=self.hidden_act,    classifier_dropout_prob=self.classifier_dropout_prob,    initializer_range=self.initializer_range,    )
					def     UpperCAmelCase_							(     self,    A,    A,    A,    A      ):

									"""simple docstring"""


									lowerCamelCase					:			Optional[Any]									= MobileNetVaModel(config=A      )
									model.to(A      )
									model.eval()
									lowerCamelCase					:			int									= model(A      )
									self.parent.assertEqual(
									    result.last_hidden_state.shape,    (
									        self.batch_size,
									        self.last_hidden_size,
									        self.image_size // self.output_stride,
									        self.image_size // self.output_stride,
									    ),    )
					def     UpperCAmelCase_							(     self,    A,    A,    A,    A      ):

									"""simple docstring"""


									lowerCamelCase					:			Any									= self.num_labels
									lowerCamelCase					:			Tuple									= MobileNetVaForImageClassification(A      )
									model.to(A      )
									model.eval()
									lowerCamelCase					:			Any									= model(A,    labels=A      )
									self.parent.assertEqual(result.logits.shape,    (self.batch_size, self.num_labels)      )




					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									lowerCamelCase					:			int									= self.prepare_config_and_inputs()
									lowerCamelCase			, lowerCamelCase			, lowerCamelCase			, lowerCamelCase					:			Tuple									= config_and_inputs
									lowerCamelCase					:			str									= {'pixel_values': pixel_values}
									return config, inputs_dict





@require_torch
class     __snake_case		(   a__    ,   a__    ,   unittest.TestCase):
					_lowerCAmelCase			     =	(MobileNetVaModel, MobileNetVaForImageClassification) if is_torch_available() else ()
					_lowerCAmelCase			     =	(
					    {'''feature-extraction''': MobileNetVaModel, '''image-classification''': MobileNetVaForImageClassification}
					    if is_torch_available()
					    else {}
					)

					_lowerCAmelCase			     =	False
					_lowerCAmelCase			     =	False
					_lowerCAmelCase			     =	False
					_lowerCAmelCase			     =	False
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									lowerCamelCase					:			Tuple									= MobileNetVaModelTester(self      )
									lowerCamelCase					:			List[str]									= MobileNetVaConfigTester(self,    config_class=A,    has_text_modality=A      )
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									self.config_tester.run_common_tests()
					@unittest.skip(reason='MobileNetV1 does not use inputs_embeds'      )
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									pass
					@unittest.skip(reason='MobileNetV1 does not support input and output embeddings'      )
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									pass
					@unittest.skip(reason='MobileNetV1 does not output attentions'      )
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									pass
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									lowerCamelCase			, lowerCamelCase					:			List[Any]									= self.model_tester.prepare_config_and_inputs_for_common()

									for model_class in self.all_model_classes:
													lowerCamelCase					:			int									= model_class(A      )
													lowerCamelCase					:			Tuple									= inspect.signature(model.forward      )
													# signature.parameters is an OrderedDict => so arg_names order is deterministic
													lowerCamelCase					:			List[str]									= [*signature.parameters.keys()]

													lowerCamelCase					:			List[Any]									= ['pixel_values']
													self.assertListEqual(arg_names[:1],    A      )
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									lowerCamelCase					:			Any									= self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_model(*A      )
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									def check_hidden_states_output(A,    A,    A      ):
													lowerCamelCase					:			Optional[int]									= model_class(A      )
													model.to(A      )
													model.eval()

													with torch.no_grad():
																	lowerCamelCase					:			Any									= model(**self._prepare_for_class(A,    A      )      )

													lowerCamelCase					:			Any									= outputs.hidden_states

													lowerCamelCase					:			Optional[Any]									= 26
													self.assertEqual(len(A      ),    A      )

									lowerCamelCase			, lowerCamelCase					:			List[Any]									= self.model_tester.prepare_config_and_inputs_for_common()

									for model_class in self.all_model_classes:
													lowerCamelCase					:			Optional[Any]									= True
													check_hidden_states_output(A,    A,    A      )

													# check that output_hidden_states also work using config
													del inputs_dict["output_hidden_states"]
													lowerCamelCase					:			Any									= True

													check_hidden_states_output(A,    A,    A      )
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									lowerCamelCase					:			Union[str, Any]									= self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_for_image_classification(*A      )




					@slow
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									for model_name in MOBILENET_V1_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
													lowerCamelCase					:			List[Any]									= MobileNetVaModel.from_pretrained(A      )
													self.assertIsNotNone(A      )





def    UpperCAmelCase							(  ):
				lowerCamelCase					:			int									= Image.open('./tests/fixtures/tests_samples/COCO/000000039769.png')
				return image




@require_torch
@require_vision
class     __snake_case		(   unittest.TestCase):
					@cached_property
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									return (
									    MobileNetVaImageProcessor.from_pretrained('google/mobilenet_v1_1.0_224'      ) if is_vision_available() else None
									)




					@slow
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									lowerCamelCase					:			Tuple									= MobileNetVaForImageClassification.from_pretrained('google/mobilenet_v1_1.0_224'      ).to(A      )

									lowerCamelCase					:			int									= self.default_image_processor
									lowerCamelCase					:			List[Any]									= prepare_img()
									lowerCamelCase					:			List[Any]									= image_processor(images=A,    return_tensors='pt'      ).to(A      )

									# forward pass
									with torch.no_grad():
													lowerCamelCase					:			Optional[Any]									= model(**A      )

									# verify the logits
									lowerCamelCase					:			Any									= torch.Size((1, 1001)      )
									self.assertEqual(outputs.logits.shape,    A      )

									lowerCamelCase					:			List[Any]									= torch.tensor([-4.1739, -1.1233, 3.1205]      ).to(A      )

									self.assertTrue(torch.allclose(outputs.logits[0, :3],    A,    atol=1e-4      )      )


'''simple docstring'''






# Imports
import numpy as np




class     __snake_case		:
					def __init__(     self,    A=None,    A=None,    A=None,    A=None,    A=None      ):

									"""simple docstring"""


									self.set_matricies(red=A,    green=A,    blue=A,    red_edge=A,    nir=A      )
					def     UpperCAmelCase_							(     self,    A=None,    A=None,    A=None,    A=None,    A=None      ):

									"""simple docstring"""


									if red is not None:
													lowerCamelCase					:			Optional[int]									= red
									if green is not None:
													lowerCamelCase					:			Optional[int]									= green
									if blue is not None:
													lowerCamelCase					:			List[str]									= blue
									if red_edge is not None:
													lowerCamelCase					:			Tuple									= red_edge
									if nir is not None:
													lowerCamelCase					:			Any									= nir
									return True
					def     UpperCAmelCase_							(     self,    A="",    A=None,    A=None,    A=None,    A=None,    A=None      ):

									"""simple docstring"""


									self.set_matricies(red=A,    green=A,    blue=A,    red_edge=A,    nir=A      )
									lowerCamelCase					:			Optional[int]									= {
									    'ARVI2': self.arvaa,
									    'CCCI': self.ccci,
									    'CVI': self.cvi,
									    'GLI': self.gli,
									    'NDVI': self.ndvi,
									    'BNDVI': self.bndvi,
									    'redEdgeNDVI': self.red_edge_ndvi,
									    'GNDVI': self.gndvi,
									    'GBNDVI': self.gbndvi,
									    'GRNDVI': self.grndvi,
									    'RBNDVI': self.rbndvi,
									    'PNDVI': self.pndvi,
									    'ATSAVI': self.atsavi,
									    'BWDRVI': self.bwdrvi,
									    'CIgreen': self.ci_green,
									    'CIrededge': self.ci_rededge,
									    'CI': self.ci,
									    'CTVI': self.ctvi,
									    'GDVI': self.gdvi,
									    'EVI': self.evi,
									    'GEMI': self.gemi,
									    'GOSAVI': self.gosavi,
									    'GSAVI': self.gsavi,
									    'Hue': self.hue,
									    'IVI': self.ivi,
									    'IPVI': self.ipvi,
									    'I': self.i,
									    'RVI': self.rvi,
									    'MRVI': self.mrvi,
									    'MSAVI': self.m_savi,
									    'NormG': self.norm_g,
									    'NormNIR': self.norm_nir,
									    'NormR': self.norm_r,
									    'NGRDI': self.ngrdi,
									    'RI': self.ri,
									    'S': self.s,
									    'IF': self._if,
									    'DVI': self.dvi,
									    'TVI': self.tvi,
									    'NDRE': self.ndre,
									}

									try:
													return funcs[index]()
									except KeyError:
													print('Index not in the list!'      )
													return False
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									return -0.18 + (1.17 * ((self.nir - self.red) / (self.nir + self.red)))
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									return ((self.nir - self.redEdge) / (self.nir + self.redEdge)) / (
									    (self.nir - self.red) / (self.nir + self.red)
									)
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									return self.nir * (self.red / (self.green**2))
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									return (2 * self.green - self.red - self.blue) / (
									    2 * self.green + self.red + self.blue
									)
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									return (self.nir - self.red) / (self.nir + self.red)
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									return (self.nir - self.blue) / (self.nir + self.blue)
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									return (self.redEdge - self.red) / (self.redEdge + self.red)
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									return (self.nir - self.green) / (self.nir + self.green)
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									return (self.nir - (self.green + self.blue)) / (
									    self.nir + (self.green + self.blue)
									)
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									return (self.nir - (self.green + self.red)) / (
									    self.nir + (self.green + self.red)
									)
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									return (self.nir - (self.blue + self.red)) / (self.nir + (self.blue + self.red))
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									return (self.nir - (self.green + self.red + self.blue)) / (
									    self.nir + (self.green + self.red + self.blue)
									)
					def     UpperCAmelCase_							(     self,    A=0.08,    A=1.22,    A=0.03      ):

									"""simple docstring"""


									return a * (
									    (self.nir - a * self.red - b)
									    / (a * self.nir + self.red - a * b + x * (1 + a**2))
									)
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									return (0.1 * self.nir - self.blue) / (0.1 * self.nir + self.blue)
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									return (self.nir / self.green) - 1
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									return (self.nir / self.redEdge) - 1
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									return (self.red - self.blue) / self.red
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									lowerCamelCase					:			Union[str, Any]									= self.ndvi()
									return ((ndvi + 0.5) / (abs(ndvi + 0.5      ))) * (abs(ndvi + 0.5      ) ** (1 / 2))
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									return self.nir - self.green
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									return 2.5 * (
									    (self.nir - self.red) / (self.nir + 6 * self.red - 7.5 * self.blue + 1)
									)
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									lowerCamelCase					:			str									= (2 * (self.nir**2 - self.red**2) + 1.5 * self.nir + 0.5 * self.red) / (
									    self.nir + self.red + 0.5
									)
									return n * (1 - 0.25 * n) - (self.red - 0.125) / (1 - self.red)
					def     UpperCAmelCase_							(     self,    A=0.16      ):

									"""simple docstring"""


									return (self.nir - self.green) / (self.nir + self.green + y)
					def     UpperCAmelCase_							(     self,    A=0.5      ):

									"""simple docstring"""


									return ((self.nir - self.green) / (self.nir + self.green + n)) * (1 + n)
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									return np.arctan(
									    ((2 * self.red - self.green - self.blue) / 30.5) * (self.green - self.blue)      )
					def     UpperCAmelCase_							(     self,    A=None,    A=None      ):

									"""simple docstring"""


									return (self.nir - b) / (a * self.red)
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									return (self.nir / ((self.nir + self.red) / 2)) * (self.ndvi() + 1)
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									return (self.red + self.green + self.blue) / 30.5
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									return self.nir / self.red
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									return (self.rvi() - 1) / (self.rvi() + 1)
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									return (
									    (2 * self.nir + 1)
									    - ((2 * self.nir + 1) ** 2 - 8 * (self.nir - self.red)) ** (1 / 2)
									) / 2
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									return self.green / (self.nir + self.red + self.green)
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									return self.nir / (self.nir + self.red + self.green)
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									return self.red / (self.nir + self.red + self.green)
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									return (self.green - self.red) / (self.green + self.red)
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									return (self.red - self.green) / (self.red + self.green)
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									lowerCamelCase					:			Optional[Any]									= np.max([np.max(self.red      ), np.max(self.green      ), np.max(self.blue      )]      )
									lowerCamelCase					:			Tuple									= np.min([np.min(self.red      ), np.min(self.green      ), np.min(self.blue      )]      )
									return (max_value - min_value) / max_value
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									return (2 * self.red - self.green - self.blue) / (self.green - self.blue)
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									return self.nir / self.red
					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									return (self.ndvi() + 0.5) ** (1 / 2)




					def     UpperCAmelCase_							(     self      ):

									"""simple docstring"""


									return (self.nir - self.redEdge) / (self.nir + self.redEdge)
