



"""simple docstring"""






import unittest

from transformers import (
    MODEL_FOR_OBJECT_DETECTION_MAPPING,
    AutoFeatureExtractor,
    AutoModelForObjectDetection,
    ObjectDetectionPipeline,
    is_vision_available,
    pipeline,
)
from transformers.testing_utils import (
    is_pipeline_test,
    nested_simplify,
    require_pytesseract,
    require_tf,
    require_timm,
    require_torch,
    require_vision,
    slow,
)

from .test_pipelines_common import ANY


if is_vision_available():
     from PIL import Image
else:



     class     UpperCAmelCase    :



        @staticmethod
        def    __UpperCAmelCase    (       *__lowerCamelCase    :	Tuple							,       **__lowerCamelCase    :	str				):



          """simple docstring"""
          pass



@is_pipeline_test
@require_vision
@require_timm
@require_torch
class     UpperCAmelCase    (	unittest.TestCase  ):
   A__		:	Optional[Any]           =  MODEL_FOR_OBJECT_DETECTION_MAPPING



   def    __UpperCAmelCase    (       self    :	Union[str, Any]							,       __lowerCamelCase    :	Optional[int]							,       __lowerCamelCase    :	Optional[int]							,       __lowerCamelCase    :	str				):



     """simple docstring"""
     _snake_case   	=      ObjectDetectionPipeline(model=__lowerCamelCase							,       image_processor=__lowerCamelCase				)
     return object_detector, ["./tests/fixtures/tests_samples/COCO/000000039769.png"]



   def    __UpperCAmelCase    (       self    :	List[str]							,       __lowerCamelCase    :	Union[str, Any]							,       __lowerCamelCase    :	Any				):



     """simple docstring"""
     _snake_case   	=      object_detector('''./tests/fixtures/tests_samples/COCO/000000039769.png'''							,       threshold=0.0				)

     self.assertGreater(len(__lowerCamelCase				)							,       0				)
     for detected_object in outputs:
       self.assertEqual(
           __lowerCamelCase							,       {
               '''score''': ANY(__lowerCamelCase				),
               '''label''': ANY(__lowerCamelCase				),
               '''box''': {'''xmin''': ANY(__lowerCamelCase				), '''ymin''': ANY(__lowerCamelCase				), '''xmax''': ANY(__lowerCamelCase				), '''ymax''': ANY(__lowerCamelCase				)},
           }							,       )

     import datasets

     _snake_case   	=      datasets.load_dataset('''hf-internal-testing/fixtures_image_utils'''							,       '''image'''							,       split='''test'''				)

     _snake_case   	=      [
         Image.open('''./tests/fixtures/tests_samples/COCO/000000039769.png'''				),
         '''http://images.cocodataset.org/val2017/000000039769.jpg''',
         # RGBA
         dataset[0]['''file'''],
         # LA
         dataset[1]['''file'''],
         # L
         dataset[2]['''file'''],
     ]
     _snake_case   	=      object_detector(__lowerCamelCase							,       threshold=0.0				)

     self.assertEqual(len(__lowerCamelCase				)							,       len(__lowerCamelCase				)				)
     for outputs in batch_outputs:
       self.assertGreater(len(__lowerCamelCase				)							,       0				)
       for detected_object in outputs:
         self.assertEqual(
             __lowerCamelCase							,       {
                 '''score''': ANY(__lowerCamelCase				),
                 '''label''': ANY(__lowerCamelCase				),
                 '''box''': {'''xmin''': ANY(__lowerCamelCase				), '''ymin''': ANY(__lowerCamelCase				), '''xmax''': ANY(__lowerCamelCase				), '''ymax''': ANY(__lowerCamelCase				)},
             }							,       )



   @require_tf
   @unittest.skip('''Object detection not implemented in TF'''				)
   def    __UpperCAmelCase    (       self    :	Optional[Any]				):



     """simple docstring"""
     pass



   @require_torch
   def    __UpperCAmelCase    (       self    :	Any				):



     """simple docstring"""
     _snake_case   	=      '''hf-internal-testing/tiny-detr-mobilenetsv3'''

     _snake_case   	=      AutoModelForObjectDetection.from_pretrained(__lowerCamelCase				)
     _snake_case   	=      AutoFeatureExtractor.from_pretrained(__lowerCamelCase				)
     _snake_case   	=      ObjectDetectionPipeline(model=__lowerCamelCase							,       feature_extractor=__lowerCamelCase				)

     _snake_case   	=      object_detector('''http://images.cocodataset.org/val2017/000000039769.jpg'''							,       threshold=0.0				)

     self.assertEqual(
         nested_simplify(__lowerCamelCase							,       decimals=4				)							,       [
             {'''score''': 0.3_3_7_6, '''label''': '''LABEL_0''', '''box''': {'''xmin''': 1_5_9, '''ymin''': 1_2_0, '''xmax''': 4_8_0, '''ymax''': 3_5_9}},
             {'''score''': 0.3_3_7_6, '''label''': '''LABEL_0''', '''box''': {'''xmin''': 1_5_9, '''ymin''': 1_2_0, '''xmax''': 4_8_0, '''ymax''': 3_5_9}},
         ]							,       )

     _snake_case   	=      object_detector(
         [
             '''http://images.cocodataset.org/val2017/000000039769.jpg''',
             '''http://images.cocodataset.org/val2017/000000039769.jpg''',
         ]							,       threshold=0.0							,       )

     self.assertEqual(
         nested_simplify(__lowerCamelCase							,       decimals=4				)							,       [
             [
                 {'''score''': 0.3_3_7_6, '''label''': '''LABEL_0''', '''box''': {'''xmin''': 1_5_9, '''ymin''': 1_2_0, '''xmax''': 4_8_0, '''ymax''': 3_5_9}},
                 {'''score''': 0.3_3_7_6, '''label''': '''LABEL_0''', '''box''': {'''xmin''': 1_5_9, '''ymin''': 1_2_0, '''xmax''': 4_8_0, '''ymax''': 3_5_9}},
             ],
             [
                 {'''score''': 0.3_3_7_6, '''label''': '''LABEL_0''', '''box''': {'''xmin''': 1_5_9, '''ymin''': 1_2_0, '''xmax''': 4_8_0, '''ymax''': 3_5_9}},
                 {'''score''': 0.3_3_7_6, '''label''': '''LABEL_0''', '''box''': {'''xmin''': 1_5_9, '''ymin''': 1_2_0, '''xmax''': 4_8_0, '''ymax''': 3_5_9}},
             ],
         ]							,       )



   @require_torch
   @slow
   def    __UpperCAmelCase    (       self    :	Any				):



     """simple docstring"""
     _snake_case   	=      '''facebook/detr-resnet-50'''

     _snake_case   	=      AutoModelForObjectDetection.from_pretrained(__lowerCamelCase				)
     _snake_case   	=      AutoFeatureExtractor.from_pretrained(__lowerCamelCase				)
     _snake_case   	=      ObjectDetectionPipeline(model=__lowerCamelCase							,       feature_extractor=__lowerCamelCase				)

     _snake_case   	=      object_detector('''http://images.cocodataset.org/val2017/000000039769.jpg'''				)
     self.assertEqual(
         nested_simplify(__lowerCamelCase							,       decimals=4				)							,       [
             {'''score''': 0.9_9_8_2, '''label''': '''remote''', '''box''': {'''xmin''': 4_0, '''ymin''': 7_0, '''xmax''': 1_7_5, '''ymax''': 1_1_7}},
             {'''score''': 0.9_9_6_0, '''label''': '''remote''', '''box''': {'''xmin''': 3_3_3, '''ymin''': 7_2, '''xmax''': 3_6_8, '''ymax''': 1_8_7}},
             {'''score''': 0.9_9_5_5, '''label''': '''couch''', '''box''': {'''xmin''': 0, '''ymin''': 1, '''xmax''': 6_3_9, '''ymax''': 4_7_3}},
             {'''score''': 0.9_9_8_8, '''label''': '''cat''', '''box''': {'''xmin''': 1_3, '''ymin''': 5_2, '''xmax''': 3_1_4, '''ymax''': 4_7_0}},
             {'''score''': 0.9_9_8_7, '''label''': '''cat''', '''box''': {'''xmin''': 3_4_5, '''ymin''': 2_3, '''xmax''': 6_4_0, '''ymax''': 3_6_8}},
         ]							,       )

     _snake_case   	=      object_detector(
         [
             '''http://images.cocodataset.org/val2017/000000039769.jpg''',
             '''http://images.cocodataset.org/val2017/000000039769.jpg''',
         ]				)
     self.assertEqual(
         nested_simplify(__lowerCamelCase							,       decimals=4				)							,       [
             [
                 {'''score''': 0.9_9_8_2, '''label''': '''remote''', '''box''': {'''xmin''': 4_0, '''ymin''': 7_0, '''xmax''': 1_7_5, '''ymax''': 1_1_7}},
                 {'''score''': 0.9_9_6_0, '''label''': '''remote''', '''box''': {'''xmin''': 3_3_3, '''ymin''': 7_2, '''xmax''': 3_6_8, '''ymax''': 1_8_7}},
                 {'''score''': 0.9_9_5_5, '''label''': '''couch''', '''box''': {'''xmin''': 0, '''ymin''': 1, '''xmax''': 6_3_9, '''ymax''': 4_7_3}},
                 {'''score''': 0.9_9_8_8, '''label''': '''cat''', '''box''': {'''xmin''': 1_3, '''ymin''': 5_2, '''xmax''': 3_1_4, '''ymax''': 4_7_0}},
                 {'''score''': 0.9_9_8_7, '''label''': '''cat''', '''box''': {'''xmin''': 3_4_5, '''ymin''': 2_3, '''xmax''': 6_4_0, '''ymax''': 3_6_8}},
             ],
             [
                 {'''score''': 0.9_9_8_2, '''label''': '''remote''', '''box''': {'''xmin''': 4_0, '''ymin''': 7_0, '''xmax''': 1_7_5, '''ymax''': 1_1_7}},
                 {'''score''': 0.9_9_6_0, '''label''': '''remote''', '''box''': {'''xmin''': 3_3_3, '''ymin''': 7_2, '''xmax''': 3_6_8, '''ymax''': 1_8_7}},
                 {'''score''': 0.9_9_5_5, '''label''': '''couch''', '''box''': {'''xmin''': 0, '''ymin''': 1, '''xmax''': 6_3_9, '''ymax''': 4_7_3}},
                 {'''score''': 0.9_9_8_8, '''label''': '''cat''', '''box''': {'''xmin''': 1_3, '''ymin''': 5_2, '''xmax''': 3_1_4, '''ymax''': 4_7_0}},
                 {'''score''': 0.9_9_8_7, '''label''': '''cat''', '''box''': {'''xmin''': 3_4_5, '''ymin''': 2_3, '''xmax''': 6_4_0, '''ymax''': 3_6_8}},
             ],
         ]							,       )



   @require_torch
   @slow
   def    __UpperCAmelCase    (       self    :	Optional[int]				):



     """simple docstring"""
     _snake_case   	=      '''facebook/detr-resnet-50'''

     _snake_case   	=      pipeline('''object-detection'''							,       model=__lowerCamelCase				)

     _snake_case   	=      object_detector('''http://images.cocodataset.org/val2017/000000039769.jpg'''				)
     self.assertEqual(
         nested_simplify(__lowerCamelCase							,       decimals=4				)							,       [
             {'''score''': 0.9_9_8_2, '''label''': '''remote''', '''box''': {'''xmin''': 4_0, '''ymin''': 7_0, '''xmax''': 1_7_5, '''ymax''': 1_1_7}},
             {'''score''': 0.9_9_6_0, '''label''': '''remote''', '''box''': {'''xmin''': 3_3_3, '''ymin''': 7_2, '''xmax''': 3_6_8, '''ymax''': 1_8_7}},
             {'''score''': 0.9_9_5_5, '''label''': '''couch''', '''box''': {'''xmin''': 0, '''ymin''': 1, '''xmax''': 6_3_9, '''ymax''': 4_7_3}},
             {'''score''': 0.9_9_8_8, '''label''': '''cat''', '''box''': {'''xmin''': 1_3, '''ymin''': 5_2, '''xmax''': 3_1_4, '''ymax''': 4_7_0}},
             {'''score''': 0.9_9_8_7, '''label''': '''cat''', '''box''': {'''xmin''': 3_4_5, '''ymin''': 2_3, '''xmax''': 6_4_0, '''ymax''': 3_6_8}},
         ]							,       )

     _snake_case   	=      object_detector(
         [
             '''http://images.cocodataset.org/val2017/000000039769.jpg''',
             '''http://images.cocodataset.org/val2017/000000039769.jpg''',
         ]				)
     self.assertEqual(
         nested_simplify(__lowerCamelCase							,       decimals=4				)							,       [
             [
                 {'''score''': 0.9_9_8_2, '''label''': '''remote''', '''box''': {'''xmin''': 4_0, '''ymin''': 7_0, '''xmax''': 1_7_5, '''ymax''': 1_1_7}},
                 {'''score''': 0.9_9_6_0, '''label''': '''remote''', '''box''': {'''xmin''': 3_3_3, '''ymin''': 7_2, '''xmax''': 3_6_8, '''ymax''': 1_8_7}},
                 {'''score''': 0.9_9_5_5, '''label''': '''couch''', '''box''': {'''xmin''': 0, '''ymin''': 1, '''xmax''': 6_3_9, '''ymax''': 4_7_3}},
                 {'''score''': 0.9_9_8_8, '''label''': '''cat''', '''box''': {'''xmin''': 1_3, '''ymin''': 5_2, '''xmax''': 3_1_4, '''ymax''': 4_7_0}},
                 {'''score''': 0.9_9_8_7, '''label''': '''cat''', '''box''': {'''xmin''': 3_4_5, '''ymin''': 2_3, '''xmax''': 6_4_0, '''ymax''': 3_6_8}},
             ],
             [
                 {'''score''': 0.9_9_8_2, '''label''': '''remote''', '''box''': {'''xmin''': 4_0, '''ymin''': 7_0, '''xmax''': 1_7_5, '''ymax''': 1_1_7}},
                 {'''score''': 0.9_9_6_0, '''label''': '''remote''', '''box''': {'''xmin''': 3_3_3, '''ymin''': 7_2, '''xmax''': 3_6_8, '''ymax''': 1_8_7}},
                 {'''score''': 0.9_9_5_5, '''label''': '''couch''', '''box''': {'''xmin''': 0, '''ymin''': 1, '''xmax''': 6_3_9, '''ymax''': 4_7_3}},
                 {'''score''': 0.9_9_8_8, '''label''': '''cat''', '''box''': {'''xmin''': 1_3, '''ymin''': 5_2, '''xmax''': 3_1_4, '''ymax''': 4_7_0}},
                 {'''score''': 0.9_9_8_7, '''label''': '''cat''', '''box''': {'''xmin''': 3_4_5, '''ymin''': 2_3, '''xmax''': 6_4_0, '''ymax''': 3_6_8}},
             ],
         ]							,       )



   @require_torch
   @slow
   def    __UpperCAmelCase    (       self    :	Union[str, Any]				):



     """simple docstring"""
     _snake_case   	=      0.9_9_8_5
     _snake_case   	=      '''facebook/detr-resnet-50'''

     _snake_case   	=      pipeline('''object-detection'''							,       model=__lowerCamelCase				)

     _snake_case   	=      object_detector('''http://images.cocodataset.org/val2017/000000039769.jpg'''							,       threshold=__lowerCamelCase				)
     self.assertEqual(
         nested_simplify(__lowerCamelCase							,       decimals=4				)							,       [
             {'''score''': 0.9_9_8_8, '''label''': '''cat''', '''box''': {'''xmin''': 1_3, '''ymin''': 5_2, '''xmax''': 3_1_4, '''ymax''': 4_7_0}},
             {'''score''': 0.9_9_8_7, '''label''': '''cat''', '''box''': {'''xmin''': 3_4_5, '''ymin''': 2_3, '''xmax''': 6_4_0, '''ymax''': 3_6_8}},
         ]							,       )





   @require_torch
   @require_pytesseract
   @slow
   def    __UpperCAmelCase    (       self    :	Union[str, Any]				):



     """simple docstring"""
     _snake_case   	=      '''Narsil/layoutlmv3-finetuned-funsd'''
     _snake_case   	=      0.9_9_9_3

     _snake_case   	=      pipeline('''object-detection'''							,       model=__lowerCamelCase							,       threshold=__lowerCamelCase				)

     _snake_case   	=      object_detector(
         '''https://huggingface.co/spaces/impira/docquery/resolve/2359223c1837a7587402bda0f2643382a6eefeab/invoice.png'''				)
     self.assertEqual(
         nested_simplify(__lowerCamelCase							,       decimals=4				)							,       [
             {'''score''': 0.9_9_9_3, '''label''': '''I-ANSWER''', '''box''': {'''xmin''': 2_9_4, '''ymin''': 2_5_4, '''xmax''': 3_4_3, '''ymax''': 2_6_4}},
             {'''score''': 0.9_9_9_3, '''label''': '''I-ANSWER''', '''box''': {'''xmin''': 2_9_4, '''ymin''': 2_5_4, '''xmax''': 3_4_3, '''ymax''': 2_6_4}},
         ]							,       )










"""simple docstring"""






from math import sqrt




def 			snake_case		(		lowerCAmelCase_ = 1000000	)						->				int:
  _snake_case   	=      0
  _snake_case   	=      0
  _snake_case   	=      42

  while num_cuboids <= limit:
    max_cuboid_size += 1
    for sum_shortest_sides in range(2  ,						2 * max_cuboid_size + 1	):
      if sqrt(sum_shortest_sides**2 + max_cuboid_size**2	).is_integer():
        num_cuboids += (
            min(lowerCAmelCase_  ,						sum_shortest_sides // 2	)
            - max(1  ,						sum_shortest_sides - max_cuboid_size	)
            + 1
        )

  return max_cuboid_size


if __name__ == "__main__":
     print(F"{solution() = }")





