





# coding=utf-8
# Copyright 2023 The HuggingFace Inc. team.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# this script dumps information about the environment

import os
import platform
import sys


__A									=				"3"

print("Python version:", sys.version)

print("OS platform:", platform.platform())
print("OS architecture:", platform.machine())

try:
     import torch

     print("Torch version:", torch.__version__)
     print("Cuda available:", torch.cuda.is_available())
     print("Cuda version:", torch.version.cuda)
     print("CuDNN version:", torch.backends.cudnn.version())
     print("Number of GPUs available:", torch.cuda.device_count())
except ImportError:
     print("Torch version:", None)

try:
     import transformers

     print("transformers version:", transformers.__version__)
except ImportError:
     print("transformers version:", None)








import unittest

import numpy as np

from transformers.testing_utils import require_torch, require_vision
from transformers.utils import is_torch_available, is_vision_available

from ...test_image_processing_common import ImageProcessingSavingTestMixin, prepare_image_inputs


if is_torch_available():
     import torch

if is_vision_available():
     from PIL import Image

     from transformers import PoolFormerImageProcessor



class    _SCREAMING_SNAKE_CASE						(	unittest.TestCase    ):







 '''simple docstring'''

 def __init__(self				:   List[Any]       , UpperCAmelCase_				:   Any       , UpperCAmelCase_				:   Dict=7       , UpperCAmelCase_				:   List[str]=3       , UpperCAmelCase_				:   str=30       , UpperCAmelCase_				:   List[str]=400       , UpperCAmelCase_				:   Optional[int]=True       , UpperCAmelCase_				:   Optional[int]=None       , UpperCAmelCase_				:   Tuple=0.9       , UpperCAmelCase_				:   str=None       , UpperCAmelCase_				:   int=True       , UpperCAmelCase_				:   Union[str, Any]=[0.5, 0.5, 0.5]       , UpperCAmelCase_				:   Optional[Any]=[0.5, 0.5, 0.5]       , )       ->str:



   '''simple docstring'''



   lowerCamelCase__:      List[Any]			  =size if size is not None else {"shortest_edge": 30}
   lowerCamelCase__:      Dict			  =crop_size if crop_size is not None else {"height": 30, "width": 30}
   lowerCamelCase__:      Any			  =parent
   lowerCamelCase__:      Any			  =batch_size
   lowerCamelCase__:      Optional[Any]			  =num_channels
   lowerCamelCase__:      Tuple			  =min_resolution
   lowerCamelCase__:      Union[str, Any]			  =max_resolution
   lowerCamelCase__:      Union[str, Any]			  =do_resize_and_center_crop
   lowerCamelCase__:      Optional[int]			  =size
   lowerCamelCase__:      str			  =crop_pct
   lowerCamelCase__:      Any			  =crop_size
   lowerCamelCase__:      List[str]			  =do_normalize
   lowerCamelCase__:      List[str]			  =image_mean
   lowerCamelCase__:      Tuple			  =image_std







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



   '''simple docstring'''



   return {
       "size": self.size,
       "do_resize_and_center_crop": self.do_resize_and_center_crop,
       "crop_pct": self.crop_pct,
       "crop_size": self.crop_size,
       "do_normalize": self.do_normalize,
       "image_mean": self.image_mean,
       "image_std": self.image_std,
   }



@require_torch
@require_vision
class    _SCREAMING_SNAKE_CASE						(	__SCREAMING_SNAKE_CASE    ,							unittest.TestCase    ):







 '''simple docstring'''
 lowercase_		=			PoolFormerImageProcessor if is_vision_available() else None

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



   '''simple docstring'''



   lowerCamelCase__:      Optional[int]			  =PoolFormerImageProcessingTester(self)

 @property
 def 							SCREAMING_SNAKE_CASE_					(self				:   str)       ->int:



   '''simple docstring'''



   return self.image_processor_tester.prepare_image_processor_dict()

 def 							SCREAMING_SNAKE_CASE_					(self				:   Optional[Any])       ->Optional[Any]:



   '''simple docstring'''



   lowerCamelCase__:      Any			  =self.image_processing_class(**self.image_processor_dict)
   self.assertTrue(hasattr(UpperCAmelCase_       , "do_resize_and_center_crop"))
   self.assertTrue(hasattr(UpperCAmelCase_       , "size"))
   self.assertTrue(hasattr(UpperCAmelCase_       , "crop_pct"))
   self.assertTrue(hasattr(UpperCAmelCase_       , "do_normalize"))
   self.assertTrue(hasattr(UpperCAmelCase_       , "image_mean"))
   self.assertTrue(hasattr(UpperCAmelCase_       , "image_std"))

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



   '''simple docstring'''



   lowerCamelCase__:      List[str]			  =self.image_processing_class.from_dict(self.image_processor_dict)
   self.assertEqual(image_processor.size       , {"shortest_edge": 30})
   self.assertEqual(image_processor.crop_size       , {"height": 30, "width": 30})

   lowerCamelCase__:      Union[str, Any]			  =self.image_processing_class.from_dict(self.image_processor_dict       , size=42       , crop_size=84)
   self.assertEqual(image_processor.size       , {"shortest_edge": 42})
   self.assertEqual(image_processor.crop_size       , {"height": 84, "width": 84})

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



   '''simple docstring'''



   pass

 def 							SCREAMING_SNAKE_CASE_					(self				:   Optional[Any])       ->Any:



   '''simple docstring'''



   lowerCamelCase__:      Union[str, Any]			  =self.image_processing_class(**self.image_processor_dict)
   # create random PIL images
   lowerCamelCase__:      Union[str, Any]			  =prepare_image_inputs(self.image_processor_tester       , equal_resolution=UpperCAmelCase_)
   for image in image_inputs:
     self.assertIsInstance(UpperCAmelCase_       , Image.Image)

   # Test not batched input
   lowerCamelCase__:      Dict			  =image_processing(image_inputs[0]       , return_tensors="pt").pixel_values

   self.assertEqual(
       encoded_images.shape       , (
           1,
           self.image_processor_tester.num_channels,
           self.image_processor_tester.crop_size["height"],
           self.image_processor_tester.crop_size["width"],
       )       , )

   # Test batched
   lowerCamelCase__:      int			  =image_processing(UpperCAmelCase_       , return_tensors="pt").pixel_values
   self.assertEqual(
       encoded_images.shape       , (
           self.image_processor_tester.batch_size,
           self.image_processor_tester.num_channels,
           self.image_processor_tester.crop_size["height"],
           self.image_processor_tester.crop_size["width"],
       )       , )

 def 							SCREAMING_SNAKE_CASE_					(self				:   Optional[Any])       ->Dict:



   '''simple docstring'''



   lowerCamelCase__:      Any			  =self.image_processing_class(**self.image_processor_dict)
   # create random numpy tensors
   lowerCamelCase__:      Tuple			  =prepare_image_inputs(self.image_processor_tester       , equal_resolution=UpperCAmelCase_       , numpify=UpperCAmelCase_)
   for image in image_inputs:
     self.assertIsInstance(UpperCAmelCase_       , np.ndarray)

   # Test not batched input
   lowerCamelCase__:      Union[str, Any]			  =image_processing(image_inputs[0]       , return_tensors="pt").pixel_values
   self.assertEqual(
       encoded_images.shape       , (
           1,
           self.image_processor_tester.num_channels,
           self.image_processor_tester.crop_size["height"],
           self.image_processor_tester.crop_size["width"],
       )       , )

   # Test batched
   lowerCamelCase__:      List[str]			  =image_processing(UpperCAmelCase_       , return_tensors="pt").pixel_values
   self.assertEqual(
       encoded_images.shape       , (
           self.image_processor_tester.batch_size,
           self.image_processor_tester.num_channels,
           self.image_processor_tester.crop_size["height"],
           self.image_processor_tester.crop_size["width"],
       )       , )







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



   '''simple docstring'''



   lowerCamelCase__:      Optional[int]			  =self.image_processing_class(**self.image_processor_dict)
   # create random PyTorch tensors
   lowerCamelCase__:      Any			  =prepare_image_inputs(self.image_processor_tester       , equal_resolution=UpperCAmelCase_       , torchify=UpperCAmelCase_)
   for image in image_inputs:
     self.assertIsInstance(UpperCAmelCase_       , torch.Tensor)

   # Test not batched input
   lowerCamelCase__:      Any			  =image_processing(image_inputs[0]       , return_tensors="pt").pixel_values
   self.assertEqual(
       encoded_images.shape       , (
           1,
           self.image_processor_tester.num_channels,
           self.image_processor_tester.crop_size["height"],
           self.image_processor_tester.crop_size["width"],
       )       , )

   # Test batched
   lowerCamelCase__:      str			  =image_processing(UpperCAmelCase_       , return_tensors="pt").pixel_values
   self.assertEqual(
       encoded_images.shape       , (
           self.image_processor_tester.batch_size,
           self.image_processor_tester.num_channels,
           self.image_processor_tester.crop_size["height"],
           self.image_processor_tester.crop_size["width"],
       )       , )

