
"""simple docstring"""




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


if is_torch_available():
    import torch

if is_vision_available():
    from PIL import Image

    from transformers import BlipImageProcessor







class 	_lowercase    (							unittest.TestCase					):


     '''simple docstring'''





     def __init__(   self			,      __UpperCamelCase			,      __UpperCamelCase=7			,      __UpperCamelCase=3			,      __UpperCamelCase=18			,      __UpperCamelCase=30			,      __UpperCamelCase=4_00			,      __UpperCamelCase=True			,      __UpperCamelCase=None			,      __UpperCamelCase=True			,      __UpperCamelCase=False			,      __UpperCamelCase=[0.4814_5466, 0.457_8275, 0.4082_1073]			,      __UpperCamelCase=[0.2686_2954, 0.2613_0258, 0.2757_7711]			,      __UpperCamelCase=True			,      )->       Optional[int]:
          UpperCAmelCase__				:			List[Any]							=    size if size is not None else {"height": 20, "width": 20}
          UpperCAmelCase__				:			List[Any]							=    parent
          UpperCAmelCase__				:			str							=    batch_size
          UpperCAmelCase__				:			str							=    num_channels
          UpperCAmelCase__				:			Optional[Any]							=    image_size
          UpperCAmelCase__				:			List[str]							=    min_resolution
          UpperCAmelCase__				:			Tuple							=    max_resolution
          UpperCAmelCase__				:			Tuple							=    do_resize
          UpperCAmelCase__				:			str							=    size
          UpperCAmelCase__				:			Tuple							=    do_normalize
          UpperCAmelCase__				:			Any							=    image_mean
          UpperCAmelCase__				:			Tuple							=    image_std
          UpperCAmelCase__				:			Dict							=    do_pad
          UpperCAmelCase__				:			Optional[Any]							=    do_convert_rgb



     def 			lowerCAmelCase__							(   self	)->       Optional[int]:
          return {
              "do_resize": self.do_resize,
              "size": self.size,
              "do_normalize": self.do_normalize,
              "image_mean": self.image_mean,
              "image_std": self.image_std,
              "do_convert_rgb": self.do_convert_rgb,
              "do_pad": self.do_pad,
          }



     def 			lowerCAmelCase__							(   self			,      __UpperCamelCase=False			,      __UpperCamelCase=False			,      __UpperCamelCase=False	)->       List[str]:
          assert not (numpify and torchify), "You cannot specify both numpy and PyTorch tensors at the same time"

          if equal_resolution:
               UpperCAmelCase__				:			List[str]							=    []
               for i in range(self.batch_size	):
                    image_inputs.append(
                        np.random.randint(
                            2_55			,      size=(self.num_channels, self.max_resolution, self.max_resolution)			,      dtype=np.uinta	)	)
          else:
               UpperCAmelCase__				:			int							=    []
               for i in range(self.batch_size	):
                    UpperCAmelCase__				,						UpperCAmelCase__				:			List[Any]							=    np.random.choice(np.arange(self.min_resolution			,      self.max_resolution	)			,      2	)
                    image_inputs.append(np.random.randint(2_55			,      size=(self.num_channels, width, height)			,      dtype=np.uinta	)	)

          if not numpify and not torchify:
               # PIL expects the channel dimension as last dimension
               UpperCAmelCase__				:			int							=    [Image.fromarray(np.moveaxis(__UpperCamelCase			,      0			,      -1	)	) for x in image_inputs]

          if torchify:
               UpperCAmelCase__				:			int							=    [torch.from_numpy(__UpperCamelCase	) for x in image_inputs]

          return image_inputs







@require_torch
@require_vision
class 	_lowercase    (							lowerCAmelCase_						, unittest.TestCase					):


     '''simple docstring'''





     _A		    =				BlipImageProcessor if is_vision_available() else None



     def 			lowerCAmelCase__							(   self	)->       Union[str, Any]:
          UpperCAmelCase__				:			Optional[Any]							=    BlipImageProcessingTester(self	)



     @property
     def 			lowerCAmelCase__							(   self	)->       Optional[int]:
          return self.image_processor_tester.prepare_image_processor_dict()



     def 			lowerCAmelCase__							(   self	)->       Optional[Any]:
          UpperCAmelCase__				:			Optional[Any]							=    self.image_processing_class(**self.image_processor_dict	)
          self.assertTrue(hasattr(__UpperCamelCase			,      "do_resize"	)	)
          self.assertTrue(hasattr(__UpperCamelCase			,      "size"	)	)
          self.assertTrue(hasattr(__UpperCamelCase			,      "do_normalize"	)	)
          self.assertTrue(hasattr(__UpperCamelCase			,      "image_mean"	)	)
          self.assertTrue(hasattr(__UpperCamelCase			,      "image_std"	)	)
          self.assertTrue(hasattr(__UpperCamelCase			,      "do_convert_rgb"	)	)



     def 			lowerCAmelCase__							(   self	)->       Optional[Any]:
          pass



     def 			lowerCAmelCase__							(   self	)->       int:
          # Initialize image_processor
          UpperCAmelCase__				:			Tuple							=    self.image_processing_class(**self.image_processor_dict	)
          # create random PIL images
          UpperCAmelCase__				:			Any							=    self.image_processor_tester.prepare_inputs(equal_resolution=__UpperCamelCase	)
          for image in image_inputs:
               self.assertIsInstance(__UpperCamelCase			,      Image.Image	)

          # Test not batched input
          UpperCAmelCase__				:			Optional[int]							=    image_processor(image_inputs[0]			,      return_tensors="pt"	).pixel_values
          self.assertEqual(
              encoded_images.shape			,      (
                  1,
                  self.image_processor_tester.num_channels,
                  self.image_processor_tester.size["height"],
                  self.image_processor_tester.size["width"],
              )			,      )

          # Test batched
          UpperCAmelCase__				:			Any							=    image_processor(__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.size["height"],
                  self.image_processor_tester.size["width"],
              )			,      )



     def 			lowerCAmelCase__							(   self	)->       List[Any]:
          # Initialize image_processor
          UpperCAmelCase__				:			int							=    self.image_processing_class(**self.image_processor_dict	)
          # create random numpy tensors
          UpperCAmelCase__				:			Any							=    self.image_processor_tester.prepare_inputs(equal_resolution=__UpperCamelCase			,      numpify=__UpperCamelCase	)
          for image in image_inputs:
               self.assertIsInstance(__UpperCamelCase			,      np.ndarray	)

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

          # Test batched
          UpperCAmelCase__				:			List[Any]							=    image_processor(__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.size["height"],
                  self.image_processor_tester.size["width"],
              )			,      )



     def 			lowerCAmelCase__							(   self	)->       List[str]:
          # Initialize image_processor
          UpperCAmelCase__				:			Tuple							=    self.image_processing_class(**self.image_processor_dict	)
          # create random PyTorch tensors
          UpperCAmelCase__				:			str							=    self.image_processor_tester.prepare_inputs(equal_resolution=__UpperCamelCase			,      torchify=__UpperCamelCase	)
          for image in image_inputs:
               self.assertIsInstance(__UpperCamelCase			,      torch.Tensor	)

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

          # Test batched
          UpperCAmelCase__				:			List[Any]							=    image_processor(__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.size["height"],
                  self.image_processor_tester.size["width"],
              )			,      )







@require_torch
@require_vision
class 	_lowercase    (							lowerCAmelCase_						, unittest.TestCase					):


     '''simple docstring'''





     _A		    =				BlipImageProcessor if is_vision_available() else None



     def 			lowerCAmelCase__							(   self	)->       Union[str, Any]:
          UpperCAmelCase__				:			Any							=    BlipImageProcessingTester(self			,      num_channels=4	)
          UpperCAmelCase__				:			Union[str, Any]							=    3



     @property
     def 			lowerCAmelCase__							(   self	)->       int:
          return self.image_processor_tester.prepare_image_processor_dict()



     def 			lowerCAmelCase__							(   self	)->       Dict:
          UpperCAmelCase__				:			int							=    self.image_processing_class(**self.image_processor_dict	)
          self.assertTrue(hasattr(__UpperCamelCase			,      "do_resize"	)	)
          self.assertTrue(hasattr(__UpperCamelCase			,      "size"	)	)
          self.assertTrue(hasattr(__UpperCamelCase			,      "do_normalize"	)	)
          self.assertTrue(hasattr(__UpperCamelCase			,      "image_mean"	)	)
          self.assertTrue(hasattr(__UpperCamelCase			,      "image_std"	)	)
          self.assertTrue(hasattr(__UpperCamelCase			,      "do_convert_rgb"	)	)



     def 			lowerCAmelCase__							(   self	)->       int:
          pass



     def 			lowerCAmelCase__							(   self	)->       Optional[int]:
          # Initialize image_processor
          UpperCAmelCase__				:			Tuple							=    self.image_processing_class(**self.image_processor_dict	)
          # create random PIL images
          UpperCAmelCase__				:			Tuple							=    self.image_processor_tester.prepare_inputs(equal_resolution=__UpperCamelCase	)
          for image in image_inputs:
               self.assertIsInstance(__UpperCamelCase			,      Image.Image	)

          # Test not batched input
          UpperCAmelCase__				:			Any							=    image_processor(image_inputs[0]			,      return_tensors="pt"	).pixel_values
          self.assertEqual(
              encoded_images.shape			,      (
                  1,
                  self.expected_encoded_image_num_channels,
                  self.image_processor_tester.size["height"],
                  self.image_processor_tester.size["width"],
              )			,      )

          # Test batched
          UpperCAmelCase__				:			Optional[Any]							=    image_processor(__UpperCamelCase			,      return_tensors="pt"	).pixel_values
          self.assertEqual(
              encoded_images.shape			,      (
                  self.image_processor_tester.batch_size,
                  self.expected_encoded_image_num_channels,
                  self.image_processor_tester.size["height"],
                  self.image_processor_tester.size["width"],
              )			,      )





"""simple docstring"""




import argparse
import os


A__   :						Any 							=     {
    """pytorch""": {
        """1.13""": {
            """torch""": """1.13.1""",
            """torchvision""": """0.14.1""",
            """torchaudio""": """0.13.1""",
            """python""": 3.9,
            """cuda""": """cu116""",
            """install""": (
                """python3 -m pip install --no-cache-dir -U torch==1.13.1 torchvision==0.14.1 torchaudio==0.13.1"""
                """ --extra-index-url https://download.pytorch.org/whl/cu116"""
            ),
            """base_image""": """nvidia/cuda:11.6.2-cudnn8-devel-ubuntu20.04""",
        },
        """1.12""": {
            """torch""": """1.12.1""",
            """torchvision""": """0.13.1""",
            """torchaudio""": """0.12.1""",
            """python""": 3.9,
            """cuda""": """cu113""",
            """install""": (
                """python3 -m pip install --no-cache-dir -U torch==1.12.1 torchvision==0.13.1 torchaudio==0.12.1"""
                """ --extra-index-url https://download.pytorch.org/whl/cu113"""
            ),
            """base_image""": """nvidia/cuda:11.2.2-cudnn8-devel-ubuntu20.04""",
        },
        """1.11""": {
            """torch""": """1.11.0""",
            """torchvision""": """0.12.0""",
            """torchaudio""": """0.11.0""",
            """python""": 3.9,
            """cuda""": """cu113""",
            """install""": (
                """python3 -m pip install --no-cache-dir -U torch==1.11.0 torchvision==0.12.0 torchaudio==0.11.0"""
                """ --extra-index-url https://download.pytorch.org/whl/cu113"""
            ),
            """base_image""": """nvidia/cuda:11.2.2-cudnn8-devel-ubuntu20.04""",
        },
        """1.10""": {
            """torch""": """1.10.2""",
            """torchvision""": """0.11.3""",
            """torchaudio""": """0.10.2""",
            """python""": 3.9,
            """cuda""": """cu113""",
            """install""": (
                """python3 -m pip install --no-cache-dir -U torch==1.10.2 torchvision==0.11.3 torchaudio==0.10.2"""
                """ --extra-index-url https://download.pytorch.org/whl/cu113"""
            ),
            """base_image""": """nvidia/cuda:11.2.2-cudnn8-devel-ubuntu20.04""",
        },
        # torchaudio < 0.10 has no CUDA-enabled binary distributions
        """1.9""": {
            """torch""": """1.9.1""",
            """torchvision""": """0.10.1""",
            """torchaudio""": """0.9.1""",
            """python""": 3.9,
            """cuda""": """cu111""",
            """install""": (
                """python3 -m pip install --no-cache-dir -U torch==1.9.1 torchvision==0.10.1 torchaudio==0.9.1"""
                """ --extra-index-url https://download.pytorch.org/whl/cu111"""
            ),
            """base_image""": """nvidia/cuda:11.2.2-cudnn8-devel-ubuntu20.04""",
        },
    },
    """tensorflow""": {
        """2.11""": {
            """tensorflow""": """2.11.1""",
            """install""": """python3 -m pip install --no-cache-dir -U tensorflow==2.11.1""",
            """base_image""": """nvidia/cuda:11.2.2-cudnn8-devel-ubuntu20.04""",
        },
        """2.10""": {
            """tensorflow""": """2.10.1""",
            """install""": """python3 -m pip install --no-cache-dir -U tensorflow==2.10.1""",
            """base_image""": """nvidia/cuda:11.2.2-cudnn8-devel-ubuntu20.04""",
        },
        """2.9""": {
            """tensorflow""": """2.9.3""",
            """install""": """python3 -m pip install --no-cache-dir -U tensorflow==2.9.3""",
            """base_image""": """nvidia/cuda:11.2.2-cudnn8-devel-ubuntu20.04""",
        },
        """2.8""": {
            """tensorflow""": """2.8.2""",
            """install""": """python3 -m pip install --no-cache-dir -U tensorflow==2.8.2""",
            """base_image""": """nvidia/cuda:11.2.2-cudnn8-devel-ubuntu20.04""",
        },
        """2.7""": {
            """tensorflow""": """2.7.3""",
            """install""": """python3 -m pip install --no-cache-dir -U tensorflow==2.7.3""",
            """base_image""": """nvidia/cuda:11.2.2-cudnn8-devel-ubuntu20.04""",
        },
        """2.6""": {
            """tensorflow""": """2.6.5""",
            """install""": """python3 -m pip install --no-cache-dir -U tensorflow==2.6.5""",
            """base_image""": """nvidia/cuda:11.2.2-cudnn8-devel-ubuntu20.04""",
        },
        """2.5""": {
            """tensorflow""": """2.5.3""",
            """install""": """python3 -m pip install --no-cache-dir -U tensorflow==2.5.3""",
            """base_image""": """nvidia/cuda:11.2.2-cudnn8-devel-ubuntu20.04""",
        },
    },
}


if __name__ == "__main__":
    A__   :						str 							=     argparse.ArgumentParser("""Choose the framework and version to install""")
    parser.add_argument(
        """--framework""", help="""The framework to install. Should be `torch` or `tensorflow`""", type=str, required=True
    )
    parser.add_argument("""--version""", help="""The version of the framework to install.""", type=str, required=True)
    A__   :						Any 							=     parser.parse_args()

    A__   :						List[Any] 							=     past_versions_testing[args.framework][args.version]

    os.system(f"""echo \"export INSTALL_CMD=\'{info["install"]}\'\" >> ~/.profile""")
    print(f"""echo \"export INSTALL_CMD=\'{info["install"]}\'\" >> ~/.profile""")

    A__   :						Any 							=     """"""
    if args.framework == "pytorch":
        A__   :						str 							=     info["""cuda"""]
    os.system(f"""echo \"export CUDA='{cuda}'\" >> ~/.profile""")
    print(f"""echo \"export CUDA='{cuda}'\" >> ~/.profile""")



