
'''simple docstring'''




import shutil
import tempfile
import unittest

import numpy as np

from transformers.testing_utils import (
    is_pt_tf_cross_test,
    require_tf,
    require_torch,
    require_torchvision,
    require_vision,
)
from transformers.utils import is_tf_available, is_torch_available, is_vision_available


if is_vision_available():
      from PIL import Image

      from transformers import AutoProcessor, SamImageProcessor, SamProcessor

if is_torch_available():
      import torch

if is_tf_available():
      import tensorflow as tf





@require_vision
@require_torchvision
class  A				(							unittest.TestCase						):





     def 				__lowerCAmelCase							(							self	) ->				int:






         """simple docstring"""






         A       :   Optional[Any]					=						tempfile.mkdtemp()
         A       :   List[str]					=						SamImageProcessor()
         A       :   Dict					=						SamProcessor(SCREAMING_SNAKE_CASE	)
         processor.save_pretrained(self.tmpdirname	)





     def 				__lowerCAmelCase							(							self						,			**SCREAMING_SNAKE_CASE	) ->				Tuple:






         """simple docstring"""






         return AutoProcessor.from_pretrained(self.tmpdirname						,			**SCREAMING_SNAKE_CASE	).image_processor





     def 				__lowerCAmelCase							(							self	) ->				Any:






         """simple docstring"""






         shutil.rmtree(self.tmpdirname	)





     def 				__lowerCAmelCase							(							self	) ->				str:






         """simple docstring"""






         A       :   str					=						[np.random.randint(255						,			size=(3, 30, 400)						,			dtype=np.uinta	)]

         A       :   List[str]					=						[Image.fromarray(np.moveaxis(SCREAMING_SNAKE_CASE						,			0						,			-1	)	) for x in image_inputs]

         return image_inputs





     def 				__lowerCAmelCase							(							self	) ->				int:






         """simple docstring"""






         A       :   Optional[int]					=						SamProcessor(image_processor=self.get_image_processor()	)
         processor.save_pretrained(self.tmpdirname	)

         A       :   Any					=						self.get_image_processor(do_normalize=SCREAMING_SNAKE_CASE						,			padding_value=1.0	)

         A       :   Optional[Any]					=						SamProcessor.from_pretrained(self.tmpdirname						,			do_normalize=SCREAMING_SNAKE_CASE						,			padding_value=1.0	)

         self.assertEqual(processor.image_processor.to_json_string()						,			image_processor_add_kwargs.to_json_string()	)
         self.assertIsInstance(processor.image_processor						,			SCREAMING_SNAKE_CASE	)





     def 				__lowerCAmelCase							(							self	) ->				int:






         """simple docstring"""






         A       :   Optional[int]					=						self.get_image_processor()

         A       :   List[Any]					=						SamProcessor(image_processor=SCREAMING_SNAKE_CASE	)

         A       :   List[Any]					=						self.prepare_image_inputs()

         A       :   List[Any]					=						image_processor(SCREAMING_SNAKE_CASE						,			return_tensors='''np'''	)
         A       :   Tuple					=						processor(images=SCREAMING_SNAKE_CASE						,			return_tensors='''np'''	)

         input_feat_extract.pop('''original_sizes'''	)  # pop original_sizes as it is popped in the processor
         input_feat_extract.pop('''reshaped_input_sizes'''	)  # pop original_sizes as it is popped in the processor

         for key in input_feat_extract.keys():
             self.assertAlmostEqual(input_feat_extract[key].sum()						,			input_processor[key].sum()						,			delta=1e-2	)





     @require_torch
     def 				__lowerCAmelCase							(							self	) ->				Optional[Any]:






         """simple docstring"""






         A       :   Optional[int]					=						self.get_image_processor()

         A       :   List[Any]					=						SamProcessor(image_processor=SCREAMING_SNAKE_CASE	)
         A       :   Tuple					=						[torch.ones((1, 3, 5, 5)	)]

         A       :   int					=						[[1764, 2646]]

         A       :   Tuple					=						[[683, 1024]]
         A       :   Optional[int]					=						processor.post_process_masks(SCREAMING_SNAKE_CASE						,			SCREAMING_SNAKE_CASE						,			SCREAMING_SNAKE_CASE	)
         self.assertEqual(masks[0].shape						,			(1, 3, 1764, 2646)	)

         A       :   List[str]					=						processor.post_process_masks(
             SCREAMING_SNAKE_CASE						,			torch.tensor(SCREAMING_SNAKE_CASE	)						,			torch.tensor(SCREAMING_SNAKE_CASE	)	)
         self.assertEqual(masks[0].shape						,			(1, 3, 1764, 2646)	)

         # should also work with np
         A       :   Union[str, Any]					=						[np.ones((1, 3, 5, 5)	)]
         A       :   str					=						processor.post_process_masks(SCREAMING_SNAKE_CASE						,			np.array(SCREAMING_SNAKE_CASE	)						,			np.array(SCREAMING_SNAKE_CASE	)	)

         self.assertEqual(masks[0].shape						,			(1, 3, 1764, 2646)	)

         A       :   Tuple					=						[[1, 0], [0, 1]]
         with self.assertRaises(SCREAMING_SNAKE_CASE	):
             A       :   Optional[Any]					=						processor.post_process_masks(SCREAMING_SNAKE_CASE						,			np.array(SCREAMING_SNAKE_CASE	)						,			np.array(SCREAMING_SNAKE_CASE	)	)





@require_vision
@require_tf
class  A				(							unittest.TestCase						):





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






         """simple docstring"""






         A       :   Any					=						tempfile.mkdtemp()
         A       :   Any					=						SamImageProcessor()
         A       :   str					=						SamProcessor(SCREAMING_SNAKE_CASE	)
         processor.save_pretrained(self.tmpdirname	)





     def 				__lowerCAmelCase							(							self						,			**SCREAMING_SNAKE_CASE	) ->				List[str]:






         """simple docstring"""






         return AutoProcessor.from_pretrained(self.tmpdirname						,			**SCREAMING_SNAKE_CASE	).image_processor





     def 				__lowerCAmelCase							(							self	) ->				int:






         """simple docstring"""






         shutil.rmtree(self.tmpdirname	)





     def 				__lowerCAmelCase							(							self	) ->				Any:






         """simple docstring"""






         A       :   Optional[Any]					=						[np.random.randint(255						,			size=(3, 30, 400)						,			dtype=np.uinta	)]

         A       :   List[Any]					=						[Image.fromarray(np.moveaxis(SCREAMING_SNAKE_CASE						,			0						,			-1	)	) for x in image_inputs]

         return image_inputs





     def 				__lowerCAmelCase							(							self	) ->				Any:






         """simple docstring"""






         A       :   Optional[Any]					=						SamProcessor(image_processor=self.get_image_processor()	)
         processor.save_pretrained(self.tmpdirname	)

         A       :   List[str]					=						self.get_image_processor(do_normalize=SCREAMING_SNAKE_CASE						,			padding_value=1.0	)

         A       :   Any					=						SamProcessor.from_pretrained(self.tmpdirname						,			do_normalize=SCREAMING_SNAKE_CASE						,			padding_value=1.0	)

         self.assertEqual(processor.image_processor.to_json_string()						,			image_processor_add_kwargs.to_json_string()	)
         self.assertIsInstance(processor.image_processor						,			SCREAMING_SNAKE_CASE	)





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






         """simple docstring"""






         A       :   Union[str, Any]					=						self.get_image_processor()

         A       :   Dict					=						SamProcessor(image_processor=SCREAMING_SNAKE_CASE	)

         A       :   Union[str, Any]					=						self.prepare_image_inputs()

         A       :   Tuple					=						image_processor(SCREAMING_SNAKE_CASE						,			return_tensors='''np'''	)
         A       :   Optional[Any]					=						processor(images=SCREAMING_SNAKE_CASE						,			return_tensors='''np'''	)

         input_feat_extract.pop('''original_sizes'''	)  # pop original_sizes as it is popped in the processor
         input_feat_extract.pop('''reshaped_input_sizes'''	)  # pop reshaped_input_sizes as it is popped in the processor

         for key in input_feat_extract.keys():
             self.assertAlmostEqual(input_feat_extract[key].sum()						,			input_processor[key].sum()						,			delta=1e-2	)





     @require_tf
     def 				__lowerCAmelCase							(							self	) ->				int:






         """simple docstring"""






         A       :   str					=						self.get_image_processor()

         A       :   Union[str, Any]					=						SamProcessor(image_processor=SCREAMING_SNAKE_CASE	)
         A       :   Dict					=						[tf.ones((1, 3, 5, 5)	)]

         A       :   List[str]					=						[[1764, 2646]]

         A       :   List[Any]					=						[[683, 1024]]
         A       :   Any					=						processor.post_process_masks(SCREAMING_SNAKE_CASE						,			SCREAMING_SNAKE_CASE						,			SCREAMING_SNAKE_CASE						,			return_tensors='''tf'''	)
         self.assertEqual(masks[0].shape						,			(1, 3, 1764, 2646)	)

         A       :   Any					=						processor.post_process_masks(
             SCREAMING_SNAKE_CASE						,			tf.convert_to_tensor(SCREAMING_SNAKE_CASE	)						,			tf.convert_to_tensor(SCREAMING_SNAKE_CASE	)						,			return_tensors='''tf'''						,			)
         self.assertEqual(masks[0].shape						,			(1, 3, 1764, 2646)	)

         # should also work with np
         A       :   int					=						[np.ones((1, 3, 5, 5)	)]
         A       :   int					=						processor.post_process_masks(
             SCREAMING_SNAKE_CASE						,			np.array(SCREAMING_SNAKE_CASE	)						,			np.array(SCREAMING_SNAKE_CASE	)						,			return_tensors='''tf'''	)

         self.assertEqual(masks[0].shape						,			(1, 3, 1764, 2646)	)

         A       :   Any					=						[[1, 0], [0, 1]]
         with self.assertRaises(tf.errors.InvalidArgumentError	):
             A       :   Dict					=						processor.post_process_masks(
                 SCREAMING_SNAKE_CASE						,			np.array(SCREAMING_SNAKE_CASE	)						,			np.array(SCREAMING_SNAKE_CASE	)						,			return_tensors='''tf'''	)





@require_vision
@require_torchvision
class  A				(							unittest.TestCase						):





     def 				__lowerCAmelCase							(							self	) ->				Any:






         """simple docstring"""






         A       :   Any					=						tempfile.mkdtemp()
         A       :   Any					=						SamImageProcessor()
         A       :   Optional[Any]					=						SamProcessor(SCREAMING_SNAKE_CASE	)
         processor.save_pretrained(self.tmpdirname	)





     def 				__lowerCAmelCase							(							self						,			**SCREAMING_SNAKE_CASE	) ->				Optional[Any]:






         """simple docstring"""






         return AutoProcessor.from_pretrained(self.tmpdirname						,			**SCREAMING_SNAKE_CASE	).image_processor





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






         """simple docstring"""






         shutil.rmtree(self.tmpdirname	)





     def 				__lowerCAmelCase							(							self	) ->				List[Any]:






         """simple docstring"""






         A       :   Optional[int]					=						[np.random.randint(255						,			size=(3, 30, 400)						,			dtype=np.uinta	)]

         A       :   Optional[Any]					=						[Image.fromarray(np.moveaxis(SCREAMING_SNAKE_CASE						,			0						,			-1	)	) for x in image_inputs]

         return image_inputs





     @is_pt_tf_cross_test
     def 				__lowerCAmelCase							(							self	) ->				int:






         """simple docstring"""






         A       :   Tuple					=						self.get_image_processor()

         A       :   Union[str, Any]					=						SamProcessor(image_processor=SCREAMING_SNAKE_CASE	)
         A       :   Optional[Any]					=						np.random.randint(0						,			2						,			size=(1, 3, 5, 5)	).astype(np.floataa	)
         A       :   List[str]					=						[tf.convert_to_tensor(SCREAMING_SNAKE_CASE	)]
         A       :   Tuple					=						[torch.tensor(SCREAMING_SNAKE_CASE	)]

         A       :   Dict					=						[[1764, 2646]]

         A       :   int					=						[[683, 1024]]
         A       :   List[Any]					=						processor.post_process_masks(
             SCREAMING_SNAKE_CASE						,			SCREAMING_SNAKE_CASE						,			SCREAMING_SNAKE_CASE						,			return_tensors='''tf'''	)
         A       :   Optional[int]					=						processor.post_process_masks(
             SCREAMING_SNAKE_CASE						,			SCREAMING_SNAKE_CASE						,			SCREAMING_SNAKE_CASE						,			return_tensors='''pt'''	)

         self.assertTrue(np.all(tf_masks[0].numpy() == pt_masks[0].numpy()	)	)





     @is_pt_tf_cross_test
     def 				__lowerCAmelCase							(							self	) ->				Union[str, Any]:






         """simple docstring"""






         A       :   Dict					=						self.get_image_processor()

         A       :   Union[str, Any]					=						SamProcessor(image_processor=SCREAMING_SNAKE_CASE	)

         A       :   Dict					=						self.prepare_image_inputs()

         A       :   List[str]					=						image_processor(SCREAMING_SNAKE_CASE						,			return_tensors='''pt'''	)['''pixel_values'''].numpy()
         A       :   str					=						processor(images=SCREAMING_SNAKE_CASE						,			return_tensors='''pt'''	)['''pixel_values'''].numpy()

         A       :   Tuple					=						image_processor(SCREAMING_SNAKE_CASE						,			return_tensors='''tf'''	)['''pixel_values'''].numpy()
         A       :   Any					=						processor(images=SCREAMING_SNAKE_CASE						,			return_tensors='''tf'''	)['''pixel_values'''].numpy()

         self.assertTrue(np.allclose(SCREAMING_SNAKE_CASE						,			SCREAMING_SNAKE_CASE	)	)
         self.assertTrue(np.allclose(SCREAMING_SNAKE_CASE						,			SCREAMING_SNAKE_CASE	)	)
         self.assertTrue(np.allclose(SCREAMING_SNAKE_CASE						,			SCREAMING_SNAKE_CASE	)	)






'''simple docstring'''




import os







def 		lowerCAmelCase_				(   ):




    '''simple docstring'''



    A       :   List[Any]					=						os.path.join(os.path.dirname(snake_case__						)		,				'''num.txt'''						)
    with open(snake_case__						) as file_hand:
        return str(sum(int(snake_case__						) for line in file_hand						)						)[:10]


if __name__ == "__main__":
      print(solution())




