




'''simple docstring'''




import collections
import inspect
import unittest

from transformers import SwinConfig
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_backbone_common import BackboneTesterMixin
from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, _config_zero_init, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
							import torch
							from torch import nn

							from transformers import SwinBackbone, SwinForImageClassification, SwinForMaskedImageModeling, SwinModel
							from transformers.models.swin.modeling_swin import SWIN_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
							from PIL import Image

							from transformers import AutoImageProcessor






class 			UpperCamelCase_   :







						"""simple docstring"""


						def __init__(   self					:				Optional[Any]							,       _lowerCamelCase					:				List[str]							,       _lowerCamelCase					:				Any=13							,       _lowerCamelCase					:				Dict=32							,       _lowerCamelCase					:				Optional[Any]=2							,       _lowerCamelCase					:				str=3							,       _lowerCamelCase					:				Union[str, Any]=16							,       _lowerCamelCase					:				List[str]=[1, 2, 1]							,       _lowerCamelCase					:				Union[str, Any]=[2, 2, 4]							,       _lowerCamelCase					:				int=2							,       _lowerCamelCase					:				int=2.0							,       _lowerCamelCase					:				Dict=True							,       _lowerCamelCase					:				Tuple=0.0							,       _lowerCamelCase					:				int=0.0							,       _lowerCamelCase					:				int=0.1							,       _lowerCamelCase					:				Optional[Any]="gelu"							,       _lowerCamelCase					:				str=False							,       _lowerCamelCase					:				Union[str, Any]=True							,       _lowerCamelCase					:				int=0.02							,       _lowerCamelCase					:				Union[str, Any]=1E-5							,       _lowerCamelCase					:				List[str]=True							,       _lowerCamelCase					:				int=None							,       _lowerCamelCase					:				List[Any]=True							,       _lowerCamelCase					:				Tuple=10							,       _lowerCamelCase					:				Dict=8							,       _lowerCamelCase					:				Optional[int]=["stage1", "stage2"]							,       _lowerCamelCase					:				Dict=[1, 2]							,       ):





											"""simple docstring"""







											A_       :   Dict       =							parent
											A_       :   str       =							batch_size
											A_       :   Union[str, Any]       =							image_size
											A_       :   int       =							patch_size
											A_       :   List[Any]       =							num_channels
											A_       :   Union[str, Any]       =							embed_dim
											A_       :   Tuple       =							depths
											A_       :   Optional[Any]       =							num_heads
											A_       :   int       =							window_size
											A_       :   Union[str, Any]       =							mlp_ratio
											A_       :   Any       =							qkv_bias
											A_       :   str       =							hidden_dropout_prob
											A_       :   Tuple       =							attention_probs_dropout_prob
											A_       :   Tuple       =							drop_path_rate
											A_       :   Any       =							hidden_act
											A_       :   Optional[Any]       =							use_absolute_embeddings
											A_       :   Dict       =							patch_norm
											A_       :   Dict       =							layer_norm_eps
											A_       :   str       =							initializer_range
											A_       :   int       =							is_training
											A_       :   Optional[int]       =							scope
											A_       :   Any       =							use_labels
											A_       :   Union[str, Any]       =							type_sequence_label_size
											A_       :   List[Any]       =							encoder_stride
											A_       :   Tuple       =							out_features
											A_       :   Tuple       =							out_indices







						def 					_a			(   self					:				List[str]			):





											"""simple docstring"""







											A_       :   int       =							floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]			)

											A_       :   Optional[Any]       =							None
											if self.use_labels:
																A_       :   List[str]       =							ids_tensor([self.batch_size]							,       self.type_sequence_label_size			)

											A_       :   Optional[int]       =							self.get_config()

											return config, pixel_values, labels







						def 					_a			(   self					:				Optional[int]			):





											"""simple docstring"""







											return SwinConfig(
											    image_size=self.image_size							,       patch_size=self.patch_size							,       num_channels=self.num_channels							,       embed_dim=self.embed_dim							,       depths=self.depths							,       num_heads=self.num_heads							,       window_size=self.window_size							,       mlp_ratio=self.mlp_ratio							,       qkv_bias=self.qkv_bias							,       hidden_dropout_prob=self.hidden_dropout_prob							,       attention_probs_dropout_prob=self.attention_probs_dropout_prob							,       drop_path_rate=self.drop_path_rate							,       hidden_act=self.hidden_act							,       use_absolute_embeddings=self.use_absolute_embeddings							,       path_norm=self.patch_norm							,       layer_norm_eps=self.layer_norm_eps							,       initializer_range=self.initializer_range							,       encoder_stride=self.encoder_stride							,       out_features=self.out_features							,       out_indices=self.out_indices							,       )







						def 					_a			(   self					:				str							,       _lowerCamelCase					:				Optional[Any]							,       _lowerCamelCase					:				Optional[int]							,       _lowerCamelCase					:				str			):





											"""simple docstring"""







											A_       :   List[Any]       =							SwinModel(config=_lowerCamelCase			)
											model.to(_lowerCamelCase			)
											model.eval()
											A_       :   Tuple       =							model(_lowerCamelCase			)

											A_       :   Union[str, Any]       =							((config.image_size // config.patch_size) ** 2) // (4 ** (len(config.depths			) - 1))
											A_       :   str       =							int(config.embed_dim * 2 ** (len(config.depths			) - 1)			)

											self.parent.assertEqual(result.last_hidden_state.shape							,       (self.batch_size, expected_seq_len, expected_dim)			)







						def 					_a			(   self					:				List[str]							,       _lowerCamelCase					:				List[str]							,       _lowerCamelCase					:				Optional[int]							,       _lowerCamelCase					:				Union[str, Any]			):





											"""simple docstring"""







											A_       :   Any       =							SwinBackbone(config=_lowerCamelCase			)
											model.to(_lowerCamelCase			)
											model.eval()
											A_       :   Dict       =							model(_lowerCamelCase			)

											# verify hidden states
											self.parent.assertEqual(len(result.feature_maps			)							,       len(config.out_features			)			)
											self.parent.assertListEqual(list(result.feature_maps[0].shape			)							,       [self.batch_size, model.channels[0], 16, 16]			)

											# verify channels
											self.parent.assertEqual(len(model.channels			)							,       len(config.out_features			)			)

											# verify backbone works with out_features=None
											A_       :   str       =							None
											A_       :   Tuple       =							SwinBackbone(config=_lowerCamelCase			)
											model.to(_lowerCamelCase			)
											model.eval()
											A_       :   Any       =							model(_lowerCamelCase			)

											# verify feature maps
											self.parent.assertEqual(len(result.feature_maps			)							,       1			)
											self.parent.assertListEqual(list(result.feature_maps[0].shape			)							,       [self.batch_size, model.channels[-1], 4, 4]			)

											# verify channels
											self.parent.assertEqual(len(model.channels			)							,       1			)







						def 					_a			(   self					:				List[Any]							,       _lowerCamelCase					:				List[Any]							,       _lowerCamelCase					:				Any							,       _lowerCamelCase					:				Union[str, Any]			):





											"""simple docstring"""







											A_       :   Any       =							SwinForMaskedImageModeling(config=_lowerCamelCase			)
											model.to(_lowerCamelCase			)
											model.eval()
											A_       :   str       =							model(_lowerCamelCase			)
											self.parent.assertEqual(
											    result.logits.shape							,       (self.batch_size, self.num_channels, self.image_size, self.image_size)			)

											# test greyscale images
											A_       :   Optional[int]       =							1
											A_       :   List[Any]       =							SwinForMaskedImageModeling(_lowerCamelCase			)
											model.to(_lowerCamelCase			)
											model.eval()

											A_       :   List[str]       =							floats_tensor([self.batch_size, 1, self.image_size, self.image_size]			)
											A_       :   List[str]       =							model(_lowerCamelCase			)
											self.parent.assertEqual(result.logits.shape							,       (self.batch_size, 1, self.image_size, self.image_size)			)







						def 					_a			(   self					:				Optional[Any]							,       _lowerCamelCase					:				int							,       _lowerCamelCase					:				Optional[Any]							,       _lowerCamelCase					:				Optional[Any]			):





											"""simple docstring"""







											A_       :   Any       =							self.type_sequence_label_size
											A_       :   Optional[Any]       =							SwinForImageClassification(_lowerCamelCase			)
											model.to(_lowerCamelCase			)
											model.eval()
											A_       :   Optional[Any]       =							model(_lowerCamelCase							,       labels=_lowerCamelCase			)
											self.parent.assertEqual(result.logits.shape							,       (self.batch_size, self.type_sequence_label_size)			)

											# test greyscale images
											A_       :   Optional[Any]       =							1
											A_       :   Optional[int]       =							SwinForImageClassification(_lowerCamelCase			)
											model.to(_lowerCamelCase			)
											model.eval()

											A_       :   str       =							floats_tensor([self.batch_size, 1, self.image_size, self.image_size]			)
											A_       :   Optional[Any]       =							model(_lowerCamelCase			)
											self.parent.assertEqual(result.logits.shape							,       (self.batch_size, self.type_sequence_label_size)			)







						def 					_a			(   self					:				Union[str, Any]			):





											"""simple docstring"""







											A_       :   Optional[int]       =							self.prepare_config_and_inputs()
											(
											    (
											    A_					
											)       ,(
											    A_					
											)       ,(
											    A_					
											)       ,					
											)       :   Dict       =							config_and_inputs
											A_       :   Tuple       =							{'''pixel_values''': pixel_values}
											return config, inputs_dict






@require_torch
class 			UpperCamelCase_   (a__,					a__,					unittest.TestCase   ):







						"""simple docstring"""


						_lowerCAmelCase			  =    (
						    (
						        SwinModel,
						        SwinBackbone,
						        SwinForImageClassification,
						        SwinForMaskedImageModeling,
						    )
						    if is_torch_available()
						    else ()
						)
						_lowerCAmelCase			  =    (
						    {'feature-extraction': SwinModel, 'image-classification': SwinForImageClassification}
						    if is_torch_available()
						    else {}
						)
						_lowerCAmelCase			  =    True

						_lowerCAmelCase			  =    False
						_lowerCAmelCase			  =    False
						_lowerCAmelCase			  =    False







						def 					_a			(   self					:				Union[str, Any]			):





											"""simple docstring"""







											A_       :   Tuple       =							SwinModelTester(self			)
											A_       :   Union[str, Any]       =							ConfigTester(self							,       config_class=_lowerCamelCase							,       embed_dim=37			)







						def 					_a			(   self					:				Optional[Any]			):





											"""simple docstring"""







											self.create_and_test_config_common_properties()
											self.config_tester.create_and_test_config_to_json_string()
											self.config_tester.create_and_test_config_to_json_file()
											self.config_tester.create_and_test_config_from_and_save_pretrained()
											self.config_tester.create_and_test_config_with_num_labels()
											self.config_tester.check_config_can_be_init_without_params()
											self.config_tester.check_config_arguments_init()







						def 					_a			(   self					:				int			):





											"""simple docstring"""







											return







						def 					_a			(   self					:				str			):





											"""simple docstring"""







											A_       :   str       =							self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_model(*_lowerCamelCase			)







						@unittest.skip(reason='''Got `CUDA error: misaligned address` with PyTorch 2.0.0.'''			)
						def 					_a			(   self					:				Union[str, Any]			):





											"""simple docstring"""







											pass







						def 					_a			(   self					:				str			):





											"""simple docstring"""







											super().test_training_gradient_checkpointing()







						def 					_a			(   self					:				str			):





											"""simple docstring"""







											A_       :   List[Any]       =							self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_backbone(*_lowerCamelCase			)







						def 					_a			(   self					:				Dict			):





											"""simple docstring"""







											A_       :   List[Any]       =							self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_for_masked_image_modeling(*_lowerCamelCase			)







						def 					_a			(   self					:				Union[str, Any]			):





											"""simple docstring"""







											A_       :   Dict       =							self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_for_image_classification(*_lowerCamelCase			)







						@unittest.skip(reason='''Swin does not use inputs_embeds'''			)
						def 					_a			(   self					:				Any			):





											"""simple docstring"""







											pass







						@unittest.skip(reason='''Swin Transformer does not use feedforward chunking'''			)
						def 					_a			(   self					:				str			):





											"""simple docstring"""







											pass







						def 					_a			(   self					:				Dict			):





											"""simple docstring"""







											A_       ,A_       :   List[str]       =							self.model_tester.prepare_config_and_inputs_for_common()

											for model_class in self.all_model_classes:
																A_       :   Dict       =							model_class(_lowerCamelCase			)
																self.assertIsInstance(model.get_input_embeddings()							,       (nn.Module)			)
																A_       :   List[Any]       =							model.get_output_embeddings()
																self.assertTrue(x is None or isinstance(_lowerCamelCase							,       nn.Linear			)			)







						def 					_a			(   self					:				Optional[int]			):





											"""simple docstring"""







											A_       ,A_       :   Union[str, Any]       =							self.model_tester.prepare_config_and_inputs_for_common()

											for model_class in self.all_model_classes:
																A_       :   Optional[Any]       =							model_class(_lowerCamelCase			)
																A_       :   int       =							inspect.signature(model.forward			)
																# signature.parameters is an OrderedDict => so arg_names order is deterministic
																A_       :   Optional[Any]       =							[*signature.parameters.keys()]

																A_       :   int       =							['''pixel_values''']
																self.assertListEqual(arg_names[:1]							,       _lowerCamelCase			)







						def 					_a			(   self					:				List[Any]			):





											"""simple docstring"""







											A_       ,A_       :   List[Any]       =							self.model_tester.prepare_config_and_inputs_for_common()
											A_       :   Optional[Any]       =							True

											for model_class in self.all_model_classes:
																A_       :   str       =							True
																A_       :   Tuple       =							False
																A_       :   int       =							True
																A_       :   Tuple       =							model_class(_lowerCamelCase			)
																model.to(_lowerCamelCase			)
																model.eval()
																with torch.no_grad():
																					A_       :   Union[str, Any]       =							model(**self._prepare_for_class(_lowerCamelCase							,       _lowerCamelCase			)			)
																A_       :   Dict       =							outputs.attentions
																A_       :   Tuple       =							len(self.model_tester.depths			)
																self.assertEqual(len(_lowerCamelCase			)							,       _lowerCamelCase			)

																# check that output_attentions also work using config
																del inputs_dict["output_attentions"]
																A_       :   Optional[Any]       =							True
																A_       :   List[Any]       =							config.window_size**2
																A_       :   int       =							model_class(_lowerCamelCase			)
																model.to(_lowerCamelCase			)
																model.eval()
																with torch.no_grad():
																					A_       :   Dict       =							model(**self._prepare_for_class(_lowerCamelCase							,       _lowerCamelCase			)			)
																A_       :   int       =							outputs.attentions
																self.assertEqual(len(_lowerCamelCase			)							,       _lowerCamelCase			)

																self.assertListEqual(
																    list(attentions[0].shape[-3:]			)							,       [self.model_tester.num_heads[0], window_size_squared, window_size_squared]							,       )
																A_       :   str       =							len(_lowerCamelCase			)

																# Check attention is always last and order is fine
																A_       :   List[Any]       =							True
																A_       :   List[Any]       =							True
																A_       :   Dict       =							model_class(_lowerCamelCase			)
																model.to(_lowerCamelCase			)
																model.eval()
																with torch.no_grad():
																					A_       :   Optional[int]       =							model(**self._prepare_for_class(_lowerCamelCase							,       _lowerCamelCase			)			)

																# also another +1 for reshaped_hidden_states
																A_       :   Dict       =							1 if model_class.__name__ == '''SwinBackbone''' else 2
																self.assertEqual(out_len + added_hidden_states							,       len(_lowerCamelCase			)			)

																A_       :   List[Any]       =							outputs.attentions

																self.assertEqual(len(_lowerCamelCase			)							,       _lowerCamelCase			)

																self.assertListEqual(
																    list(self_attentions[0].shape[-3:]			)							,       [self.model_tester.num_heads[0], window_size_squared, window_size_squared]							,       )







						def 					_a			(   self					:				Any							,       _lowerCamelCase					:				int							,       _lowerCamelCase					:				int							,       _lowerCamelCase					:				int							,       _lowerCamelCase					:				str			):





											"""simple docstring"""







											A_       :   List[Any]       =							model_class(_lowerCamelCase			)
											model.to(_lowerCamelCase			)
											model.eval()

											with torch.no_grad():
																A_       :   Dict       =							model(**self._prepare_for_class(_lowerCamelCase							,       _lowerCamelCase			)			)

											A_       :   str       =							outputs.hidden_states

											A_       :   Tuple       =							getattr(
											    self.model_tester							,       '''expected_num_hidden_layers'''							,       len(self.model_tester.depths			) + 1			)
											self.assertEqual(len(_lowerCamelCase			)							,       _lowerCamelCase			)

											# Swin has a different seq_length
											A_       :   Tuple       =							(
											    config.patch_size
											    if isinstance(config.patch_size							,       collections.abc.Iterable			)
											    else (config.patch_size, config.patch_size)
											)

											A_       :   Dict       =							(image_size[1] // patch_size[1]) * (image_size[0] // patch_size[0])

											self.assertListEqual(
											    list(hidden_states[0].shape[-2:]			)							,       [num_patches, self.model_tester.embed_dim]							,       )

											if not model_class.__name__ == "SwinBackbone":
																A_       :   Any       =							outputs.reshaped_hidden_states
																self.assertEqual(len(_lowerCamelCase			)							,       _lowerCamelCase			)

																A_       ,A_       ,A_       ,A_       :   Union[str, Any]       =							reshaped_hidden_states[0].shape
																A_       :   Tuple       =							(
																    reshaped_hidden_states[0].view(_lowerCamelCase							,       _lowerCamelCase							,       height * width			).permute(0							,       2							,       1			)
																)
																self.assertListEqual(
																    list(reshaped_hidden_states.shape[-2:]			)							,       [num_patches, self.model_tester.embed_dim]							,       )







						def 					_a			(   self					:				List[Any]			):





											"""simple docstring"""







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

											A_       :   Any       =							(
											    self.model_tester.image_size
											    if isinstance(self.model_tester.image_size							,       collections.abc.Iterable			)
											    else (self.model_tester.image_size, self.model_tester.image_size)
											)

											for model_class in self.all_model_classes:
																A_       :   List[Any]       =							True
																self.check_hidden_states_output(_lowerCamelCase							,       _lowerCamelCase							,       _lowerCamelCase							,       _lowerCamelCase			)

																# check that output_hidden_states also work using config
																del inputs_dict["output_hidden_states"]
																A_       :   Optional[int]       =							True

																self.check_hidden_states_output(_lowerCamelCase							,       _lowerCamelCase							,       _lowerCamelCase							,       _lowerCamelCase			)







						def 					_a			(   self					:				int			):





											"""simple docstring"""







											A_       ,A_       :   List[str]       =							self.model_tester.prepare_config_and_inputs_for_common()
											A_       :   List[Any]       =							3

											A_       :   Dict       =							(
											    self.model_tester.image_size
											    if isinstance(self.model_tester.image_size							,       collections.abc.Iterable			)
											    else (self.model_tester.image_size, self.model_tester.image_size)
											)
											A_       :   List[str]       =							(
											    config.patch_size
											    if isinstance(config.patch_size							,       collections.abc.Iterable			)
											    else (config.patch_size, config.patch_size)
											)

											A_       :   Optional[int]       =							image_size[0] + patch_size[0] - (image_size[0] % patch_size[0])
											A_       :   Optional[int]       =							image_size[1] + patch_size[1] - (image_size[1] % patch_size[1])

											for model_class in self.all_model_classes:
																A_       :   str       =							True
																self.check_hidden_states_output(_lowerCamelCase							,       _lowerCamelCase							,       _lowerCamelCase							,       (padded_height, padded_width)			)

																# check that output_hidden_states also work using config
																del inputs_dict["output_hidden_states"]
																A_       :   List[Any]       =							True
																self.check_hidden_states_output(_lowerCamelCase							,       _lowerCamelCase							,       _lowerCamelCase							,       (padded_height, padded_width)			)







						@slow
						def 					_a			(   self					:				str			):





											"""simple docstring"""







											for model_name in SWIN_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
																A_       :   Optional[Any]       =							SwinModel.from_pretrained(_lowerCamelCase			)
																self.assertIsNotNone(_lowerCamelCase			)







						def 					_a			(   self					:				Optional[Any]			):





											"""simple docstring"""







											A_       ,A_       :   Union[str, Any]       =							self.model_tester.prepare_config_and_inputs_for_common()

											A_       :   Tuple       =							_config_zero_init(_lowerCamelCase			)
											for model_class in self.all_model_classes:
																A_       :   str       =							model_class(config=_lowerCamelCase			)
																for name, param in model.named_parameters():
																					if "embeddings" not in name and param.requires_grad:
																										self.assertIn(
																										    ((param.data.mean() * 1E9).round() / 1E9).item()							,       [0.0, 1.0]							,       msg=f'Parameter {name} of model {model_class} seems not properly initialized'							,       )






@require_vision
@require_torch
class 			UpperCamelCase_   (unittest.TestCase   ):







						"""simple docstring"""


						@cached_property
						def 					_a			(   self					:				Optional[int]			):





											"""simple docstring"""







											return (
											    AutoImageProcessor.from_pretrained('''microsoft/swin-tiny-patch4-window7-224'''			)
											    if is_vision_available()
											    else None
											)







						@slow
						def 					_a			(   self					:				Dict			):





											"""simple docstring"""







											A_       :   int       =							SwinForImageClassification.from_pretrained('''microsoft/swin-tiny-patch4-window7-224'''			).to(_lowerCamelCase			)
											A_       :   Optional[int]       =							self.default_image_processor

											A_       :   Optional[int]       =							Image.open('''./tests/fixtures/tests_samples/COCO/000000039769.png'''			)
											A_       :   Optional[Any]       =							image_processor(images=_lowerCamelCase							,       return_tensors='''pt'''			).to(_lowerCamelCase			)

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

											# verify the logits
											A_       :   Tuple       =							torch.Size((1, 1000)			)
											self.assertEqual(outputs.logits.shape							,       _lowerCamelCase			)
											A_       :   Optional[Any]       =							torch.tensor([-0.09_48, -0.64_54, -0.09_21]			).to(_lowerCamelCase			)
											self.assertTrue(torch.allclose(outputs.logits[0, :3]							,       _lowerCamelCase							,       atol=1E-4			)			)






@require_torch
class 			UpperCamelCase_   (unittest.TestCase,					a__   ):







						"""simple docstring"""


						_lowerCAmelCase			  =    (SwinBackbone,) if is_torch_available() else ()
						_lowerCAmelCase			  =    SwinConfig







						def 					_a			(   self					:				List[Any]			):





											"""simple docstring"""







											A_       :   Any       =							SwinModelTester(self			)











"""simple docstring"""







import cva
import numpy as np

def _a (		_snake_case      ,       _snake_case      ,       _snake_case      ,       _snake_case							):







      """simple docstring"""






      try:
            return int(image[x_coordinate][y_coordinate] >= center							)
      except (IndexError, TypeError):
            return 0

def _a (		_snake_case      ,       _snake_case      ,       _snake_case							):







      """simple docstring"""






      UpperCAmelCase							=       image[x_coordinate][y_coordinate]
      UpperCAmelCase							=       [1, 2, 4, 8, 16, 32, 64, 128]

      # skip get_neighbors_pixel if center is null
      if center is None:
            return 0

      # Starting from the top right, assigning value to pixels clockwise
      UpperCAmelCase							=       [
          get_neighbors_pixel(_snake_case      ,       x_coordinate - 1      ,       y_coordinate + 1      ,       _snake_case							),
          get_neighbors_pixel(_snake_case      ,       _snake_case      ,       y_coordinate + 1      ,       _snake_case							),
          get_neighbors_pixel(_snake_case      ,       x_coordinate - 1      ,       _snake_case      ,       _snake_case							),
          get_neighbors_pixel(_snake_case      ,       x_coordinate + 1      ,       y_coordinate + 1      ,       _snake_case							),
          get_neighbors_pixel(_snake_case      ,       x_coordinate + 1      ,       _snake_case      ,       _snake_case							),
          get_neighbors_pixel(_snake_case      ,       x_coordinate + 1      ,       y_coordinate - 1      ,       _snake_case							),
          get_neighbors_pixel(_snake_case      ,       _snake_case      ,       y_coordinate - 1      ,       _snake_case							),
          get_neighbors_pixel(_snake_case      ,       x_coordinate - 1      ,       y_coordinate - 1      ,       _snake_case							),
      ]

      # Converting the binary value to decimal.
      return sum(
          binary_value * power for binary_value, power in zip(_snake_case      ,       _snake_case							)							)


if __name__ == "__main__":
  # Reading the image and converting it to grayscale.
  _UpperCamelCase     			=  cva.imread(
      """digital_image_processing/image_data/lena.jpg""", cva.IMREAD_GRAYSCALE
  )

  # Create a numpy array as the same height and width of read image
  _UpperCamelCase     			=  np.zeros((image.shape[0], image.shape[1]))

  # Iterating through the image and calculating the
  # local binary pattern value for each pixel.
  for i in range(0, image.shape[0]):
    for j in range(0, image.shape[1]):
      _UpperCamelCase     			=  local_binary_value(image, i, j)

  cva.imshow("""local binary pattern""", lbp_image)
  cva.waitKey(0)
  cva.destroyAllWindows()



