


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 ConvNextImageProcessor


class 	a__						(    unittest.TestCase     ):

       def __init__( self   :  str   ,				lowerCamelCase_   :  Tuple   ,				lowerCamelCase_   :  Optional[Any]=7   ,				lowerCamelCase_   :  Optional[int]=3   ,				lowerCamelCase_   :  List[str]=1_8   ,				lowerCamelCase_   :  Tuple=3_0   ,				lowerCamelCase_   :  Tuple=4_0_0   ,				lowerCamelCase_   :  Dict=True   ,				lowerCamelCase_   :  Union[str, Any]=None   ,				lowerCamelCase_   :  Optional[int]=0.8_7_5   ,				lowerCamelCase_   :  Optional[int]=True   ,				lowerCamelCase_   :  Dict=[0.5, 0.5, 0.5]   ,				lowerCamelCase_   :  List[str]=[0.5, 0.5, 0.5]   ,				):
            a_     :  List[Any]				      =     size if size is not None else {"""shortest_edge""": 2_0}
            a_     :  List[str]				      =     parent
            a_     :  Union[str, Any]				      =     batch_size
            a_     :  List[str]				      =     num_channels
            a_     :  List[str]				      =     image_size
            a_     :  Optional[Any]				      =     min_resolution
            a_     :  Any				      =     max_resolution
            a_     :  List[str]				      =     do_resize
            a_     :  Dict				      =     size
            a_     :  Optional[Any]				      =     crop_pct
            a_     :  List[Any]				      =     do_normalize
            a_     :  Dict				      =     image_mean
            a_     :  List[Any]				      =     image_std

       def     UpperCAmelCase( self   :  Dict     ):
            return {
                "image_mean": self.image_mean,
                "image_std": self.image_std,
                "do_normalize": self.do_normalize,
                "do_resize": self.do_resize,
                "size": self.size,
                "crop_pct": self.crop_pct,
            }


@require_torch
@require_vision
class 	a__						(    lowerCAmelCase_    ,							unittest.TestCase     ):
       lowerCamelCase__:  Tuple				     =  ConvNextImageProcessor if is_vision_available() else None

       def     UpperCAmelCase( self   :  List[Any]     ):
            a_     :  Tuple				      =     ConvNextImageProcessingTester(self     )

       @property
       def     UpperCAmelCase( self   :  Any     ):
            return self.image_processor_tester.prepare_image_processor_dict()

       def     UpperCAmelCase( self   :  str     ):
            a_     :  Union[str, Any]				      =     self.image_processing_class(**self.image_processor_dict     )
            self.assertTrue(hasattr(lowerCamelCase_   ,				"""do_resize"""     )     )
            self.assertTrue(hasattr(lowerCamelCase_   ,				"""size"""     )     )
            self.assertTrue(hasattr(lowerCamelCase_   ,				"""crop_pct"""     )     )
            self.assertTrue(hasattr(lowerCamelCase_   ,				"""do_normalize"""     )     )
            self.assertTrue(hasattr(lowerCamelCase_   ,				"""image_mean"""     )     )
            self.assertTrue(hasattr(lowerCamelCase_   ,				"""image_std"""     )     )

       def     UpperCAmelCase( self   :  Optional[int]     ):
            a_     :  Tuple				      =     self.image_processing_class.from_dict(self.image_processor_dict     )
            self.assertEqual(image_processor.size   ,				{"""shortest_edge""": 2_0}     )

            a_     :  str				      =     self.image_processing_class.from_dict(self.image_processor_dict   ,				size=4_2     )
            self.assertEqual(image_processor.size   ,				{"""shortest_edge""": 4_2}     )

       def     UpperCAmelCase( self   :  Optional[Any]     ):
            pass

       def     UpperCAmelCase( self   :  Any     ):
            # Initialize image_processing
            a_     :  Union[str, Any]				      =     self.image_processing_class(**self.image_processor_dict     )
            # create random PIL images
            a_     :  Any				      =     prepare_image_inputs(self.image_processor_tester   ,				equal_resolution=lowerCamelCase_     )
            for image in image_inputs:
                 self.assertIsInstance(lowerCamelCase_   ,				Image.Image     )

            # Test not batched input
            a_     :  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.size["""shortest_edge"""],
                    self.image_processor_tester.size["""shortest_edge"""],
                )   ,				)

            # Test batched
            a_     :  Optional[Any]				      =     image_processing(lowerCamelCase_   ,				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["""shortest_edge"""],
                    self.image_processor_tester.size["""shortest_edge"""],
                )   ,				)

       def     UpperCAmelCase( self   :  Tuple     ):
            # Initialize image_processing
            a_     :  Optional[int]				      =     self.image_processing_class(**self.image_processor_dict     )
            # create random numpy tensors
            a_     :  int				      =     prepare_image_inputs(self.image_processor_tester   ,				equal_resolution=lowerCamelCase_   ,				numpify=lowerCamelCase_     )
            for image in image_inputs:
                 self.assertIsInstance(lowerCamelCase_   ,				np.ndarray     )

            # Test not batched input
            a_     :  List[str]				      =     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["""shortest_edge"""],
                    self.image_processor_tester.size["""shortest_edge"""],
                )   ,				)

            # Test batched
            a_     :  Tuple				      =     image_processing(lowerCamelCase_   ,				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["""shortest_edge"""],
                    self.image_processor_tester.size["""shortest_edge"""],
                )   ,				)

       def     UpperCAmelCase( self   :  str     ):
            # Initialize image_processing
            a_     :  str				      =     self.image_processing_class(**self.image_processor_dict     )
            # create random PyTorch tensors
            a_     :  Optional[int]				      =     prepare_image_inputs(self.image_processor_tester   ,				equal_resolution=lowerCamelCase_   ,				torchify=lowerCamelCase_     )
            for image in image_inputs:
                 self.assertIsInstance(lowerCamelCase_   ,				torch.Tensor     )

            # Test not batched input
            a_     :  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.size["""shortest_edge"""],
                    self.image_processor_tester.size["""shortest_edge"""],
                )   ,				)

            # Test batched
            a_     :  str				      =     image_processing(lowerCamelCase_   ,				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["""shortest_edge"""],
                    self.image_processor_tester.size["""shortest_edge"""],
                )   ,				)







# Copyright 2023 The HuggingFace Team. All rights reserved.
#
# 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.
from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_torch_available,
    is_vision_available,
)


__lowerCamelCase   	=  {
    '''configuration_tvlt''': ['''TVLT_PRETRAINED_CONFIG_ARCHIVE_MAP''', '''TvltConfig'''],
    '''feature_extraction_tvlt''': ['''TvltFeatureExtractor'''],
    '''processing_tvlt''': ['''TvltProcessor'''],
}

try:
       if not is_torch_available():
              raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
       pass
else:
       __lowerCamelCase   	=  [
           '''TVLT_PRETRAINED_MODEL_ARCHIVE_LIST''',
           '''TvltModel''',
           '''TvltForPreTraining''',
           '''TvltForAudioVisualClassification''',
           '''TvltPreTrainedModel''',
       ]

try:
       if not is_vision_available():
              raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
       pass
else:
       __lowerCamelCase   	=  ['''TvltImageProcessor''']


if TYPE_CHECKING:
       from .configuration_tvlt import TVLT_PRETRAINED_CONFIG_ARCHIVE_MAP, TvltConfig
       from .processing_tvlt import TvltProcessor
       from .feature_extraction_tvlt import TvltFeatureExtractor

       try:
              if not is_torch_available():
                     raise OptionalDependencyNotAvailable()
       except OptionalDependencyNotAvailable:
              pass
       else:
              from .modeling_tvlt import (
                  TVLT_PRETRAINED_MODEL_ARCHIVE_LIST,
                  TvltForAudioVisualClassification,
                  TvltForPreTraining,
                  TvltModel,
                  TvltPreTrainedModel,
              )

       try:
              if not is_vision_available():
                     raise OptionalDependencyNotAvailable()
       except OptionalDependencyNotAvailable:
              pass
       else:
              from .image_processing_tvlt import TvltImageProcessor


else:
       import sys

       __lowerCamelCase   	=  _LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)



