CoolFace
Apppublic

tawondazz/Mobile-Agent

sourceHugging Facemitupdated 2y agoView on Hugging Face
0likes
icon_localization.cpython-310.pyc19 linesDownload Raw Back to __pycache__
1o

2�{f�@sHddlmZmZddlmZddlmZddlZddd�Zdd	d3�Z	dS)
�)�calculate_size�
calculate_iou)�pipeline)�ImageN��?cs�t��tt|��D]U}t||�d|d|dkr ��|�tt|��D]7}t||�d|d|dkr=��|�||krBq&|�vsJ|�vrKq&t||||�}||kr]��|�q&q	�fdd�t|�D�}|S)N皙�����?r�csg|]4\}}|�vr|�qS�r	)�.0�idx�box�Zboxes_to_remover	�@E:\Desktop\Mobile-Agent-v2-demo\MobileAgent\icon_localization.py�5<listcomp>sz remove_boxes.<locals>.<listcomp>)�set�range�lenr�addr�	enumerate)�6boxes_filt�size�
iou_threshold�i�j�iour	r
r�remove_boxess$ 7 89��rrcCs.t�|�}|j}|��}|��}|�d�s|d}||||d�}||�}|d}	|d|d}10}t|	�d��D]7}|	|t�||11||12g�|	|<|	|dd�|	|dd�d8<|	|dd�|	|dd�7<q8|	�	��13���}	t|	|�}
g}|
D]}|�
|d|d|d|dg�q�|S)N�.)Z14IMAGE_PATHZTEXT_PROMPTZBOX_TRESHOLDZ
TEXT_TRESHOLD�boxesrr��)r�openr�lower�strip�endswithr�torch�Tensor�cpu�int�tolistr�append)Zinput_image_path�caption�groundingdino_modelZ
box_threshold�text_threshold�imager�inputs�resultr�H�WrZfiltered_boxes�coordinatesrr	r	r�dets01516�(&17$r3)r)rr)18�MobileAgent.croprr�modelscope.pipelinesr�PILrr$rr3r	r	r	r�<module>s19