




import warnings
from typing import Any, Dict, List, Optional, Union

import numpy as np

from ...audio_utils import mel_filter_bank, optimal_fft_length, spectrogram, window_function
from ...feature_extraction_sequence_utils import SequenceFeatureExtractor
from ...feature_extraction_utils import BatchFeature
from ...utils import PaddingStrategy, TensorType, logging


lowerCamelCase__ :   Optional[int]					=							logging.get_logger(__name__)





class        lowerCamelCase_							(      __snake_case					):


 '''simple docstring'''







 lowercase_				    =    ["input_values", "attention_mask"]



 def __init__(							self  :		Optional[int]				,				_lowerCAmelCase  :		Any = 1				,				_lowerCAmelCase  :		Any = 16_000				,				_lowerCAmelCase  :		Optional[int] = 0.0				,				_lowerCAmelCase  :		Any = False				,				_lowerCAmelCase  :		int = 80				,				_lowerCAmelCase  :		Dict = 16				,				_lowerCAmelCase  :		Tuple = 64				,				_lowerCAmelCase  :		List[str] = "hann_window"				,				_lowerCAmelCase  :		Any = 1.0				,				_lowerCAmelCase  :		Optional[Any] = 80				,				_lowerCAmelCase  :		int = 7_600				,				_lowerCAmelCase  :		List[Any] = 1E-10				,				_lowerCAmelCase  :		int = 2				,				_lowerCAmelCase  :		int = True				,				**_lowerCAmelCase  :		int				,				):
       super().__init__(feature_size=a_				,				sampling_rate=a_				,				padding_value=a_				,				**a_						)
       SCREAMING_SNAKE_CASE_							=			do_normalize
       SCREAMING_SNAKE_CASE_							=			return_attention_mask

       SCREAMING_SNAKE_CASE_							=			num_mel_bins
       SCREAMING_SNAKE_CASE_							=			hop_length
       SCREAMING_SNAKE_CASE_							=			win_length
       SCREAMING_SNAKE_CASE_							=			win_function
       SCREAMING_SNAKE_CASE_							=			frame_signal_scale
       SCREAMING_SNAKE_CASE_							=			fmin
       SCREAMING_SNAKE_CASE_							=			fmax
       SCREAMING_SNAKE_CASE_							=			mel_floor
       SCREAMING_SNAKE_CASE_							=			reduction_factor

       SCREAMING_SNAKE_CASE_							=			win_length * sampling_rate // 1_000
       SCREAMING_SNAKE_CASE_							=			hop_length * sampling_rate // 1_000
       SCREAMING_SNAKE_CASE_							=			optimal_fft_length(self.sample_size						)
       SCREAMING_SNAKE_CASE_							=			(self.n_fft // 2) + 1

       SCREAMING_SNAKE_CASE_							=			window_function(window_length=self.sample_size				,				name=self.win_function				,				periodic=a_						)

       SCREAMING_SNAKE_CASE_							=			mel_filter_bank(
           num_frequency_bins=self.n_freqs				,				num_mel_filters=self.num_mel_bins				,				min_frequency=self.fmin				,				max_frequency=self.fmax				,				sampling_rate=self.sampling_rate				,				norm='slaney'				,				mel_scale='slaney'				,				)

       if frame_signal_scale != 1.0:
             warnings.warn(
                 'The argument `frame_signal_scale` is deprecated and will be removed in version 4.30.0 of Transformers'				,				a_				,				)
       if reduction_factor != 2.0:
             warnings.warn(
                 'The argument `reduction_factor` is deprecated and will be removed in version 4.30.0 of Transformers'				,				a_				,				)



 @staticmethod
 # Copied from transformers.models.wav2vec2.feature_extraction_wav2vec2.Wav2Vec2FeatureExtractor.zero_mean_unit_var_norm
 def       lowerCAmelCase_  (							_lowerCAmelCase  :		Optional[int]				,				_lowerCAmelCase  :		Optional[int]				,				_lowerCAmelCase  :		Any = 0.0						):

       if attention_mask is not None:
             SCREAMING_SNAKE_CASE_							=			np.array(a_				,				np.intaa						)
             SCREAMING_SNAKE_CASE_							=			[]

             for vector, length in zip(a_				,				attention_mask.sum(-1						)						):
                   SCREAMING_SNAKE_CASE_							=			(vector - vector[:length].mean()) / np.sqrt(vector[:length].var() + 1E-7						)
                   if length < normed_slice.shape[0]:
                         SCREAMING_SNAKE_CASE_							=			padding_value

                   normed_input_values.append(a_						)
       else:
             SCREAMING_SNAKE_CASE_							=			[(x - x.mean()) / np.sqrt(x.var() + 1E-7						) for x in input_values]

       return normed_input_values



 def       lowerCAmelCase_  (							self  :		List[str]				,				_lowerCAmelCase  :		Tuple				,				):
       SCREAMING_SNAKE_CASE_							=			spectrogram(
           a_				,				window=self.window				,				frame_length=self.sample_size				,				hop_length=self.sample_stride				,				fft_length=self.n_fft				,				mel_filters=self.mel_filters				,				mel_floor=self.mel_floor				,				log_mel='log10'				,				)
       return log_mel_spec.T



 def __call__(							self  :		Tuple				,				_lowerCAmelCase  :		str = None				,				_lowerCAmelCase  :		Union[str, Any] = None				,				_lowerCAmelCase  :		Tuple = False				,				_lowerCAmelCase  :		str = None				,				_lowerCAmelCase  :		Tuple = False				,				_lowerCAmelCase  :		List[Any] = None				,				_lowerCAmelCase  :		Tuple = None				,				_lowerCAmelCase  :		int = None				,				_lowerCAmelCase  :		Optional[int] = None				,				**_lowerCAmelCase  :		Any				,				):

       if audio is None and audio_target is None:
             raise ValueError('You must provide either `audio` or `audio_target` values.'						)

       if sampling_rate is not None:
             if sampling_rate != self.sampling_rate:
                   raise ValueError(
                       F"The model corresponding to this feature extractor: {self} was trained using a sampling rate of"
                       F" {self.sampling_rate}. Please make sure that the provided audio input was sampled with"
                       F" {self.sampling_rate} and not {sampling_rate}."						)
       else:
             logger.warning(
                 'It is strongly recommended to pass the ``sampling_rate`` argument to this function. '
                 'Failing to do so can result in silent errors that might be hard to debug.'						)

       if audio is not None:
             SCREAMING_SNAKE_CASE_							=			self._process_audio(
                 a_				,				a_				,				a_				,				a_				,				a_				,				a_				,				a_				,				a_				,				**a_				,				)
       else:
             SCREAMING_SNAKE_CASE_							=			None

       if audio_target is not None:
             SCREAMING_SNAKE_CASE_							=			self._process_audio(
                 a_				,				a_				,				a_				,				a_				,				a_				,				a_				,				a_				,				a_				,				**a_				,				)

             if inputs is None:
                   return inputs_target
             else:
                   SCREAMING_SNAKE_CASE_							=			inputs_target['''input_values''']
                   SCREAMING_SNAKE_CASE_							=			inputs_target.get('attention_mask'						)
                   if decoder_attention_mask is not None:
                         SCREAMING_SNAKE_CASE_							=			decoder_attention_mask

       return inputs



 def       lowerCAmelCase_  (							self  :		int				,				_lowerCAmelCase  :		Optional[int]				,				_lowerCAmelCase  :		Union[str, Any] = False				,				_lowerCAmelCase  :		Tuple = False				,				_lowerCAmelCase  :		Union[str, Any] = None				,				_lowerCAmelCase  :		Union[str, Any] = False				,				_lowerCAmelCase  :		Optional[int] = None				,				_lowerCAmelCase  :		Any = None				,				_lowerCAmelCase  :		List[Any] = None				,				**_lowerCAmelCase  :		int				,				):
       SCREAMING_SNAKE_CASE_							=			isinstance(a_				,				np.ndarray						) and len(speech.shape						) > 1
       if is_batched_numpy and len(speech.shape						) > 2:
             raise ValueError(F"Only mono-channel audio is supported for input to {self}"						)
       SCREAMING_SNAKE_CASE_							=			is_batched_numpy or (
           isinstance(a_				,				(list, tuple)						) and (isinstance(speech[0]				,				(np.ndarray, tuple, list)						))
       )

       if is_batched:
             SCREAMING_SNAKE_CASE_							=			[np.asarray(a_				,				dtype=np.floataa						) for speech in speech]
       elif not is_batched and not isinstance(a_				,				np.ndarray						):
             SCREAMING_SNAKE_CASE_							=			np.asarray(a_				,				dtype=np.floataa						)
       elif isinstance(a_				,				np.ndarray						) and speech.dtype is np.dtype(np.floataa						):
             SCREAMING_SNAKE_CASE_							=			speech.astype(np.floataa						)

       # always return batch
       if not is_batched:
             SCREAMING_SNAKE_CASE_							=			[speech]

       # needed to make pad() work on spectrogram inputs
       SCREAMING_SNAKE_CASE_							=			self.feature_size

       # convert into correct format for padding
       if is_target:
             SCREAMING_SNAKE_CASE_							=			[self._extract_mel_features(a_						) for waveform in speech]
             SCREAMING_SNAKE_CASE_							=			BatchFeature({'input_values': features}						)
             SCREAMING_SNAKE_CASE_							=			self.num_mel_bins
       else:
             SCREAMING_SNAKE_CASE_							=			BatchFeature({'input_values': speech}						)

       SCREAMING_SNAKE_CASE_							=			self.pad(
           a_				,				padding=a_				,				max_length=a_				,				truncation=a_				,				pad_to_multiple_of=a_				,				return_attention_mask=a_				,				**a_				,				)

       SCREAMING_SNAKE_CASE_							=			feature_size_hack

       # convert input values to correct format
       SCREAMING_SNAKE_CASE_							=			padded_inputs['''input_values''']
       if not isinstance(input_values[0]				,				np.ndarray						):
             SCREAMING_SNAKE_CASE_							=			[np.asarray(a_				,				dtype=np.floataa						) for array in input_values]
       elif (
           not isinstance(a_				,				np.ndarray						)
           and isinstance(input_values[0]				,				np.ndarray						)
           and input_values[0].dtype is np.dtype(np.floataa						)
       ):
             SCREAMING_SNAKE_CASE_							=			[array.astype(np.floataa						) for array in input_values]
       elif isinstance(a_				,				np.ndarray						) and input_values.dtype is np.dtype(np.floataa						):
             SCREAMING_SNAKE_CASE_							=			input_values.astype(np.floataa						)

       # convert attention_mask to correct format
       SCREAMING_SNAKE_CASE_							=			padded_inputs.get('attention_mask'						)
       if attention_mask is not None:
             SCREAMING_SNAKE_CASE_							=			[np.asarray(a_				,				dtype=np.intaa						) for array in attention_mask]

       # zero-mean and unit-variance normalization
       if not is_target and self.do_normalize:
             SCREAMING_SNAKE_CASE_							=			(
                 attention_mask
                 if self._get_padding_strategies(a_				,				max_length=a_						) is not PaddingStrategy.DO_NOT_PAD
                 else None
             )
             SCREAMING_SNAKE_CASE_							=			self.zero_mean_unit_var_norm(
                 padded_inputs['input_values']				,				attention_mask=a_				,				padding_value=self.padding_value						)

       if return_tensors is not None:
             SCREAMING_SNAKE_CASE_							=			padded_inputs.convert_to_tensors(a_						)

       return padded_inputs




 def       lowerCAmelCase_  (							self  :		Optional[int]						):
       SCREAMING_SNAKE_CASE_							=			super().to_dict()

       # Don't serialize these as they are derived from the other properties.
       SCREAMING_SNAKE_CASE_							=			['''window''', '''mel_filters''', '''sample_size''', '''sample_stride''', '''n_fft''', '''n_freqs''']
       for name in names:
             if name in output:
                   del output[name]

       return output



"""simple docstring"""
import inspect
import unittest

from transformers import ConvNextVaConfig
from transformers.models.auto import get_values
from transformers.models.auto.modeling_auto import MODEL_FOR_BACKBONE_MAPPING_NAMES, MODEL_MAPPING_NAMES
from transformers.testing_utils import require_torch, require_vision, slow, torch_device
from transformers.utils import cached_property, is_torch_available, is_vision_available

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
			import torch

			from transformers import ConvNextVaBackbone, ConvNextVaForImageClassification, ConvNextVaModel
			from transformers.models.convnextva.modeling_convnextva import CONVNEXTV2_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
			from PIL import Image

			from transformers import AutoImageProcessor



class 			_UpperCAmelCase :






		'''simple docstring'''

		def __init__(self				,       a_				,       a_=13				,       a_=32				,       a_=3				,       a_=4				,       a_=[10, 20, 30, 40]				,       a_=[2, 2, 3, 2]				,       a_=True				,       a_=True				,       a_=37				,       a_="gelu"				,       a_=10				,       a_=0.02				,       a_=["stage2", "stage3", "stage4"]				,       a_=[2, 3, 4]				,       a_=None				,       ):





			'''simple docstring'''

			__snake_case	:						List[str]						=				parent
			__snake_case	:						str						=				batch_size
			__snake_case	:						List[Any]						=				image_size
			__snake_case	:						List[Any]						=				num_channels
			__snake_case	:						str						=				num_stages
			__snake_case	:						Any						=				hidden_sizes
			__snake_case	:						Optional[int]						=				depths
			__snake_case	:						Dict						=				is_training
			__snake_case	:						Tuple						=				use_labels
			__snake_case	:						str						=				intermediate_size
			__snake_case	:						Optional[int]						=				hidden_act
			__snake_case	:						Dict						=				num_labels
			__snake_case	:						Tuple						=				initializer_range
			__snake_case	:						Dict						=				out_features
			__snake_case	:						Optional[int]						=				out_indices
			__snake_case	:						str						=				scope



		def 				SCREAMING_SNAKE_CASE  (self					):





			'''simple docstring'''

			__snake_case	:						Optional[Any]						=				floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]					)

			__snake_case	:						str						=				None
			if self.use_labels:
				__snake_case	:						Any						=				ids_tensor([self.batch_size]				,       self.num_labels					)

			__snake_case	:						Dict						=				self.get_config()

			return config, pixel_values, labels



		def 				SCREAMING_SNAKE_CASE  (self					):





			'''simple docstring'''

			return ConvNextVaConfig(
			    num_channels=self.num_channels				,       hidden_sizes=self.hidden_sizes				,       depths=self.depths				,       num_stages=self.num_stages				,       hidden_act=self.hidden_act				,       is_decoder=a_				,       initializer_range=self.initializer_range				,       out_features=self.out_features				,       out_indices=self.out_indices				,       num_labels=self.num_labels				,       )



		def 				SCREAMING_SNAKE_CASE  (self				,       a_				,       a_				,       a_					):





			'''simple docstring'''

			__snake_case	:						Optional[int]						=				ConvNextVaModel(config=a_					)
			model.to(a_					)
			model.eval()
			__snake_case	:						Any						=				model(a_					)
			# expected last hidden states: B, C, H // 32, W // 32
			self.parent.assertEqual(
			    result.last_hidden_state.shape				,       (self.batch_size, self.hidden_sizes[-1], self.image_size // 32, self.image_size // 32)				,       )



		def 				SCREAMING_SNAKE_CASE  (self				,       a_				,       a_				,       a_					):





			'''simple docstring'''

			__snake_case	:						Any						=				ConvNextVaForImageClassification(a_					)
			model.to(a_					)
			model.eval()
			__snake_case	:						Union[str, Any]						=				model(a_				,       labels=a_					)
			self.parent.assertEqual(result.logits.shape				,       (self.batch_size, self.num_labels)					)



		def 				SCREAMING_SNAKE_CASE  (self				,       a_				,       a_				,       a_					):





			'''simple docstring'''

			__snake_case	:						Dict						=				ConvNextVaBackbone(config=a_					)
			model.to(a_					)
			model.eval()
			__snake_case	:						Tuple						=				model(a_					)

			# verify hidden states
			self.parent.assertEqual(len(result.feature_maps					)				,       len(config.out_features					)					)
			self.parent.assertListEqual(list(result.feature_maps[0].shape					)				,       [self.batch_size, self.hidden_sizes[1], 4, 4]					)

			# verify channels
			self.parent.assertEqual(len(model.channels					)				,       len(config.out_features					)					)
			self.parent.assertListEqual(model.channels				,       config.hidden_sizes[1:]					)

			# verify backbone works with out_features=None
			__snake_case	:						str						=				None
			__snake_case	:						Optional[Any]						=				ConvNextVaBackbone(config=a_					)
			model.to(a_					)
			model.eval()
			__snake_case	:						Tuple						=				model(a_					)

			# verify feature maps
			self.parent.assertEqual(len(result.feature_maps					)				,       1					)
			self.parent.assertListEqual(list(result.feature_maps[0].shape					)				,       [self.batch_size, self.hidden_sizes[-1], 1, 1]					)

			# verify channels
			self.parent.assertEqual(len(model.channels					)				,       1					)
			self.parent.assertListEqual(model.channels				,       [config.hidden_sizes[-1]]					)



		def 				SCREAMING_SNAKE_CASE  (self					):





			'''simple docstring'''

			__snake_case	:						int						=				self.prepare_config_and_inputs()
			__snake_case	,							__snake_case	,							__snake_case	:						Union[str, Any]						=				config_and_inputs
			__snake_case	:						Any						=				{'''pixel_values''': pixel_values}
			return config, inputs_dict



		def 				SCREAMING_SNAKE_CASE  (self					):





			'''simple docstring'''

			__snake_case	:						int						=				self.prepare_config_and_inputs()
			__snake_case	,							__snake_case	,							__snake_case	:						Union[str, Any]						=				config_and_inputs
			__snake_case	:						Optional[int]						=				{'''pixel_values''': pixel_values, '''labels''': labels}
			return config, inputs_dict



@require_torch
class 			_UpperCAmelCase (							__snake_case,				__snake_case,				unittest.TestCase				):






		'''simple docstring'''

		lowerCamelCase__				=(
		    (
		        ConvNextVaModel,
		        ConvNextVaForImageClassification,
		        ConvNextVaBackbone,
		    )
		    if is_torch_available()
		    else ()
		)
		lowerCamelCase__				=(
		    {'feature-extraction': ConvNextVaModel, 'image-classification': ConvNextVaForImageClassification}
		    if is_torch_available()
		    else {}
		)

		lowerCamelCase__				=False
		lowerCamelCase__				=False
		lowerCamelCase__				=False
		lowerCamelCase__				=False
		lowerCamelCase__				=False



		def 				SCREAMING_SNAKE_CASE  (self					):





			'''simple docstring'''

			__snake_case	:						Dict						=				ConvNextVaModelTester(self					)
			__snake_case	:						Union[str, Any]						=				ConfigTester(self				,       config_class=a_				,       has_text_modality=a_				,       hidden_size=37					)



		def 				SCREAMING_SNAKE_CASE  (self					):





			'''simple docstring'''

			self.create_and_test_config_common_properties()
			self.config_tester.create_and_test_config_to_json_string()
			self.config_tester.create_and_test_config_to_json_file()
			self.config_tester.create_and_test_config_from_and_save_pretrained()
			self.config_tester.create_and_test_config_with_num_labels()
			self.config_tester.check_config_can_be_init_without_params()
			self.config_tester.check_config_arguments_init()



		def 				SCREAMING_SNAKE_CASE  (self					):





			'''simple docstring'''

			return



		@unittest.skip(reason='''ConvNextV2 does not use inputs_embeds'''					)
		def 				SCREAMING_SNAKE_CASE  (self					):





			'''simple docstring'''

			pass



		@unittest.skip(reason='''ConvNextV2 does not support input and output embeddings'''					)
		def 				SCREAMING_SNAKE_CASE  (self					):





			'''simple docstring'''

			pass



		@unittest.skip(reason='''ConvNextV2 does not use feedforward chunking'''					)
		def 				SCREAMING_SNAKE_CASE  (self					):





			'''simple docstring'''

			pass



		def 				SCREAMING_SNAKE_CASE  (self					):





			'''simple docstring'''

			if not self.model_tester.is_training:
				return

			for model_class in self.all_model_classes:
				__snake_case	,							__snake_case	:						str						=				self.model_tester.prepare_config_and_inputs_with_labels()
				__snake_case	:						int						=				True

				if model_class.__name__ in [
				    *get_values(a_					),
				    *get_values(a_					),
				]:
					continue

				__snake_case	:						Dict						=				model_class(a_					)
				model.to(a_					)
				model.train()
				__snake_case	:						Tuple						=				self._prepare_for_class(a_				,       a_				,       return_labels=a_					)
				__snake_case	:						List[str]						=				model(**a_					).loss
				loss.backward()



		def 				SCREAMING_SNAKE_CASE  (self					):





			'''simple docstring'''

			if not self.model_tester.is_training:
				return

			for model_class in self.all_model_classes:
				__snake_case	,							__snake_case	:						Optional[Any]						=				self.model_tester.prepare_config_and_inputs_with_labels()
				__snake_case	:						Optional[Any]						=				False
				__snake_case	:						Tuple						=				True

				if (
				    model_class.__name__
				    in [*get_values(a_					), *get_values(a_					)]
				    or not model_class.supports_gradient_checkpointing
				):
					continue

				__snake_case	:						Union[str, Any]						=				model_class(a_					)
				model.to(a_					)
				model.gradient_checkpointing_enable()
				model.train()
				__snake_case	:						str						=				self._prepare_for_class(a_				,       a_				,       return_labels=a_					)
				__snake_case	:						Union[str, Any]						=				model(**a_					).loss
				loss.backward()



		def 				SCREAMING_SNAKE_CASE  (self					):





			'''simple docstring'''

			__snake_case	,							__snake_case	:						Optional[Any]						=				self.model_tester.prepare_config_and_inputs_for_common()

			for model_class in self.all_model_classes:
				__snake_case	:						Optional[Any]						=				model_class(a_					)
				__snake_case	:						int						=				inspect.signature(model.forward					)
				# signature.parameters is an OrderedDict => so arg_names order is deterministic
				__snake_case	:						int						=				[*signature.parameters.keys()]

				__snake_case	:						Any						=				['''pixel_values''']
				self.assertListEqual(arg_names[:1]				,       a_					)



		def 				SCREAMING_SNAKE_CASE  (self					):





			'''simple docstring'''

			__snake_case	:						str						=				self.model_tester.prepare_config_and_inputs()
			self.model_tester.create_and_check_model(*a_					)



		def 				SCREAMING_SNAKE_CASE  (self					):





			'''simple docstring'''

			def check_hidden_states_output(a_				,       a_				,       a_					):
				__snake_case	:						Tuple						=				model_class(a_					)
				model.to(a_					)
				model.eval()

				with torch.no_grad():
					__snake_case	:						Union[str, Any]						=				model(**self._prepare_for_class(a_				,       a_					)					)

				__snake_case	:						Union[str, Any]						=				outputs.encoder_hidden_states if config.is_encoder_decoder else outputs.hidden_states

				__snake_case	:						List[Any]						=				self.model_tester.num_stages
				self.assertEqual(len(a_					)				,       expected_num_stages + 1					)

				# ConvNextV2's feature maps are of shape (batch_size, num_channels, height, width)
				self.assertListEqual(
				    list(hidden_states[0].shape[-2:]					)				,       [self.model_tester.image_size // 4, self.model_tester.image_size // 4]				,       )

			__snake_case	,							__snake_case	:						List[Any]						=				self.model_tester.prepare_config_and_inputs_for_common()

			for model_class in self.all_model_classes:
				__snake_case	:						str						=				True
				check_hidden_states_output(a_				,       a_				,       a_					)

				# check that output_hidden_states also work using config
				del inputs_dict["output_hidden_states"]
				__snake_case	:						str						=				True

				check_hidden_states_output(a_				,       a_				,       a_					)



		def 				SCREAMING_SNAKE_CASE  (self					):





			'''simple docstring'''

			__snake_case	:						str						=				self.model_tester.prepare_config_and_inputs()
			self.model_tester.create_and_check_for_image_classification(*a_					)



		@slow
		def 				SCREAMING_SNAKE_CASE  (self					):





			'''simple docstring'''

			for model_name in CONVNEXTV2_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
				__snake_case	:						str						=				ConvNextVaModel.from_pretrained(a_					)
				self.assertIsNotNone(a_					)






def 		lowercase							(     )     ->Any:
	"""simple docstring"""





	__snake_case	:						List[str]						=				Image.open('''./tests/fixtures/tests_samples/COCO/000000039769.png'''     )
	return image



@require_torch
@require_vision
class 			_UpperCAmelCase (							unittest.TestCase				):






		'''simple docstring'''

		@cached_property
		def 				SCREAMING_SNAKE_CASE  (self					):





			'''simple docstring'''

			return AutoImageProcessor.from_pretrained('''facebook/convnextv2-tiny-1k-224'''					) if is_vision_available() else None



		@slow
		def 				SCREAMING_SNAKE_CASE  (self					):





			'''simple docstring'''

			__snake_case	:						str						=				ConvNextVaForImageClassification.from_pretrained('''facebook/convnextv2-tiny-1k-224'''					).to(a_					)

			__snake_case	:						Dict						=				self.default_image_processor
			__snake_case	:						Tuple						=				prepare_img()
			__snake_case	:						Tuple						=				preprocessor(images=a_				,       return_tensors='''pt'''					).to(a_					)

			# forward pass
			with torch.no_grad():
				__snake_case	:						Union[str, Any]						=				model(**a_					)

			# verify the logits
			__snake_case	:						Tuple						=				torch.Size((1, 10_00)					)
			self.assertEqual(outputs.logits.shape				,       a_					)

			__snake_case	:						Any						=				torch.tensor([0.9996, 0.1966, -0.4386]					).to(a_					)
			self.assertTrue(torch.allclose(outputs.logits[0, :3]				,       a_				,       atol=1E-4					)					)





