





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 ViTImageProcessor





class UpperCAmelCase_							(   unittest.TestCase   ):


  def __init__(       self   ,__snake_case   ,__snake_case=7   ,__snake_case=3   ,__snake_case=1_8   ,__snake_case=3_0   ,__snake_case=4_0_0   ,__snake_case=True   ,__snake_case=None   ,__snake_case=True   ,__snake_case=[0.5, 0.5, 0.5]   ,__snake_case=[0.5, 0.5, 0.5]   ,):



       """simple docstring"""





       A_					      =					size if size is not None else {'''height''': 1_8, '''width''': 1_8}
       A_					      =					parent
       A_					      =					batch_size
       A_					      =					num_channels
       A_					      =					image_size
       A_					      =					min_resolution
       A_					      =					max_resolution
       A_					      =					do_resize
       A_					      =					size
       A_					      =					do_normalize
       A_					      =					image_mean
       A_					      =					image_std




  def 	__UpperCAmelCase    (       self   ):



       """simple docstring"""





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





@require_torch
@require_vision
class UpperCAmelCase_							(   _SCREAMING_SNAKE_CASE    ,		unittest.TestCase   ):
  __lowerCAmelCase      :	Union[str, Any]  	=      ViTImageProcessor if is_vision_available() else None


  def 	__UpperCAmelCase    (       self   ):



       """simple docstring"""





       A_					      =					ViTImageProcessingTester(self   )


  @property
  def 	__UpperCAmelCase    (       self   ):



       """simple docstring"""





       return self.image_processor_tester.prepare_image_processor_dict()


  def 	__UpperCAmelCase    (       self   ):



       """simple docstring"""





       A_					      =					self.image_processing_class(**self.image_processor_dict   )
       self.assertTrue(hasattr(__snake_case   ,'''image_mean'''   )   )
       self.assertTrue(hasattr(__snake_case   ,'''image_std'''   )   )
       self.assertTrue(hasattr(__snake_case   ,'''do_normalize'''   )   )
       self.assertTrue(hasattr(__snake_case   ,'''do_resize'''   )   )
       self.assertTrue(hasattr(__snake_case   ,'''size'''   )   )


  def 	__UpperCAmelCase    (       self   ):



       """simple docstring"""





       A_					      =					self.image_processing_class.from_dict(self.image_processor_dict   )
       self.assertEqual(image_processor.size   ,{'''height''': 1_8, '''width''': 1_8}   )

       A_					      =					self.image_processing_class.from_dict(self.image_processor_dict   ,size=4_2   )
       self.assertEqual(image_processor.size   ,{'''height''': 4_2, '''width''': 4_2}   )


  def 	__UpperCAmelCase    (       self   ):



       """simple docstring"""





       pass


  def 	__UpperCAmelCase    (       self   ):



       """simple docstring"""





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

       # Test not batched input
       A_					      =					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.size['''height'''],
               self.image_processor_tester.size['''width'''],
           )   ,)

       # Test batched
       A_					      =					image_processing(__snake_case   ,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 	__UpperCAmelCase    (       self   ):



       """simple docstring"""





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

       # Test not batched input
       A_					      =					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.size['''height'''],
               self.image_processor_tester.size['''width'''],
           )   ,)

       # Test batched
       A_					      =					image_processing(__snake_case   ,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 	__UpperCAmelCase    (       self   ):



       """simple docstring"""





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

       # Test not batched input
       A_					      =					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.size['''height'''],
               self.image_processor_tester.size['''width'''],
           )   ,)

       # Test batched
       A_					      =					image_processing(__snake_case   ,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'''],
           )   ,)










from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
from sklearn.neighbors import KNeighborsClassifier

# Load iris file
a__			:    List[str]			      =		load_iris()
iris.keys()


print(f'''Target names: \n {iris.target_names} ''')
print(f'''\n Features: \n {iris.feature_names}''')

# Train set e Test set
a__      ,							a__      ,							a__      ,							a__			:    Any			      =		train_test_split(
    iris['data'], iris['target'], random_state=4
)

# KNN

a__			:    List[Any]			      =		KNeighborsClassifier(n_neighbors=1)
knn.fit(X_train, y_train)

# new array to test
a__			:    Optional[Any]			      =		[[1, 2, 1, 4], [2, 3, 4, 5]]

a__			:    Union[str, Any]			      =		knn.predict(X_new)

print(
    f'''\nNew array: \n {X_new}\n\nTarget Names Prediction: \n'''
    f''' {iris['target_names'][prediction]}'''
)



