




from argparse import ArgumentParser

from datasets.commands.convert import ConvertCommand
from datasets.commands.dummy_data import DummyDataCommand
from datasets.commands.env import EnvironmentCommand
from datasets.commands.run_beam import RunBeamCommand
from datasets.commands.test import TestCommand
from datasets.utils.logging import set_verbosity_info

def       _SCREAMING_SNAKE_CASE      (							lowercase     :	Dict					):


      '''simple docstring'''



      return {key.lstrip('-'					): value for key, value in zip(unknown_args[::2]     ,							unknown_args[1::2]					)}

def       _SCREAMING_SNAKE_CASE      (							):


      '''simple docstring'''



      lowerCamelCase_							=   ArgumentParser(
          'HuggingFace Datasets CLI tool'     ,							usage='datasets-cli <command> [<args>]'     ,							allow_abbrev=lowercase					)
      lowerCamelCase_							=   parser.add_subparsers(help='datasets-cli command helpers'					)
      set_verbosity_info()

      # Register commands
      ConvertCommand.register_subcommand(lowercase					)
      EnvironmentCommand.register_subcommand(lowercase					)
      TestCommand.register_subcommand(lowercase					)
      RunBeamCommand.register_subcommand(lowercase					)
      DummyDataCommand.register_subcommand(lowercase					)

      # Parse args
      lowerCamelCase_					,    lowerCamelCase_							=   parser.parse_known_args()
      if not hasattr(lowercase     ,							'func'					):
            parser.print_help()
            exit(1					)
      lowerCamelCase_							=   parse_unknown_args(lowercase					)

      # Run
      lowerCamelCase_							=   args.func(lowercase     ,							**lowercase					)
      service.run()


if __name__ == "__main__":
 main()









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 ChineseCLIPImageProcessor







class   A(						unittest.TestCase       ):



 '''simple docstring'''


 def __init__(    self :  str						,							A_ :  int						,							A_ :  Any=7						,							A_ :  Tuple=3						,							A_ :  Union[str, Any]=18						,							A_ :  Tuple=30						,							A_ :  Union[str, Any]=400						,							A_ :  Optional[int]=True						,							A_ :  List[Any]=None						,							A_ :  Dict=True						,							A_ :  Union[str, Any]=None						,							A_ :  Optional[int]=True						,							A_ :  str=[0.48145466, 0.4578275, 0.40821073]						,							A_ :  Tuple=[0.26862954, 0.26130258, 0.27577711]						,							A_ :  Any=True						,							)       ->     str:

       """simple docstring"""






       lowerCamelCase_							=   size if size is not None else {'height': 224, 'width': 224}
       lowerCamelCase_							=   crop_size if crop_size is not None else {'height': 18, 'width': 18}
       lowerCamelCase_							=   parent
       lowerCamelCase_							=   batch_size
       lowerCamelCase_							=   num_channels
       lowerCamelCase_							=   image_size
       lowerCamelCase_							=   min_resolution
       lowerCamelCase_							=   max_resolution
       lowerCamelCase_							=   do_resize
       lowerCamelCase_							=   size
       lowerCamelCase_							=   do_center_crop
       lowerCamelCase_							=   crop_size
       lowerCamelCase_							=   do_normalize
       lowerCamelCase_							=   image_mean
       lowerCamelCase_							=   image_std
       lowerCamelCase_							=   do_convert_rgb

 def     a__			(    self :  Optional[int]  )       ->     Tuple:

       """simple docstring"""






       return {
           "do_resize": self.do_resize,
           "size": self.size,
           "do_center_crop": self.do_center_crop,
           "crop_size": self.crop_size,
           "do_normalize": self.do_normalize,
           "image_mean": self.image_mean,
           "image_std": self.image_std,
           "do_convert_rgb": self.do_convert_rgb,
       }





 def     a__			(    self :  Any						,							A_ :  Any=False						,							A_ :  Dict=False						,							A_ :  str=False  )       ->     Union[str, Any]:

       """simple docstring"""






       assert not (numpify and torchify), "You cannot specify both numpy and PyTorch tensors at the same time"

       if equal_resolution:
             lowerCamelCase_							=   []
             for i in range(self.batch_size  ):
                   image_inputs.append(
                       np.random.randint(
                           255						,							size=(self.num_channels, self.max_resolution, self.max_resolution)						,							dtype=np.uinta  )  )
       else:
             lowerCamelCase_							=   []
             for i in range(self.batch_size  ):
                   lowerCamelCase_					,    lowerCamelCase_							=   np.random.choice(np.arange(self.min_resolution						,							self.max_resolution  )						,							2  )
                   image_inputs.append(np.random.randint(255						,							size=(self.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(A_						,							0						,							-1  )  ) for x in image_inputs]

       if torchify:
             lowerCamelCase_							=   [torch.from_numpy(A_  ) for x in image_inputs]

       return image_inputs







@require_torch
@require_vision
class   A(						UpperCamelCase							,				unittest.TestCase       ):



 '''simple docstring'''


 UpperCamelCase						       =						ChineseCLIPImageProcessor if is_vision_available() else None

 def     a__			(    self :  int  )       ->     Any:

       """simple docstring"""






       lowerCamelCase_							=   ChineseCLIPImageProcessingTester(self						,							do_center_crop=A_  )

 @property
 def     a__			(    self :  str  )       ->     List[Any]:

       """simple docstring"""






       return self.image_processor_tester.prepare_image_processor_dict()

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

       """simple docstring"""






       lowerCamelCase_							=   self.image_processing_class(**self.image_processor_dict  )
       self.assertTrue(hasattr(A_						,							'do_resize'  )  )
       self.assertTrue(hasattr(A_						,							'size'  )  )
       self.assertTrue(hasattr(A_						,							'do_center_crop'  )  )
       self.assertTrue(hasattr(A_						,							'center_crop'  )  )
       self.assertTrue(hasattr(A_						,							'do_normalize'  )  )
       self.assertTrue(hasattr(A_						,							'image_mean'  )  )
       self.assertTrue(hasattr(A_						,							'image_std'  )  )
       self.assertTrue(hasattr(A_						,							'do_convert_rgb'  )  )

 def     a__			(    self :  Any  )       ->     Any:

       """simple docstring"""






       lowerCamelCase_							=   self.image_processing_class.from_dict(self.image_processor_dict  )
       self.assertEqual(image_processor.size						,							{'height': 224, 'width': 224}  )
       self.assertEqual(image_processor.crop_size						,							{'height': 18, 'width': 18}  )

       lowerCamelCase_							=   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     a__			(    self :  List[Any]  )       ->     List[Any]:

       """simple docstring"""






       pass

 def     a__			(    self :  str  )       ->     str:

       """simple docstring"""






       lowerCamelCase_							=   self.image_processing_class(**self.image_processor_dict  )
       # create random PIL images
       lowerCamelCase_							=   self.image_processor_tester.prepare_inputs(equal_resolution=A_  )
       for image in image_inputs:
             self.assertIsInstance(A_						,							Image.Image  )

       # Test not batched input
       lowerCamelCase_							=   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_							=   image_processing(A_						,							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     a__			(    self :  List[str]  )       ->     Optional[Any]:

       """simple docstring"""






       lowerCamelCase_							=   self.image_processing_class(**self.image_processor_dict  )
       # create random numpy tensors
       lowerCamelCase_							=   self.image_processor_tester.prepare_inputs(equal_resolution=A_						,							numpify=A_  )
       for image in image_inputs:
             self.assertIsInstance(A_						,							np.ndarray  )

       # Test not batched input
       lowerCamelCase_							=   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_							=   image_processing(A_						,							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     a__			(    self :  str  )       ->     Dict:

       """simple docstring"""






       lowerCamelCase_							=   self.image_processing_class(**self.image_processor_dict  )
       # create random PyTorch tensors
       lowerCamelCase_							=   self.image_processor_tester.prepare_inputs(equal_resolution=A_						,							torchify=A_  )
       for image in image_inputs:
             self.assertIsInstance(A_						,							torch.Tensor  )

       # Test not batched input
       lowerCamelCase_							=   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_							=   image_processing(A_						,							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'],
           )						,							)







@require_torch
@require_vision
class   A(						UpperCamelCase							,				unittest.TestCase       ):



 '''simple docstring'''


 UpperCamelCase						       =						ChineseCLIPImageProcessor if is_vision_available() else None

 def     a__			(    self :  Dict  )       ->     int:

       """simple docstring"""






       lowerCamelCase_							=   ChineseCLIPImageProcessingTester(self						,							num_channels=4						,							do_center_crop=A_  )
       lowerCamelCase_							=   3

 @property
 def     a__			(    self :  Any  )       ->     int:

       """simple docstring"""






       return self.image_processor_tester.prepare_image_processor_dict()

 def     a__			(    self :  Dict  )       ->     Tuple:

       """simple docstring"""






       lowerCamelCase_							=   self.image_processing_class(**self.image_processor_dict  )
       self.assertTrue(hasattr(A_						,							'do_resize'  )  )
       self.assertTrue(hasattr(A_						,							'size'  )  )
       self.assertTrue(hasattr(A_						,							'do_center_crop'  )  )
       self.assertTrue(hasattr(A_						,							'center_crop'  )  )
       self.assertTrue(hasattr(A_						,							'do_normalize'  )  )
       self.assertTrue(hasattr(A_						,							'image_mean'  )  )
       self.assertTrue(hasattr(A_						,							'image_std'  )  )
       self.assertTrue(hasattr(A_						,							'do_convert_rgb'  )  )

 def     a__			(    self :  Tuple  )       ->     List[str]:

       """simple docstring"""






       pass





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

       """simple docstring"""






       lowerCamelCase_							=   self.image_processing_class(**self.image_processor_dict  )
       # create random PIL images
       lowerCamelCase_							=   self.image_processor_tester.prepare_inputs(equal_resolution=A_  )
       for image in image_inputs:
             self.assertIsInstance(A_						,							Image.Image  )

       # Test not batched input
       lowerCamelCase_							=   image_processing(image_inputs[0]						,							return_tensors='pt'  ).pixel_values
       self.assertEqual(
           encoded_images.shape						,							(
               1,
               self.expected_encoded_image_num_channels,
               self.image_processor_tester.crop_size['height'],
               self.image_processor_tester.crop_size['width'],
           )						,							)

       # Test batched
       lowerCamelCase_							=   image_processing(A_						,							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.crop_size['height'],
               self.image_processor_tester.crop_size['width'],
           )						,							)



