
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      _SCREAMING_SNAKE_CASE				:





									@staticmethod
									def 							_UpperCAmelCase    (		*snake_case_			:		int       ,   **snake_case_			:		Any				):


													"""simple docstring"""

													pass

@is_pipeline_test
@require_vision
@require_timm
@require_torch
class      _SCREAMING_SNAKE_CASE				(		unittest.TestCase				):
				lowerCamelCase_	  =  MODEL_FOR_OBJECT_DETECTION_MAPPING





				def 							_UpperCAmelCase    (		self			:		Any       ,   snake_case_			:		List[str]       ,   snake_case_			:		Dict       ,   snake_case_			:		Any				):


								"""simple docstring"""

								A  :	Dict				=					ObjectDetectionPipeline(model=SCREAMING_SNAKE_CASE_       ,   image_processor=SCREAMING_SNAKE_CASE_				)
								return object_detector, ["./tests/fixtures/tests_samples/COCO/000000039769.png"]





				def 							_UpperCAmelCase    (		self			:		int       ,   snake_case_			:		Union[str, Any]       ,   snake_case_			:		Union[str, Any]				):


								"""simple docstring"""

								A  :	Optional[int]				=					object_detector('''./tests/fixtures/tests_samples/COCO/000000039769.png'''       ,   threshold=0.0				)

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

								import datasets

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

								A  :	str				=					[
								    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'],
								]
								A  :	Any				=					object_detector(SCREAMING_SNAKE_CASE_       ,   threshold=0.0				)

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





				@require_tf
				@unittest.skip('''Object detection not implemented in TF'''				)
				def 							_UpperCAmelCase    (		self			:		Tuple				):


								"""simple docstring"""

								pass





				@require_torch
				def 							_UpperCAmelCase    (		self			:		Dict				):


								"""simple docstring"""

								A  :	Union[str, Any]				=					'hf-internal-testing/tiny-detr-mobilenetsv3'

								A  :	Optional[Any]				=					AutoModelForObjectDetection.from_pretrained(SCREAMING_SNAKE_CASE_				)
								A  :	Optional[int]				=					AutoFeatureExtractor.from_pretrained(SCREAMING_SNAKE_CASE_				)
								A  :	Any				=					ObjectDetectionPipeline(model=SCREAMING_SNAKE_CASE_       ,   feature_extractor=SCREAMING_SNAKE_CASE_				)

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

								self.assertEqual(
								    nested_simplify(SCREAMING_SNAKE_CASE_       ,   decimals=4				)       ,   [
								        {'''score''': 0.33_76, '''label''': '''LABEL_0''', '''box''': {'''xmin''': 159, '''ymin''': 120, '''xmax''': 480, '''ymax''': 359}},
								        {'''score''': 0.33_76, '''label''': '''LABEL_0''', '''box''': {'''xmin''': 159, '''ymin''': 120, '''xmax''': 480, '''ymax''': 359}},
								    ]       ,   )

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

								self.assertEqual(
								    nested_simplify(SCREAMING_SNAKE_CASE_       ,   decimals=4				)       ,   [
								        [
								            {'''score''': 0.33_76, '''label''': '''LABEL_0''', '''box''': {'''xmin''': 159, '''ymin''': 120, '''xmax''': 480, '''ymax''': 359}},
								            {'''score''': 0.33_76, '''label''': '''LABEL_0''', '''box''': {'''xmin''': 159, '''ymin''': 120, '''xmax''': 480, '''ymax''': 359}},
								        ],
								        [
								            {'''score''': 0.33_76, '''label''': '''LABEL_0''', '''box''': {'''xmin''': 159, '''ymin''': 120, '''xmax''': 480, '''ymax''': 359}},
								            {'''score''': 0.33_76, '''label''': '''LABEL_0''', '''box''': {'''xmin''': 159, '''ymin''': 120, '''xmax''': 480, '''ymax''': 359}},
								        ],
								    ]       ,   )





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


								"""simple docstring"""

								A  :	int				=					'facebook/detr-resnet-50'

								A  :	Dict				=					AutoModelForObjectDetection.from_pretrained(SCREAMING_SNAKE_CASE_				)
								A  :	List[Any]				=					AutoFeatureExtractor.from_pretrained(SCREAMING_SNAKE_CASE_				)
								A  :	Optional[int]				=					ObjectDetectionPipeline(model=SCREAMING_SNAKE_CASE_       ,   feature_extractor=SCREAMING_SNAKE_CASE_				)

								A  :	Tuple				=					object_detector('''http://images.cocodataset.org/val2017/000000039769.jpg'''				)
								self.assertEqual(
								    nested_simplify(SCREAMING_SNAKE_CASE_       ,   decimals=4				)       ,   [
								        {'''score''': 0.99_82, '''label''': '''remote''', '''box''': {'''xmin''': 40, '''ymin''': 70, '''xmax''': 175, '''ymax''': 117}},
								        {'''score''': 0.99_60, '''label''': '''remote''', '''box''': {'''xmin''': 333, '''ymin''': 72, '''xmax''': 368, '''ymax''': 187}},
								        {'''score''': 0.99_55, '''label''': '''couch''', '''box''': {'''xmin''': 0, '''ymin''': 1, '''xmax''': 639, '''ymax''': 473}},
								        {'''score''': 0.99_88, '''label''': '''cat''', '''box''': {'''xmin''': 13, '''ymin''': 52, '''xmax''': 314, '''ymax''': 470}},
								        {'''score''': 0.99_87, '''label''': '''cat''', '''box''': {'''xmin''': 345, '''ymin''': 23, '''xmax''': 640, '''ymax''': 368}},
								    ]       ,   )

								A  :	Dict				=					object_detector(
								    [
								        '''http://images.cocodataset.org/val2017/000000039769.jpg''',
								        '''http://images.cocodataset.org/val2017/000000039769.jpg''',
								    ]				)
								self.assertEqual(
								    nested_simplify(SCREAMING_SNAKE_CASE_       ,   decimals=4				)       ,   [
								        [
								            {'''score''': 0.99_82, '''label''': '''remote''', '''box''': {'''xmin''': 40, '''ymin''': 70, '''xmax''': 175, '''ymax''': 117}},
								            {'''score''': 0.99_60, '''label''': '''remote''', '''box''': {'''xmin''': 333, '''ymin''': 72, '''xmax''': 368, '''ymax''': 187}},
								            {'''score''': 0.99_55, '''label''': '''couch''', '''box''': {'''xmin''': 0, '''ymin''': 1, '''xmax''': 639, '''ymax''': 473}},
								            {'''score''': 0.99_88, '''label''': '''cat''', '''box''': {'''xmin''': 13, '''ymin''': 52, '''xmax''': 314, '''ymax''': 470}},
								            {'''score''': 0.99_87, '''label''': '''cat''', '''box''': {'''xmin''': 345, '''ymin''': 23, '''xmax''': 640, '''ymax''': 368}},
								        ],
								        [
								            {'''score''': 0.99_82, '''label''': '''remote''', '''box''': {'''xmin''': 40, '''ymin''': 70, '''xmax''': 175, '''ymax''': 117}},
								            {'''score''': 0.99_60, '''label''': '''remote''', '''box''': {'''xmin''': 333, '''ymin''': 72, '''xmax''': 368, '''ymax''': 187}},
								            {'''score''': 0.99_55, '''label''': '''couch''', '''box''': {'''xmin''': 0, '''ymin''': 1, '''xmax''': 639, '''ymax''': 473}},
								            {'''score''': 0.99_88, '''label''': '''cat''', '''box''': {'''xmin''': 13, '''ymin''': 52, '''xmax''': 314, '''ymax''': 470}},
								            {'''score''': 0.99_87, '''label''': '''cat''', '''box''': {'''xmin''': 345, '''ymin''': 23, '''xmax''': 640, '''ymax''': 368}},
								        ],
								    ]       ,   )





				@require_torch
				@slow
				def 							_UpperCAmelCase    (		self			:		List[Any]				):


								"""simple docstring"""

								A  :	Optional[int]				=					'facebook/detr-resnet-50'

								A  :	str				=					pipeline('''object-detection'''       ,   model=SCREAMING_SNAKE_CASE_				)

								A  :	int				=					object_detector('''http://images.cocodataset.org/val2017/000000039769.jpg'''				)
								self.assertEqual(
								    nested_simplify(SCREAMING_SNAKE_CASE_       ,   decimals=4				)       ,   [
								        {'''score''': 0.99_82, '''label''': '''remote''', '''box''': {'''xmin''': 40, '''ymin''': 70, '''xmax''': 175, '''ymax''': 117}},
								        {'''score''': 0.99_60, '''label''': '''remote''', '''box''': {'''xmin''': 333, '''ymin''': 72, '''xmax''': 368, '''ymax''': 187}},
								        {'''score''': 0.99_55, '''label''': '''couch''', '''box''': {'''xmin''': 0, '''ymin''': 1, '''xmax''': 639, '''ymax''': 473}},
								        {'''score''': 0.99_88, '''label''': '''cat''', '''box''': {'''xmin''': 13, '''ymin''': 52, '''xmax''': 314, '''ymax''': 470}},
								        {'''score''': 0.99_87, '''label''': '''cat''', '''box''': {'''xmin''': 345, '''ymin''': 23, '''xmax''': 640, '''ymax''': 368}},
								    ]       ,   )

								A  :	str				=					object_detector(
								    [
								        '''http://images.cocodataset.org/val2017/000000039769.jpg''',
								        '''http://images.cocodataset.org/val2017/000000039769.jpg''',
								    ]				)
								self.assertEqual(
								    nested_simplify(SCREAMING_SNAKE_CASE_       ,   decimals=4				)       ,   [
								        [
								            {'''score''': 0.99_82, '''label''': '''remote''', '''box''': {'''xmin''': 40, '''ymin''': 70, '''xmax''': 175, '''ymax''': 117}},
								            {'''score''': 0.99_60, '''label''': '''remote''', '''box''': {'''xmin''': 333, '''ymin''': 72, '''xmax''': 368, '''ymax''': 187}},
								            {'''score''': 0.99_55, '''label''': '''couch''', '''box''': {'''xmin''': 0, '''ymin''': 1, '''xmax''': 639, '''ymax''': 473}},
								            {'''score''': 0.99_88, '''label''': '''cat''', '''box''': {'''xmin''': 13, '''ymin''': 52, '''xmax''': 314, '''ymax''': 470}},
								            {'''score''': 0.99_87, '''label''': '''cat''', '''box''': {'''xmin''': 345, '''ymin''': 23, '''xmax''': 640, '''ymax''': 368}},
								        ],
								        [
								            {'''score''': 0.99_82, '''label''': '''remote''', '''box''': {'''xmin''': 40, '''ymin''': 70, '''xmax''': 175, '''ymax''': 117}},
								            {'''score''': 0.99_60, '''label''': '''remote''', '''box''': {'''xmin''': 333, '''ymin''': 72, '''xmax''': 368, '''ymax''': 187}},
								            {'''score''': 0.99_55, '''label''': '''couch''', '''box''': {'''xmin''': 0, '''ymin''': 1, '''xmax''': 639, '''ymax''': 473}},
								            {'''score''': 0.99_88, '''label''': '''cat''', '''box''': {'''xmin''': 13, '''ymin''': 52, '''xmax''': 314, '''ymax''': 470}},
								            {'''score''': 0.99_87, '''label''': '''cat''', '''box''': {'''xmin''': 345, '''ymin''': 23, '''xmax''': 640, '''ymax''': 368}},
								        ],
								    ]       ,   )





				@require_torch
				@slow
				def 							_UpperCAmelCase    (		self			:		List[str]				):


								"""simple docstring"""

								A  :	List[Any]				=					0.99_85
								A  :	Optional[int]				=					'facebook/detr-resnet-50'

								A  :	int				=					pipeline('''object-detection'''       ,   model=SCREAMING_SNAKE_CASE_				)

								A  :	List[str]				=					object_detector('''http://images.cocodataset.org/val2017/000000039769.jpg'''       ,   threshold=SCREAMING_SNAKE_CASE_				)
								self.assertEqual(
								    nested_simplify(SCREAMING_SNAKE_CASE_       ,   decimals=4				)       ,   [
								        {'''score''': 0.99_88, '''label''': '''cat''', '''box''': {'''xmin''': 13, '''ymin''': 52, '''xmax''': 314, '''ymax''': 470}},
								        {'''score''': 0.99_87, '''label''': '''cat''', '''box''': {'''xmin''': 345, '''ymin''': 23, '''xmax''': 640, '''ymax''': 368}},
								    ]       ,   )






				@require_torch
				@require_pytesseract
				@slow
				def 							_UpperCAmelCase    (		self			:		List[Any]				):


								"""simple docstring"""

								A  :	Optional[Any]				=					'Narsil/layoutlmv3-finetuned-funsd'
								A  :	Dict				=					0.99_93

								A  :	int				=					pipeline('''object-detection'''       ,   model=SCREAMING_SNAKE_CASE_       ,   threshold=SCREAMING_SNAKE_CASE_				)

								A  :	int				=					object_detector(
								    '''https://huggingface.co/spaces/impira/docquery/resolve/2359223c1837a7587402bda0f2643382a6eefeab/invoice.png'''				)
								self.assertEqual(
								    nested_simplify(SCREAMING_SNAKE_CASE_       ,   decimals=4				)       ,   [
								        {'''score''': 0.99_93, '''label''': '''I-ANSWER''', '''box''': {'''xmin''': 294, '''ymin''': 254, '''xmax''': 343, '''ymax''': 264}},
								        {'''score''': 0.99_93, '''label''': '''I-ANSWER''', '''box''': {'''xmin''': 294, '''ymin''': 254, '''xmax''': 343, '''ymax''': 264}},
								    ]       ,   )



'''simple docstring'''



from collections import defaultdict
from math import gcd



def      UpperCAmelCase__   (      UpperCAmelCase_       :							int = 1_50_00_00				)	->						int:
     __lowerCamelCase  :      defaultdict														=						defaultdict(UpperCAmelCase_				)
     __lowerCamelCase  :      Any														=						2
     while 2 * euclid_m * (euclid_m + 1) <= limit:
          for euclid_n in range((euclid_m % 2) + 1 ,       UpperCAmelCase_ ,       2				):
               if gcd(UpperCAmelCase_ ,       UpperCAmelCase_				) > 1:
                    continue
               __lowerCamelCase  :      Any														=						2 * euclid_m * (euclid_m + euclid_n)
               for perimeter in range(UpperCAmelCase_ ,       limit + 1 ,       UpperCAmelCase_				):
                    frequencies[perimeter] += 1
          euclid_m += 1
     return sum(1 for frequency in frequencies.values() if frequency == 1				)


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






