





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 TvltImageProcessor





def   _lowercase       (    _UpperCAmelCase      ,   _UpperCAmelCase=10      ,   _UpperCAmelCase=10      ,   _UpperCAmelCase=False      ,   _UpperCAmelCase=False					)    ->	Optional[Any]:
				lowerCamelCase									=[]
				for i in range(image_processor_tester.num_frames					):
								video.append(np.random.randint(2_55      ,   size=(image_processor_tester.num_channels, width, height)      ,   dtype=np.uinta					)					)

				if not numpify and not torchify:
								# PIL expects the channel dimension as last dimension
								lowerCamelCase									=[Image.fromarray(np.moveaxis(_UpperCAmelCase      ,   0      ,   -1					)					) for frame in video]

				if torchify:
								lowerCamelCase									=[torch.from_numpy(_UpperCAmelCase					) for frame in video]

				return video





def   _lowercase       (    _UpperCAmelCase      ,   _UpperCAmelCase=False      ,   _UpperCAmelCase=False      ,   _UpperCAmelCase=False					)    ->	Optional[Any]:
				assert not (numpify and torchify), "You cannot specify both numpy and PyTorch tensors at the same time"

				lowerCamelCase									=[]
				for i in range(image_processor_tester.batch_size					):
								if equal_resolution:
												lowerCamelCase									=lowerCamelCase									=image_processor_tester.max_resolution
								else:
												lowerCamelCase			,	lowerCamelCase									=np.random.choice(
												    np.arange(image_processor_tester.min_resolution      ,   image_processor_tester.max_resolution					)      ,   2					)
												lowerCamelCase									=prepare_video(
												    image_processor_tester=_UpperCAmelCase      ,   width=_UpperCAmelCase      ,   height=_UpperCAmelCase      ,   numpify=_UpperCAmelCase      ,   torchify=_UpperCAmelCase      ,   )
								video_inputs.append(_UpperCAmelCase					)

				return video_inputs

class    __A  (    unittest.TestCase     ):


				def __init__(		self ,			UpperCAmelCase_ ,			UpperCAmelCase_=7 ,			UpperCAmelCase_=3 ,			UpperCAmelCase_=4 ,			UpperCAmelCase_=18 ,			UpperCAmelCase_=30 ,			UpperCAmelCase_=400 ,			UpperCAmelCase_=True ,			UpperCAmelCase_=None ,			UpperCAmelCase_=True ,			UpperCAmelCase_=[0.5, 0.5, 0.5] ,			UpperCAmelCase_=[0.5, 0.5, 0.5] ,			UpperCAmelCase_=True ,			UpperCAmelCase_=None ,			):
								lowerCamelCase									=size if size is not None else {"""shortest_edge""": 18}
								lowerCamelCase									=crop_size if crop_size is not None else {"""height""": 18, """width""": 18}

								lowerCamelCase									=parent
								lowerCamelCase									=batch_size
								lowerCamelCase									=num_channels
								lowerCamelCase									=num_frames
								lowerCamelCase									=image_size
								lowerCamelCase									=min_resolution
								lowerCamelCase									=max_resolution
								lowerCamelCase									=do_resize
								lowerCamelCase									=size
								lowerCamelCase									=do_normalize
								lowerCamelCase									=image_mean
								lowerCamelCase									=image_std
								lowerCamelCase									=do_center_crop
								lowerCamelCase									=crop_size


				def _snake_case							(		self				):
								return {
								    "image_mean": self.image_mean,
								    "image_std": self.image_std,
								    "do_normalize": self.do_normalize,
								    "do_resize": self.do_resize,
								    "size": self.size,
								    "do_center_crop": self.do_center_crop,
								    "crop_size": self.crop_size,
								}




@require_torch
@require_vision
class    __A  (    a     ,       unittest.TestCase     ):
				__A  =					TvltImageProcessor if is_vision_available() else None


				def _snake_case							(		self				):
								lowerCamelCase									=TvltImageProcessorTester(self				)


				@property
				def _snake_case							(		self				):
								return self.image_processor_tester.prepare_image_processor_dict()


				def _snake_case							(		self				):
								lowerCamelCase									=self.image_processing_class(**self.image_processor_dict				)
								self.assertTrue(hasattr(UpperCAmelCase_ ,			"""image_mean"""				)				)
								self.assertTrue(hasattr(UpperCAmelCase_ ,			"""image_std"""				)				)
								self.assertTrue(hasattr(UpperCAmelCase_ ,			"""do_normalize"""				)				)
								self.assertTrue(hasattr(UpperCAmelCase_ ,			"""do_resize"""				)				)
								self.assertTrue(hasattr(UpperCAmelCase_ ,			"""do_center_crop"""				)				)
								self.assertTrue(hasattr(UpperCAmelCase_ ,			"""size"""				)				)


				def _snake_case							(		self				):
								# Initialize image_processor
								lowerCamelCase									=self.image_processing_class(**self.image_processor_dict				)
								# create random PIL videos
								lowerCamelCase									=prepare_video_inputs(self.image_processor_tester ,			equal_resolution=UpperCAmelCase_				)
								for video in video_inputs:
												self.assertIsInstance(UpperCAmelCase_ ,			UpperCAmelCase_				)
												self.assertIsInstance(video[0] ,			Image.Image				)

								# Test not batched input
								lowerCamelCase									=image_processor(video_inputs[0] ,			return_tensors="""pt"""				).pixel_values
								self.assertEqual(
								    encoded_videos.shape ,			(
								        1,
								        self.image_processor_tester.num_frames,
								        self.image_processor_tester.num_channels,
								        self.image_processor_tester.crop_size["""height"""],
								        self.image_processor_tester.crop_size["""width"""],
								    ) ,			)

								# Test batched
								lowerCamelCase									=image_processor(UpperCAmelCase_ ,			return_tensors="""pt"""				).pixel_values
								self.assertEqual(
								    encoded_videos.shape ,			(
								        self.image_processor_tester.batch_size,
								        self.image_processor_tester.num_frames,
								        self.image_processor_tester.num_channels,
								        self.image_processor_tester.crop_size["""height"""],
								        self.image_processor_tester.crop_size["""width"""],
								    ) ,			)


				def _snake_case							(		self				):
								# Initialize image_processor
								lowerCamelCase									=self.image_processing_class(**self.image_processor_dict				)
								# create random numpy tensors
								lowerCamelCase									=prepare_video_inputs(self.image_processor_tester ,			equal_resolution=UpperCAmelCase_ ,			numpify=UpperCAmelCase_				)
								for video in video_inputs:
												self.assertIsInstance(UpperCAmelCase_ ,			UpperCAmelCase_				)
												self.assertIsInstance(video[0] ,			np.ndarray				)

								# Test not batched input
								lowerCamelCase									=image_processor(video_inputs[0] ,			return_tensors="""pt"""				).pixel_values
								self.assertEqual(
								    encoded_videos.shape ,			(
								        1,
								        self.image_processor_tester.num_frames,
								        self.image_processor_tester.num_channels,
								        self.image_processor_tester.crop_size["""height"""],
								        self.image_processor_tester.crop_size["""width"""],
								    ) ,			)

								# Test batched
								lowerCamelCase									=image_processor(UpperCAmelCase_ ,			return_tensors="""pt"""				).pixel_values
								self.assertEqual(
								    encoded_videos.shape ,			(
								        self.image_processor_tester.batch_size,
								        self.image_processor_tester.num_frames,
								        self.image_processor_tester.num_channels,
								        self.image_processor_tester.crop_size["""height"""],
								        self.image_processor_tester.crop_size["""width"""],
								    ) ,			)


				def _snake_case							(		self				):
								# Initialize image_processor
								lowerCamelCase									=self.image_processing_class(**self.image_processor_dict				)
								# create random PyTorch tensors
								lowerCamelCase									=prepare_video_inputs(self.image_processor_tester ,			equal_resolution=UpperCAmelCase_ ,			torchify=UpperCAmelCase_				)
								for video in video_inputs:
												self.assertIsInstance(UpperCAmelCase_ ,			UpperCAmelCase_				)
												self.assertIsInstance(video[0] ,			torch.Tensor				)

								# Test not batched input
								lowerCamelCase									=image_processor(video_inputs[0] ,			return_tensors="""pt"""				).pixel_values
								self.assertEqual(
								    encoded_videos.shape ,			(
								        1,
								        self.image_processor_tester.num_frames,
								        self.image_processor_tester.num_channels,
								        self.image_processor_tester.crop_size["""height"""],
								        self.image_processor_tester.crop_size["""width"""],
								    ) ,			)

								# Test batched
								lowerCamelCase									=image_processor(UpperCAmelCase_ ,			return_tensors="""pt"""				).pixel_values
								self.assertEqual(
								    encoded_videos.shape ,			(
								        self.image_processor_tester.batch_size,
								        self.image_processor_tester.num_frames,
								        self.image_processor_tester.num_channels,
								        self.image_processor_tester.crop_size["""height"""],
								        self.image_processor_tester.crop_size["""width"""],
								    ) ,			)












import argparse
import os


UpperCAmelCase__    :      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__":
							UpperCAmelCase__    :      Tuple       					=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)
							UpperCAmelCase__    :      List[str]       					=parser.parse_args()

							UpperCAmelCase__    :      Dict       					=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")

							UpperCAmelCase__    :      List[Any]       					=''''''
							if args.framework == "pytorch":
														UpperCAmelCase__    :      Optional[int]       					=info['''cuda''']
							os.system(F"echo \"export CUDA='{cuda}'\" >> ~/.profile")
							print(F"echo \"export CUDA='{cuda}'\" >> ~/.profile")





