CoolFace
Apppublic

xdecoder/Instruct-X-Decoder

sourceHugging Faceafl-3.0updated 3y agoView on Hugging Face
163likes
ref_seg.cpython-38.pyc22 linesDownload Raw Back to __pycache__
1U

2E$�cL�@s�ddlZddlZddlmZddlmZddlmZddl	m3Z4ddlmZgZ
e
�ejdejd��e�e
�Ze�d	�Zd5d�ZdS)�N)�Image)�6transforms)�7Visualizer)�random_color)�MetadataCatalogi)�
interpolation�ade20k_panoptic_trainc	Os.t|j_|��}dd�|�d�D�}t|�}t����|jd}|jd}t�	|�}t�	|�}	t�8|����ddd��
�}9|10||d|id�g}|j�|d�}t|	td	�}
|dd11dk������}t|�D]4\}}tddd��tj���}|
j||||d
�}q�|��}W5QRXtj
��t�|�ddfS)NcSs(g|] }|�d�r|��n|dg�qS)�.)�endswith�strip)�.0�text�r�&/data/arXiv/demo/Demo/tasks/ref_seg.py�12<listcomp>sz*referring_segmentation.<locals>.<listcomp>�,r���texts)�image�height�width�13groundings)�metadata�grounding_maskT)�rgb�maximum)�colorr
�)r�modelr�split�	transform�torch�no_grad�size�np�asarray�14from_numpy�copy�permute�cuda�evaluate_groundingr�float�cpu�numpy�	enumerater�astype�int32�tolist�draw_binary_mask�	get_image�empty_cacher�	fromarray)rrr�inpainting_text�args�kwargs�	image_orirr�image_ori_np�images�batch_inputs�outputs�visual�grd_mask�idx�maskr�demo�resrrr�referring_segmentations(151617181920rE)r"r.r%�PILr�torchvisionr�utils.visualizerr�detectron2.utils.colormapr�detectron2.datar�t�append�Resize�BICUBIC�Composer!�getrrErrrr�<module>s2122