



import inspect
import unittest

import numpy as np

from tests.test_modeling_common import floats_tensor
from transformers import DetrConfig, MaskFormerConfig, SwinConfig, is_torch_available, is_vision_available
from transformers.testing_utils import require_torch, require_torch_multi_gpu, require_vision, slow, torch_device
from transformers.utils import cached_property

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
       import torch

       from transformers import MaskFormerForInstanceSegmentation, MaskFormerModel

       if is_vision_available():
              from transformers import MaskFormerImageProcessor

if is_vision_available():
       from PIL import Image



class       UpperCAmelCase__:

   '''simple docstring'''




   def __init__(						self  :			str			,				lowerCAmelCase  :			Any			,				lowerCAmelCase  :			List[str]=2			,				lowerCAmelCase  :			Optional[int]=True			,				lowerCAmelCase  :			int=False			,				lowerCAmelCase  :			Optional[int]=10			,				lowerCAmelCase  :			str=3			,				lowerCAmelCase  :			List[Any]=32 * 4			,				lowerCAmelCase  :			int=32 * 6			,				lowerCAmelCase  :			int=4			,				lowerCAmelCase  :			Tuple=32			,				)	->				int:




         """simple docstring"""

         lowercase__     =  parent
         lowercase__     =  batch_size
         lowercase__     =  is_training
         lowercase__     =  use_auxiliary_loss
         lowercase__     =  num_queries
         lowercase__     =  num_channels
         lowercase__     =  min_size
         lowercase__     =  max_size
         lowercase__     =  num_labels
         lowercase__     =  mask_feature_size


   def 			UpperCAmelCase		(						self  :			List[Any])	->				List[str]:




         """simple docstring"""

         lowercase__     =  floats_tensor([self.batch_size, self.num_channels, self.min_size, self.max_size]).to(
             lowerCAmelCase)

         lowercase__     =  torch.ones([self.batch_size, self.min_size, self.max_size]			,				device=lowerCAmelCase)

         lowercase__     =  (
             torch.rand([self.batch_size, self.num_labels, self.min_size, self.max_size]			,				device=lowerCAmelCase) > 0.5
         ).float()
         lowercase__     =  (torch.rand((self.batch_size, self.num_labels)			,				device=lowerCAmelCase) > 0.5).long()

         lowercase__     =  self.get_config()
         return config, pixel_values, pixel_mask, mask_labels, class_labels


   def 			UpperCAmelCase		(						self  :			Optional[int])	->				Any:




         """simple docstring"""

         return MaskFormerConfig.from_backbone_and_decoder_configs(
             backbone_config=SwinConfig(
                 depths=[1, 1, 1, 1]			,				)			,				decoder_config=DetrConfig(
                 decoder_ffn_dim=1_28			,				num_queries=self.num_queries			,				decoder_attention_heads=2			,				d_model=self.mask_feature_size			,				)			,				mask_feature_size=self.mask_feature_size			,				fpn_feature_size=self.mask_feature_size			,				num_channels=self.num_channels			,				num_labels=self.num_labels			,				)


   def 			UpperCAmelCase		(						self  :			int)	->				Optional[int]:




         """simple docstring"""

         lowercase__,	lowercase__,	lowercase__,	lowercase__,	lowercase__     =  self.prepare_config_and_inputs()
         lowercase__     =  {'pixel_values': pixel_values, 'pixel_mask': pixel_mask}
         return config, inputs_dict


   def 			UpperCAmelCase		(						self  :			Tuple			,				lowerCAmelCase  :			Any			,				lowerCAmelCase  :			Dict)	->				Optional[Any]:




         """simple docstring"""

         lowercase__     =  output.encoder_hidden_states
         lowercase__     =  output.pixel_decoder_hidden_states
         lowercase__     =  output.transformer_decoder_hidden_states

         self.parent.assertTrue(len(lowerCAmelCase)			,				len(config.backbone_config.depths))
         self.parent.assertTrue(len(lowerCAmelCase)			,				len(config.backbone_config.depths))
         self.parent.assertTrue(len(lowerCAmelCase)			,				config.decoder_config.decoder_layers)


   def 			UpperCAmelCase		(						self  :			Tuple			,				lowerCAmelCase  :			List[str]			,				lowerCAmelCase  :			Union[str, Any]			,				lowerCAmelCase  :			int			,				lowerCAmelCase  :			str=False)	->				str:




         """simple docstring"""

         with torch.no_grad():
               lowercase__     =  MaskFormerModel(config=lowerCAmelCase)
               model.to(lowerCAmelCase)
               model.eval()

               lowercase__     =  model(pixel_values=lowerCAmelCase			,				pixel_mask=lowerCAmelCase)
               lowercase__     =  model(lowerCAmelCase			,				output_hidden_states=lowerCAmelCase)
         # the correct shape of output.transformer_decoder_hidden_states ensure the correcteness of the
         # encoder and pixel decoder
         self.parent.assertEqual(
             output.transformer_decoder_last_hidden_state.shape			,				(self.batch_size, self.num_queries, self.mask_feature_size)			,				)
         # let's ensure the other two hidden state exists
         self.parent.assertTrue(output.pixel_decoder_last_hidden_state is not None)
         self.parent.assertTrue(output.encoder_last_hidden_state is not None)

         if output_hidden_states:
               self.check_output_hidden_state(lowerCAmelCase			,				lowerCAmelCase)



   def 			UpperCAmelCase		(						self  :			Any			,				lowerCAmelCase  :			str			,				lowerCAmelCase  :			List[str]			,				lowerCAmelCase  :			Union[str, Any]			,				lowerCAmelCase  :			List[Any]			,				lowerCAmelCase  :			List[Any])	->				List[Any]:




         """simple docstring"""

         lowercase__     =  MaskFormerForInstanceSegmentation(config=lowerCAmelCase)
         model.to(lowerCAmelCase)
         model.eval()

         def comm_check_on_output(lowerCAmelCase  :			List[Any]):
               # let's still check that all the required stuff is there
               self.parent.assertTrue(result.transformer_decoder_last_hidden_state is not None)
               self.parent.assertTrue(result.pixel_decoder_last_hidden_state is not None)
               self.parent.assertTrue(result.encoder_last_hidden_state is not None)
               # okay, now we need to check the logits shape
               # due to the encoder compression, masks have a //4 spatial size
               self.parent.assertEqual(
                   result.masks_queries_logits.shape			,				(self.batch_size, self.num_queries, self.min_size // 4, self.max_size // 4)			,				)
               # + 1 for null class
               self.parent.assertEqual(
                   result.class_queries_logits.shape			,				(self.batch_size, self.num_queries, self.num_labels + 1))

         with torch.no_grad():
               lowercase__     =  model(pixel_values=lowerCAmelCase			,				pixel_mask=lowerCAmelCase)
               lowercase__     =  model(lowerCAmelCase)

               comm_check_on_output(lowerCAmelCase)

               lowercase__     =  model(
                   pixel_values=lowerCAmelCase			,				pixel_mask=lowerCAmelCase			,				mask_labels=lowerCAmelCase			,				class_labels=lowerCAmelCase)

         comm_check_on_output(lowerCAmelCase)

         self.parent.assertTrue(result.loss is not None)
         self.parent.assertEqual(result.loss.shape			,				torch.Size([1]))



@require_torch
class       UpperCAmelCase__(							lowerCamelCase     ,							lowerCamelCase     ,							unittest.TestCase	):

   '''simple docstring'''




   A    :  Dict       				=    (MaskFormerModel, MaskFormerForInstanceSegmentation) if is_torch_available() else ()
   A    :  Dict       				=    (
       {"feature-extraction": MaskFormerModel, "image-segmentation": MaskFormerForInstanceSegmentation}
       if is_torch_available()
       else {}
   )

   A    :  Any       				=    False
   A    :  Tuple       				=    False
   A    :  Union[str, Any]       				=    False
   A    :  List[str]       				=    False


   def 			UpperCAmelCase		(						self  :			Tuple)	->				Dict:




         """simple docstring"""

         lowercase__     =  MaskFormerModelTester(self)
         lowercase__     =  ConfigTester(self			,				config_class=lowerCAmelCase			,				has_text_modality=lowerCAmelCase)


   def 			UpperCAmelCase		(						self  :			Tuple)	->				int:




         """simple docstring"""

         self.config_tester.run_common_tests()


   def 			UpperCAmelCase		(						self  :			Union[str, Any])	->				Dict:




         """simple docstring"""

         lowercase__,	lowercase__     =  self.model_tester.prepare_config_and_inputs_for_common()
         self.model_tester.create_and_check_maskformer_model(lowerCAmelCase			,				**lowerCAmelCase			,				output_hidden_states=lowerCAmelCase)


   def 			UpperCAmelCase		(						self  :			str)	->				Any:




         """simple docstring"""

         lowercase__     =  self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_maskformer_instance_segmentation_head_model(*lowerCAmelCase)


   @unittest.skip(reason='MaskFormer does not use inputs_embeds')
   def 			UpperCAmelCase		(						self  :			Tuple)	->				Tuple:




         """simple docstring"""

         pass


   @unittest.skip(reason='MaskFormer does not have a get_input_embeddings method')
   def 			UpperCAmelCase		(						self  :			str)	->				int:




         """simple docstring"""

         pass


   @unittest.skip(reason='MaskFormer is not a generative model')
   def 			UpperCAmelCase		(						self  :			Union[str, Any])	->				List[str]:




         """simple docstring"""

         pass


   @unittest.skip(reason='MaskFormer does not use token embeddings')
   def 			UpperCAmelCase		(						self  :			str)	->				Any:




         """simple docstring"""

         pass


   @require_torch_multi_gpu
   @unittest.skip(
       reason='MaskFormer has some layers using `add_module` which doesn\'t work well with `nn.DataParallel`')
   def 			UpperCAmelCase		(						self  :			Dict)	->				Tuple:




         """simple docstring"""

         pass


   @unittest.skip('Will be fixed soon by reducing the size of the model used for common tests.')
   def 			UpperCAmelCase		(						self  :			Optional[Any])	->				Union[str, Any]:




         """simple docstring"""

         pass


   def 			UpperCAmelCase		(						self  :			str)	->				Dict:




         """simple docstring"""

         lowercase__,	lowercase__     =  self.model_tester.prepare_config_and_inputs_for_common()

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

               lowercase__     =  ['pixel_values']
               self.assertListEqual(arg_names[:1]			,				lowerCAmelCase)


   @slow
   def 			UpperCAmelCase		(						self  :			str)	->				Optional[Any]:




         """simple docstring"""

         for model_name in ["facebook/maskformer-swin-small-coco"]:
               lowercase__     =  MaskFormerModel.from_pretrained(lowerCAmelCase)
               self.assertIsNotNone(lowerCAmelCase)


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




         """simple docstring"""

         lowercase__     =  (self.model_tester.min_size,) * 2
         lowercase__     =  {
             'pixel_values': torch.randn((2, 3, *size)			,				device=lowerCAmelCase),
             'mask_labels': torch.randn((2, 10, *size)			,				device=lowerCAmelCase),
             'class_labels': torch.zeros(2			,				10			,				device=lowerCAmelCase).long(),
         }

         lowercase__     =  MaskFormerForInstanceSegmentation(MaskFormerConfig()).to(lowerCAmelCase)
         lowercase__     =  model(**lowerCAmelCase)
         self.assertTrue(outputs.loss is not None)


   def 			UpperCAmelCase		(						self  :			Dict)	->				int:




         """simple docstring"""

         lowercase__,	lowercase__     =  self.model_tester.prepare_config_and_inputs_for_common()
         self.model_tester.create_and_check_maskformer_model(lowerCAmelCase			,				**lowerCAmelCase			,				output_hidden_states=lowerCAmelCase)


   def 			UpperCAmelCase		(						self  :			str)	->				List[Any]:




         """simple docstring"""

         lowercase__,	lowercase__     =  self.model_tester.prepare_config_and_inputs_for_common()

         for model_class in self.all_model_classes:
               lowercase__     =  model_class(lowerCAmelCase).to(lowerCAmelCase)
               lowercase__     =  model(**lowerCAmelCase			,				output_attentions=lowerCAmelCase)
               self.assertTrue(outputs.attentions is not None)


   def 			UpperCAmelCase		(						self  :			Union[str, Any])	->				Tuple:




         """simple docstring"""

         if not self.model_tester.is_training:
               return
         # only MaskFormerForInstanceSegmentation has the loss
         lowercase__     =  self.all_model_classes[1]
         lowercase__,	lowercase__,	lowercase__,	lowercase__,	lowercase__     =  self.model_tester.prepare_config_and_inputs()

         lowercase__     =  model_class(lowerCAmelCase)
         model.to(lowerCAmelCase)
         model.train()

         lowercase__     =  model(lowerCAmelCase			,				mask_labels=lowerCAmelCase			,				class_labels=lowerCAmelCase).loss
         loss.backward()



   def 			UpperCAmelCase		(						self  :			int)	->				List[str]:




         """simple docstring"""

         lowercase__     =  self.all_model_classes[1]
         lowercase__,	lowercase__,	lowercase__,	lowercase__,	lowercase__     =  self.model_tester.prepare_config_and_inputs()
         lowercase__     =  True
         lowercase__     =  True

         lowercase__     =  model_class(lowerCAmelCase)
         model.to(lowerCAmelCase)
         model.train()

         lowercase__     =  model(lowerCAmelCase			,				mask_labels=lowerCAmelCase			,				class_labels=lowerCAmelCase)

         lowercase__     =  outputs.encoder_hidden_states[0]
         encoder_hidden_states.retain_grad()

         lowercase__     =  outputs.pixel_decoder_hidden_states[0]
         pixel_decoder_hidden_states.retain_grad()
         # we requires_grad=True in inputs_embeds (line 2152), the original implementation don't
         lowercase__     =  outputs.transformer_decoder_hidden_states[0]
         transformer_decoder_hidden_states.retain_grad()

         lowercase__     =  outputs.attentions[0]
         attentions.retain_grad()

         outputs.loss.backward(retain_graph=lowerCAmelCase)

         self.assertIsNotNone(encoder_hidden_states.grad)
         self.assertIsNotNone(pixel_decoder_hidden_states.grad)
         self.assertIsNotNone(transformer_decoder_hidden_states.grad)
         self.assertIsNotNone(attentions.grad)
a__      :				Any   	=			1E-4

def   _lowerCAmelCase   (						):
      lowercase__     =  Image.open('./tests/fixtures/tests_samples/COCO/000000039769.png'	)
      return image



@require_vision
@slow
class       UpperCAmelCase__(							unittest.TestCase	):

   '''simple docstring'''




   @cached_property
   def 			UpperCAmelCase		(						self  :			int)	->				Any:




         """simple docstring"""

         return (
             MaskFormerImageProcessor.from_pretrained('facebook/maskformer-swin-small-coco')
             if is_vision_available()
             else None
         )


   def 			UpperCAmelCase		(						self  :			Dict)	->				Optional[int]:




         """simple docstring"""

         lowercase__     =  MaskFormerModel.from_pretrained('facebook/maskformer-swin-small-coco').to(lowerCAmelCase)
         lowercase__     =  self.default_image_processor
         lowercase__     =  prepare_img()
         lowercase__     =  image_processor(lowerCAmelCase			,				return_tensors='pt').to(lowerCAmelCase)
         lowercase__     =  inputs['pixel_values'].shape
         # check size is divisible by 32
         self.assertTrue((inputs_shape[-1] % 32) == 0 and (inputs_shape[-2] % 32) == 0)
         # check size
         self.assertEqual(lowerCAmelCase			,				(1, 3, 8_00, 10_88))

         with torch.no_grad():
               lowercase__     =  model(**lowerCAmelCase)

         lowercase__     =  torch.tensor(
             [[-0.04_82, 0.92_28, 0.49_51], [-0.25_47, 0.80_17, 0.85_27], [-0.00_69, 0.33_85, -0.00_89]]).to(lowerCAmelCase)
         self.assertTrue(
             torch.allclose(
                 outputs.encoder_last_hidden_state[0, 0, :3, :3]			,				lowerCAmelCase			,				atol=lowerCAmelCase))

         lowercase__     =  torch.tensor(
             [[-0.84_22, -0.84_34, -0.97_18], [-1.01_44, -0.55_65, -0.41_95], [-1.00_38, -0.44_84, -0.19_61]]).to(lowerCAmelCase)
         self.assertTrue(
             torch.allclose(
                 outputs.pixel_decoder_last_hidden_state[0, 0, :3, :3]			,				lowerCAmelCase			,				atol=lowerCAmelCase))

         lowercase__     =  torch.tensor(
             [[0.28_52, -0.01_59, 0.97_35], [0.62_54, 0.18_58, 0.85_29], [-0.06_80, -0.41_16, 1.84_13]]).to(lowerCAmelCase)
         self.assertTrue(
             torch.allclose(
                 outputs.transformer_decoder_last_hidden_state[0, :3, :3]			,				lowerCAmelCase			,				atol=lowerCAmelCase))


   def 			UpperCAmelCase		(						self  :			Tuple)	->				List[Any]:




         """simple docstring"""

         lowercase__     =  (
             MaskFormerForInstanceSegmentation.from_pretrained('facebook/maskformer-swin-small-coco')
             .to(lowerCAmelCase)
             .eval()
         )
         lowercase__     =  self.default_image_processor
         lowercase__     =  prepare_img()
         lowercase__     =  image_processor(lowerCAmelCase			,				return_tensors='pt').to(lowerCAmelCase)
         lowercase__     =  inputs['pixel_values'].shape
         # check size is divisible by 32
         self.assertTrue((inputs_shape[-1] % 32) == 0 and (inputs_shape[-2] % 32) == 0)
         # check size
         self.assertEqual(lowerCAmelCase			,				(1, 3, 8_00, 10_88))

         with torch.no_grad():
               lowercase__     =  model(**lowerCAmelCase)
         # masks_queries_logits
         lowercase__     =  outputs.masks_queries_logits
         self.assertEqual(
             masks_queries_logits.shape			,				(1, model.config.decoder_config.num_queries, inputs_shape[-2] // 4, inputs_shape[-1] // 4)			,				)
         lowercase__     =  [
             [-1.3_73_71_24, -1.7_72_49_37, -1.9_36_42_33],
             [-1.5_97_72_81, -1.9_86_79_39, -2.1_52_36_95],
             [-1.5_79_53_98, -1.9_26_98_32, -2.09_39_42],
         ]
         lowercase__     =  torch.tensor(lowerCAmelCase).to(lowerCAmelCase)
         self.assertTrue(torch.allclose(masks_queries_logits[0, 0, :3, :3]			,				lowerCAmelCase			,				atol=lowerCAmelCase))
         # class_queries_logits
         lowercase__     =  outputs.class_queries_logits
         self.assertEqual(
             class_queries_logits.shape			,				(1, model.config.decoder_config.num_queries, model.config.num_labels + 1))
         lowercase__     =  torch.tensor(
             [
                 [1.6_5_1_2E0_0, -5.2_5_7_2E0_0, -3.3_5_1_9E0_0],
                 [3.6_1_6_9E-0_2, -5.9_0_2_5E0_0, -2.9_3_1_3E0_0],
                 [1.0_7_6_6E-0_4, -7.7_6_3_0E0_0, -5.1_2_6_3E0_0],
             ]).to(lowerCAmelCase)
         self.assertTrue(torch.allclose(outputs.class_queries_logits[0, :3, :3]			,				lowerCAmelCase			,				atol=lowerCAmelCase))


   def 			UpperCAmelCase		(						self  :			Tuple)	->				Union[str, Any]:




         """simple docstring"""

         lowercase__     =  (
             MaskFormerForInstanceSegmentation.from_pretrained('facebook/maskformer-resnet101-coco-stuff')
             .to(lowerCAmelCase)
             .eval()
         )
         lowercase__     =  self.default_image_processor
         lowercase__     =  prepare_img()
         lowercase__     =  image_processor(lowerCAmelCase			,				return_tensors='pt').to(lowerCAmelCase)
         lowercase__     =  inputs['pixel_values'].shape
         # check size is divisible by 32
         self.assertTrue((inputs_shape[-1] % 32) == 0 and (inputs_shape[-2] % 32) == 0)
         # check size
         self.assertEqual(lowerCAmelCase			,				(1, 3, 8_00, 10_88))

         with torch.no_grad():
               lowercase__     =  model(**lowerCAmelCase)
         # masks_queries_logits
         lowercase__     =  outputs.masks_queries_logits
         self.assertEqual(
             masks_queries_logits.shape			,				(1, model.config.decoder_config.num_queries, inputs_shape[-2] // 4, inputs_shape[-1] // 4)			,				)
         lowercase__     =  [[-0.90_46, -2.63_66, -4.60_62], [-3.41_79, -5.78_90, -8.80_57], [-4.91_79, -7.65_60, -10.77_11]]
         lowercase__     =  torch.tensor(lowerCAmelCase).to(lowerCAmelCase)
         self.assertTrue(torch.allclose(masks_queries_logits[0, 0, :3, :3]			,				lowerCAmelCase			,				atol=lowerCAmelCase))
         # class_queries_logits
         lowercase__     =  outputs.class_queries_logits
         self.assertEqual(
             class_queries_logits.shape			,				(1, model.config.decoder_config.num_queries, model.config.num_labels + 1))
         lowercase__     =  torch.tensor(
             [[4.71_88, -3.25_85, -2.88_57], [6.68_71, -2.91_81, -1.24_87], [7.24_49, -2.27_64, -2.18_74]]).to(lowerCAmelCase)
         self.assertTrue(torch.allclose(outputs.class_queries_logits[0, :3, :3]			,				lowerCAmelCase			,				atol=lowerCAmelCase))



   def 			UpperCAmelCase		(						self  :			Dict)	->				Optional[int]:




         """simple docstring"""

         lowercase__     =  (
             MaskFormerForInstanceSegmentation.from_pretrained('facebook/maskformer-swin-small-coco')
             .to(lowerCAmelCase)
             .eval()
         )
         lowercase__     =  self.default_image_processor

         lowercase__     =  image_processor(
             [np.zeros((3, 8_00, 13_33)), np.zeros((3, 8_00, 13_33))]			,				segmentation_maps=[np.zeros((3_84, 3_84)).astype(np.floataa), np.zeros((3_84, 3_84)).astype(np.floataa)]			,				return_tensors='pt'			,				)

         lowercase__     =  inputs['pixel_values'].to(lowerCAmelCase)
         lowercase__     =  [el.to(lowerCAmelCase) for el in inputs['mask_labels']]
         lowercase__     =  [el.to(lowerCAmelCase) for el in inputs['class_labels']]

         with torch.no_grad():
               lowercase__     =  model(**lowerCAmelCase)

         self.assertTrue(outputs.loss is not None)





import cva
import numpy as np



class       UpperCAmelCase__:

   '''simple docstring'''




   def __init__(						self  :			Union[str, Any]			,				lowerCAmelCase  :			float			,				lowerCAmelCase  :			int)	->				Dict:




         """simple docstring"""

         if k in (0.04, 0.06):
               lowercase__     =  k
               lowercase__     =  window_size
         else:
               raise ValueError('invalid k value')


   def __str__(						self  :			Tuple)	->				str:




         """simple docstring"""

         return str(self.k)



   def 			UpperCAmelCase		(						self  :			Union[str, Any]			,				lowerCAmelCase  :			str)	->				tuple[cva.Mat, list[list[int]]]:




         """simple docstring"""

         lowercase__     =  cva.imread(lowerCAmelCase			,				0)
         lowercase__,	lowercase__     =  img.shape
         lowercase__     =  []
         lowercase__     =  img.copy()
         lowercase__     =  cva.cvtColor(lowerCAmelCase			,				cva.COLOR_GRAY2RGB)
         lowercase__,	lowercase__     =  np.gradient(lowerCAmelCase)
         lowercase__     =  dx**2
         lowercase__     =  dy**2
         lowercase__     =  dx * dy
         lowercase__     =  0.04
         lowercase__     =  self.window_size // 2
         for y in range(lowerCAmelCase			,				h - offset):
               for x in range(lowerCAmelCase			,				w - offset):
                     lowercase__     =  ixx[
                         y - offset : y + offset + 1, x - offset : x + offset + 1
                     ].sum()
                     lowercase__     =  iyy[
                         y - offset : y + offset + 1, x - offset : x + offset + 1
                     ].sum()
                     lowercase__     =  ixy[
                         y - offset : y + offset + 1, x - offset : x + offset + 1
                     ].sum()

                     lowercase__     =  (wxx * wyy) - (wxy**2)
                     lowercase__     =  wxx + wyy
                     lowercase__     =  det - k * (trace**2)
                     # Can change the value
                     if r > 0.5:
                           corner_list.append([x, y, r])
                           color_img.itemset((y, x, 0)			,				0)
                           color_img.itemset((y, x, 1)			,				0)
                           color_img.itemset((y, x, 2)			,				2_55)
         return color_img, corner_list


if __name__ == "__main__":
       a__      :				Dict   	=			HarrisCorner(0.0_4, 3)
       a__	,		a__      :				Dict   	=			edge_detect.detect("path_to_image")
       cva.imwrite("detect.png", color_img)
