o
    Zh                     @   sz   d Z ddlZddlmZmZmZ ddlmZ ddlm	Z	 ddl
mZmZmZmZmZ ddlmZ G d	d
 d
e	Zd
gZdS )z&
Image/Text processor class for FLAVA
    N)ListOptionalUnion   )
ImageInput)ProcessorMixin)BatchEncodingPaddingStrategyPreTokenizedInput	TextInputTruncationStrategy)
TensorTypec                (       s2  e Zd ZdZddgZdZdZd* fdd	Z					
	
								
	
	
	
			d+dee	 dee
eeee ee f  dede
eeef de
eeef dee dedee dee dee dee dee dedededededee
eef  f$ddZd d! Zd"d# Zed$d% Zed&d' Zed(d) Z  ZS ),FlavaProcessora  
    Constructs a FLAVA processor which wraps a FLAVA image processor and a FLAVA tokenizer into a single processor.

    [`FlavaProcessor`] offers all the functionalities of [`FlavaImageProcessor`] and [`BertTokenizerFast`]. See the
    [`~FlavaProcessor.__call__`] and [`~FlavaProcessor.decode`] for more information.

    Args:
        image_processor ([`FlavaImageProcessor`], *optional*): The image processor is a required input.
        tokenizer ([`BertTokenizerFast`], *optional*): The tokenizer is a required input.
    image_processor	tokenizerZFlavaImageProcessor)ZBertTokenizerZBertTokenizerFastNc                    sl   d }d|v rt dt |d}|d ur|n|}|d u r!td|d u r)tdt || | j| _d S )Nfeature_extractorzhThe `feature_extractor` argument is deprecated and will be removed in v5, use `image_processor` instead.z)You need to specify an `image_processor`.z"You need to specify a `tokenizer`.)	warningswarnFutureWarningpop
ValueErrorsuper__init__r   Zcurrent_processor)selfr   r   kwargsr   	__class__ Y/var/www/auris/lib/python3.10/site-packages/transformers/models/flava/processing_flava.pyr   ,   s   
zFlavaProcessor.__init__TFr   imagestextadd_special_tokenspadding
truncation
max_lengthstridepad_to_multiple_ofreturn_image_maskreturn_codebook_pixelsreturn_token_type_idsreturn_attention_maskreturn_overflowing_tokensreturn_special_tokens_maskreturn_offsets_mappingreturn_lengthverbosereturn_tensorsc                 K   s   |du r|du rt d|dur(| jd|||||||||||||||d|}|dur9| j|f|	|
|d|}|durH|durH|| |S |durN|S ttdi ||dS )a  
        This method uses [`FlavaImageProcessor.__call__`] method to prepare image(s) for the model, and
        [`BertTokenizerFast.__call__`] to prepare text for the model.

        Please refer to the docstring of the above two methods for more information.
        Nz?You have to specify either text or images. Both cannot be none.)r    r!   r"   r#   r$   r%   r&   r)   r*   r+   r,   r-   r.   r/   r0   )r'   r(   r0   )dataZtensor_typer   )r   r   r   updater   dict)r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r   encodingZimage_featuresr   r   r   __call__?   sL   
zFlavaProcessor.__call__c                 O      | j j|i |S )z
        This method forwards all its arguments to BertTokenizerFast's [`~PreTrainedTokenizer.batch_decode`]. Please
        refer to the docstring of this method for more information.
        )r   batch_decoder   argsr   r   r   r   r7         zFlavaProcessor.batch_decodec                 O   r6   )z
        This method forwards all its arguments to BertTokenizerFast's [`~PreTrainedTokenizer.decode`]. Please refer to
        the docstring of this method for more information.
        )r   decoder8   r   r   r   r;      r:   zFlavaProcessor.decodec                 C   s"   | j j}| jj}tt|| S )N)r   model_input_namesr   listr3   fromkeys)r   Ztokenizer_input_namesZimage_processor_input_namesr   r   r   r<      s   z FlavaProcessor.model_input_namesc                 C      t dt | jS )Nzg`feature_extractor_class` is deprecated and will be removed in v5. Use `image_processor_class` instead.)r   r   r   image_processor_classr   r   r   r   feature_extractor_class   
   z&FlavaProcessor.feature_extractor_classc                 C   r?   )Nz[`feature_extractor` is deprecated and will be removed in v5. Use `image_processor` instead.)r   r   r   r   rA   r   r   r   r      rC   z FlavaProcessor.feature_extractor)NN)NNTFFNr   NNNNNFFFFTN)__name__
__module____qualname____doc__
attributesr@   Ztokenizer_classr   r   r   r   r   r
   r   boolstrr	   r   intr   r5   r7   r;   propertyr<   rB   r   __classcell__r   r   r   r   r      s    	

D

r   )rG   r   typingr   r   r   Zimage_utilsr   Zprocessing_utilsr   Ztokenization_utils_baser   r	   r
   r   r   utilsr   r   __all__r   r   r   r   <module>   s    
