§
    9²¸jÅ,  ã                   ó€   — d Z ddlZddlmZ ddlmZ ddlmZm	Z	m
Z
  e
j        e¦  «        Z G d„ de¦  «        ZdgZdS )	z&
Feature extractor class for Wav2Vec2
é    Né   )ÚSequenceFeatureExtractor)ÚBatchFeature)ÚPaddingStrategyÚ
TensorTypeÚloggingc                   óf  ‡ — e Zd ZdZddgZ	 	 	 	 	 dˆ fd	„	Ze	 ddeej	                 deej	                 d
e
deej	                 fd„¦   «         Z	 	 	 	 	 	 	 ddej	        ee
         z  eej	                 z  eee
                  z  deez  ez  dedz  dededz  dedz  deez  dz  dedz  defd„Zˆ xZS )ÚWav2Vec2FeatureExtractora  
    Constructs a Wav2Vec2 feature extractor.

    This feature extractor inherits from [`~feature_extraction_sequence_utils.SequenceFeatureExtractor`] which contains
    most of the main methods. Users should refer to this superclass for more information regarding those methods.

    Args:
        feature_size (`int`, *optional*, defaults to 1):
            The feature dimension of the extracted features.
        sampling_rate (`int`, *optional*, defaults to 16000):
            The sampling rate at which the audio files should be digitalized expressed in hertz (Hz).
        padding_value (`float`, *optional*, defaults to 0.0):
            The value that is used to fill the padding values.
        do_normalize (`bool`, *optional*, defaults to `True`):
            Whether or not to zero-mean unit-variance normalize the input. Normalizing can help to significantly
            improve the performance for some models, *e.g.*,
            [wav2vec2-lv60](https://huggingface.co/models?search=lv60).
        return_attention_mask (`bool`, *optional*, defaults to `False`):
            Whether or not [`~Wav2Vec2FeatureExtractor.__call__`] should return `attention_mask`.

            <Tip>

            Wav2Vec2 models that have set `config.feat_extract_norm == "group"`, such as
            [wav2vec2-base](https://huggingface.co/facebook/wav2vec2-base-960h), have **not** been trained using
            `attention_mask`. For such models, `input_values` should simply be padded with 0 and no `attention_mask`
            should be passed.

            For Wav2Vec2 models that have set `config.feat_extract_norm == "layer"`, such as
            [wav2vec2-lv60](https://huggingface.co/facebook/wav2vec2-large-960h-lv60-self), `attention_mask` should be
            passed for batched inference.

            </Tip>Úinput_valuesÚattention_maské   é€>  ç        FTc                 ó^   •—  t          ¦   «         j        d|||dœ|¤Ž || _        || _        d S )N)Úfeature_sizeÚsampling_rateÚpadding_value© )ÚsuperÚ__init__Úreturn_attention_maskÚdo_normalize)Úselfr   r   r   r   r   ÚkwargsÚ	__class__s          €úˆ/root/private/project/pallet_detection_v2/.venv/lib/python3.11/site-packages/transformers/models/wav2vec2/feature_extraction_wav2vec2.pyr   z!Wav2Vec2FeatureExtractor.__init__@   sC   ø€ ð 	�‰ŒÔÐw lÀ-Ð_lÐwÐwÐpvÐwÐwÐwØ%:ˆÔ"Ø(ˆÔÐÐó    r   Úreturnc                 ó´  — |�Ét          j        |t           j        ¦  «        }g }t          | |                     d¦  «        ¦  «        D ]ƒ\  }}||d|…                              ¦   «         z
  t          j        |d|…                              ¦   «         dz   ¦  «        z  }||j        d         k     r|||d…<   | 	                    |¦  «         Œ„nd„ | D ¦   «         }|S )z[
        Every array in the list is normalized to have zero mean and unit variance
        NéÿÿÿÿçH¯¼šò×z>r   c                 ó�   — g | ]C}||                      ¦   «         z
  t          j        |                     ¦   «         d z   ¦  «        z  ‘ŒDS )r!   )ÚmeanÚnpÚsqrtÚvar)Ú.0Úxs     r   ú
<listcomp>zDWav2Vec2FeatureExtractor.zero_mean_unit_var_norm.<locals>.<listcomp>_   s@   € Ð"bÐ"bÐ"bÐPQ A¨¯ª©¬¡LµB´G¸A¿EºE¹G¼GÀd¹NÑ4KÔ4KÑ#KÐ"bÐ"bÐ"br   )
r$   ÚarrayÚint32ÚzipÚsumr#   r%   r&   ÚshapeÚappend)r   r   r   Únormed_input_valuesÚvectorÚlengthÚnormed_slices          r   Úzero_mean_unit_var_normz0Wav2Vec2FeatureExtractor.zero_mean_unit_var_normM   só   € ð Ð%ÝœX nµb´hÑ?Ô?ˆNØ"$Ðå"% l°N×4FÒ4FÀrÑ4JÔ4JÑ"KÔ"Kð 9ð 9‘�˜Ø &¨°°°¬×)=Ò)=Ñ)?Ô)?Ñ ?Å2Ä7È6ÐRYÐSYÐRYÌ?×K^ÒK^ÑK`ÔK`ÐcgÑKgÑChÔChÑh�Ø˜LÔ.¨qÔ1Ò1Ð1Ø,9�L   Ñ)à#×*Ò*¨<Ñ8Ô8Ð8Ð8ð9ð #cÐ"bÐUaÐ"bÑ"bÔ"bÐà"Ð"r   NÚ
raw_speechÚpaddingÚ
max_lengthÚ
truncationÚpad_to_multiple_ofr   Úreturn_tensorsr   c	                 ó°  — |�2|| j         k    r&t          d| › d| j         › d| j         › d|› d�	¦  «        ‚n(t                               d| j        j        › d�¦  «         t          |t          j        ¦  «        ot          |j
        ¦  «        d	k    }
|
r*t          |j
        ¦  «        d
k    rt          d| › �¦  «        ‚|
pHt          |t          t          f¦  «        o,t          |d         t          j        t          t          f¦  «        }|s|g}t          d|i¦  «        }|                      ||||||¬¦  «        }|d         }t          |d         t          j        ¦  «        sd„ |D ¦   «         |d<   nÖt          |t          j        ¦  «        s[t          |d         t          j        ¦  «        r;|d         j        t          j        t          j        ¦  «        u rd„ |D ¦   «         |d<   nat          |t          j        ¦  «        rG|j        t          j        t          j        ¦  «        u r"|                     t          j        ¦  «        |d<   |                     d¦  «        }|�d„ |D ¦   «         |d<   | j        rM|                      ||¬¦  «        t,          j        ur|nd}|                      |d         || j        ¬¦  «        |d<   |�|                     |¦  «        }|S )a�  
        Main method to featurize and prepare for the model one or several sequence(s).

        Args:
            raw_speech (`np.ndarray`, `list[float]`, `list[np.ndarray]`, `list[list[float]]`):
                The sequence or batch of sequences to be padded. Each sequence can be a numpy array, a list of float
                values, a list of numpy arrays or a list of list of float values. Must be mono channel audio, not
                stereo, i.e. single float per timestep.
            padding (`bool`, `str` or [`~utils.PaddingStrategy`], *optional*, defaults to `False`):
                Select a strategy to pad the returned sequences (according to the model's padding side and padding
                index) among:

                - `True` or `'longest'`: Pad to the longest sequence in the batch (or no padding if only a single
                  sequence if provided).
                - `'max_length'`: Pad to a maximum length specified with the argument `max_length` or to the maximum
                  acceptable input length for the model if that argument is not provided.
                - `False` or `'do_not_pad'` (default): No padding (i.e., can output a batch with sequences of different
                  lengths).
            max_length (`int`, *optional*):
                Maximum length of the returned list and optionally padding length (see above).
            truncation (`bool`):
                Activates truncation to cut input sequences longer than *max_length* to *max_length*.
            pad_to_multiple_of (`int`, *optional*):
                If set will pad the sequence to a multiple of the provided value.

                This is especially useful to enable the use of Tensor Cores on NVIDIA hardware with compute capability
                `>= 7.5` (Volta), or on TPUs which benefit from having sequence lengths be a multiple of 128.
            return_attention_mask (`bool`, *optional*):
                Whether to return the attention mask. If left to the default, will return the attention mask according
                to the specific feature_extractor's default.

                [What are attention masks?](../glossary#attention-mask)

                <Tip>

                Wav2Vec2 models that have set `config.feat_extract_norm == "group"`, such as
                [wav2vec2-base](https://huggingface.co/facebook/wav2vec2-base-960h), have **not** been trained using
                `attention_mask`. For such models, `input_values` should simply be padded with 0 and no
                `attention_mask` should be passed.

                For Wav2Vec2 models that have set `config.feat_extract_norm == "layer"`, such as
                [wav2vec2-lv60](https://huggingface.co/facebook/wav2vec2-large-960h-lv60-self), `attention_mask` should
                be passed for batched inference.

                </Tip>

            return_tensors (`str` or [`~utils.TensorType`], *optional*):
                If set, will return tensors instead of list of python integers. Acceptable values are:

                - `'pt'`: Return PyTorch `torch.Tensor` objects.
                - `'np'`: Return Numpy `np.ndarray` objects.
            sampling_rate (`int`, *optional*):
                The sampling rate at which the `raw_speech` input was sampled. It is strongly recommended to pass
                `sampling_rate` at the forward call to prevent silent errors.
            padding_value (`float`, *optional*, defaults to 0.0):
        Nz3The model corresponding to this feature extractor: z& was trained using a sampling rate of zI. Please make sure that the provided `raw_speech` input was sampled with z	 and not ú.zDIt is strongly recommended to pass the `sampling_rate` argument to `zN()`. Failing to do so can result in silent errors that might be hard to debug.r   é   z2Only mono-channel audio is supported for input to r   r   )r6   r7   r8   r9   r   c                 óN   — g | ]"}t          j        |t           j        ¬ ¦  «        ‘Œ#S ©)Údtype)r$   ÚasarrayÚfloat32©r'   r*   s     r   r)   z5Wav2Vec2FeatureExtractor.__call__.<locals>.<listcomp>Ï   s*   € Ð,kÐ,kÐ,kÐUZ­R¬Z¸ÅRÄZÐ-PÑ-PÔ-PÐ,kÐ,kÐ,kr   c                 óL   — g | ]!}|                      t          j        ¦  «        ‘Œ"S r   )Úastyper$   rB   rC   s     r   r)   z5Wav2Vec2FeatureExtractor.__call__.<locals>.<listcomp>Õ   s&   € Ð,`Ð,`Ð,`È%¨U¯\ª\½"¼*Ñ-EÔ-EÐ,`Ð,`Ð,`r   r   c                 óN   — g | ]"}t          j        |t           j        ¬ ¦  «        ‘Œ#S r?   )r$   rA   r+   rC   s     r   r)   z5Wav2Vec2FeatureExtractor.__call__.<locals>.<listcomp>Ü   s*   € Ð.mÐ.mÐ.mÐUZ­r¬z¸%ÅrÄxÐ/PÑ/PÔ/PÐ.mÐ.mÐ.mr   )r7   )r   r   )r   Ú
ValueErrorÚloggerÚwarningr   Ú__name__Ú
isinstancer$   ÚndarrayÚlenr.   ÚlistÚtupler   Úpadr@   Úfloat64rE   rB   Úgetr   Ú_get_padding_strategiesr   Ú
DO_NOT_PADr4   r   Úconvert_to_tensors)r   r5   r6   r7   r8   r9   r   r:   r   r   Úis_batched_numpyÚ
is_batchedÚencoded_inputsÚpadded_inputsr   r   s                   r   Ú__call__z!Wav2Vec2FeatureExtractor.__call__c   sa  € ðJ Ð$Ø Ô 2Ò2Ð2Ý ðFÈ$ð Fð FØÔ*ðFð FàÔ*ðFð Fà5BðFð Fð Fñô ð ð 3õ �NŠNð\ÐW[ÔWeÔWnð \ð \ð \ñô ð õ
 & jµ"´*Ñ=Ô=Ð[Å#ÀjÔFVÑBWÔBWÐZ[ÒB[ÐØð 	Z¥ JÔ$4Ñ 5Ô 5¸Ò 9Ð 9ÝÐXÐRVÐXÐXÑYÔYÐYØ%ð 
Ý�z¥D­% =Ñ1Ô1ÐlµzÀ*ÈQÄ-ÕRTÔR\Õ^cÕeiÐQjÑ7kÔ7kð 	ð
 ð 	&Ø$˜ˆJõ & ~°zÐ&BÑCÔCˆàŸšØØØ!Ø!Ø1Ø"7ð !ñ 
ô 
ˆð % ^Ô4ˆÝ˜, qœ/­2¬:Ñ6Ô6ð 		LØ,kÐ,kÐ^jÐ,kÑ,kÔ,kˆM˜.Ñ)Ð)å˜<­¬Ñ4Ô4ð	Lå˜<¨œ?­B¬JÑ7Ô7ð	Lð ˜Q”Ô%­¬µ"´*Ñ)=Ô)=Ð=Ð=à,`Ð,`ÐS_Ð,`Ñ,`Ô,`ˆM˜.Ñ)Ð)Ý˜¥b¤jÑ1Ô1ð 	L°lÔ6HÍBÌHÕUWÔU_ÑL`ÔL`Ð6`Ð6`Ø,8×,?Ò,?ÅÄ
Ñ,KÔ,KˆM˜.Ñ)ð '×*Ò*Ð+;Ñ<Ô<ˆØÐ%Ø.mÐ.mÐ^lÐ.mÑ.mÔ.mˆMÐ*Ñ+ð Ôð 	ð ×/Ò/°ÀJÐ/ÑOÔOÕWfÔWqÐqÐqð �àð ð
 -1×,HÒ,HØ˜nÔ-¸nÐ\`Ô\nð -Iñ -ô -ˆM˜.Ñ)ð Ð%Ø)×<Ò<¸^ÑLÔLˆMàÐr   )r   r   r   FT)r   )FNFNNNN)rJ   Ú
__module__Ú__qualname__Ú__doc__Úmodel_input_namesr   ÚstaticmethodrN   r$   rL   Úfloatr4   ÚboolÚstrr   Úintr   r   rZ   Ú__classcell__)r   s   @r   r
   r
      s¦  ø€ € € € € ðð ðB (Ð)9Ð:Ðð ØØØ#Øð)ð )ð )ð )ð )ð )ð àadð#ð #Ø˜2œ:Ô&ð#Ø8<¸R¼ZÔ8Hð#ØY^ð#à	ˆbŒjÔ	ð#ð #ð #ñ „\ð#ð0 16Ø!%Ø Ø)-Ø-1Ø26Ø$(ðIð Ià”J  e¤Ñ,¨t°B´JÔ/?Ñ?À$ÀtÈEÄ{ÔBSÑSðIð ˜‘˜oÑ-ðIð ˜$‘Jð	Ið
 ðIð   $™JðIð  $ d™{ðIð ˜jÑ(¨4Ñ/ðIð ˜T‘zðIð 
ðIð Ið Ið Ið Ið Ið Ið Ir   r
   )r]   Únumpyr$   Ú!feature_extraction_sequence_utilsr   Úfeature_extraction_utilsr   Úutilsr   r   r   Ú
get_loggerrJ   rH   r
   Ú__all__r   r   r   ú<module>rk      sµ   ððð ð Ð Ð Ð à IÐ IÐ IÐ IÐ IÐ IØ 4Ð 4Ð 4Ð 4Ð 4Ð 4Ø 9Ð 9Ð 9Ð 9Ð 9Ð 9Ð 9Ð 9Ð 9Ð 9ð 
ˆÔ	˜HÑ	%Ô	%€ðPð Pð Pð Pð PÐ7ñ Pô Pð Pðf &Ð
&€€€r   