CoolFace
Apppublic

XaviXva/Video-LLaVA

sourceHugging Faceapache-2.0updated 3y agoView on Hugging Face
0likes
processing_depth.cpython-310.pyc40 linesDownload Raw Back to __pycache__
1o

2� e��@s�ddlZddlZddlmZddlmZddlmZddlmZm	Z	ddl3mZdZdZ
d	d4�Zdd�ZGd
d�dej�Zdd�Zdd�ZGdd�de�ZdS)�N)�Image)�nn)�5transforms)�ProcessorMixin�
BatchEncoding)�BatchFeature)g3<�4'��?gwg��M�?gy{�� �?)g��B�91�?g�w�t.��?g��	U��?cCst|t�s|gS|S�N)�6isinstance�list)�x�r�ND:\LLaVA\llava\model\multimodal_encoder\languagebind\depth\processing_depth.py�make_list_of_imagess7rcCst�|tj��d�S)N�float32)�cv2�imread�IMREAD_UNCHANGED�astype)�pathrrr
�
opencv_loadersrcs*eZdZ		d�fdd�	Zdd�Z�ZS)�	DepthNormr�{�G�z�?cs t���||_||_d|_dS)Ng@�@)�super�__init__�	max_depth�	min_depth�scale)�selfrr��	__class__rr
rs89zDepthNorm.__init__cCsp||j}|j|jd�}|jdkr|j|jd�}||j}n||��}t�|��d��ddd�}|�	t�10��S)N)�minr)�max��)r�cliprrr!�torch�11from_numpy�	unsqueeze�repeat�to�get_default_dtype)r�imageZ	depth_imgrrr
�forward s1213zDepthNorm.forward)rr)�__name__�14__module__�__qualname__rr,�
__classcell__rrrr
rs15�16rc	Cs@|j}t�t|jd�tjdtjjd�t�d�t�	t17t�g�}|S)N)r��)�
interpolation)�
vision_configr�Composerr�Resize�InterpolationMode�BICUBIC�18CenterCrop�	Normalize�OPENAI_DATASET_MEAN�OPENAI_DATASET_STD)�config�	transformrrr
�get_depth_transform,s1920��r>cCst|�}||�}|Sr)r)Z21depth_pathr=�depthZ
depth_outputsrrr
�load_and_transform_depth;sr@csDeZdZgZdZd
�fdd�	Zddd�Zdd	d22�Zddd�Z�Z	S)�LanguageBindDepthProcessor�LanguageBindDepthTokenizerNcs2t�jdi|��||_t|�|_t|_||_dS)Nr)rrr<r>r=r@�image_processor�	tokenizer)rr<rD�kwargsrrr
rDs232425z#LanguageBindDepthProcessor.__init__�Mcs�|dur|durtd��|dur�j|f|dd|d�|��}|dur4t|�}�fdd�|D�}t�|�}|durB|durB||d<|S|durH|Sd|iS)Nz?You have to specify either text or images. Both cannot be none.�26max_lengthT)rG�padding�27truncation�return_tensorscsg|]	}��|�j��qSr)rCr=)�.0r+�rrr
�28<listcomp>Usz7LanguageBindDepthProcessor.__call__.<locals>.<listcomp>�pixel_values)�29ValueErrorrDrr%�stack)r�images�text�context_lengthrJrE�encoding�image_featuresrrLr
�__call__Ks$��30z#LanguageBindDepthProcessor.__call__TcO�|jj|d|i|��S)z�31        This method forwards all its arguments to CLIPTokenizerFast's [`~PreTrainedTokenizer.batch_decode`]. Please32        refer to the docstring of this method for more information.33        �skip_special_tokens)rD�batch_decode�rrX�argsrErrr
rY`�z'LanguageBindDepthProcessor.batch_decodecOrW)z�34        This method forwards all its arguments to CLIPTokenizerFast's [`~PreTrainedTokenizer.decode`]. Please refer to35        the docstring of this method for more information.36        rX)rD�decoderZrrr
r]gr\z!LanguageBindDepthProcessor.decoder)NNrFN)T)37r-r.r/�38attributes�tokenizer_classrrVrYr]r0rrrr
rA@s3940rA)rr%�PILrr�torchvisionr�transformersrrZ#transformers.image_processing_utilsrr:r;rr�Modulerr>r@rArrrr
�<module>s