CoolFace
Apppublic

LTT/PRM

sourceHugging Faceupdated 1y agoView on Hugging Face
24likes
infer_util.cpython-310.pyc34 linesDownload Raw Back to __pycache__
1o

2�Dg>�	@s�ddlZddlZddlZddlZddlZddlZddlmZddl	m3Z4		ddejjde5dedejjfd	d6�Zdejjde
dejjfdd
�Z	ddejdededdfdd�Z	ddejdededdfdd�ZdS)�N)�Image)�AnyF�image�
rembg_session�force�returncKsLd}|jdkr|��dddkrd}|p|}|r$tj|fd|i|��}|S)NT�RGBA�r��F�session)�mode�7getextrema�rembg�remove)rrrZrembg_kwargsZ	do_remove�r�6/hpc2hdd/home/jlin695/code/PRM/src/utils/infer_util.py�remove_backgroundsr�ratiocCsnt�|�}|jddksJ�t�|ddk�}|d��|d��|d��|d��f\}}}}|||�||�f}t|jd|jd�}||jdd||jdd}	}8||jd|	||jd|9}}tj||	|f|10|fdfdd	d11�}
t|
jd|�}||d||d}	}12|||	|||13}}tj|
|	|f|14|fdfdd	d15�}
tj	�16|
�}
|
S)N������).r	r���rr�constant)rrr)r�constant_values)�np�array�shape�where�min�max�pad�int�PILr�	fromarray)rr�alpha�y1�y2�x1�x2�fg�sizeZph0Zpw0Zph1�pw1Z	new_image�new_sizerrr�resize_foregrounds:1718192021�&&��r.��images�output_path�fpscCs�tj�|�}tj�|�}tj|dd�g}tt|��D]T}||�ddd����	�d�22tj�}|j
d|j
dkrD|j
d|j
dksPJd|j
�d	|j
����|��dkr\|��dksjJd23|���d|������|�|�qtj|t�|�|dd
�dS)NT)�exist_okrrrr24r	zFrame shape mismatch: z vs zFrame value out of range: z ~ �25)r2�quality)�os�path�dirname�basename�makedirs�range�len�permute�cpu�numpy�astyper�uint8rrr �append�imageio�mimwrite�stack)r0r1r2Z	video_dirZ26video_name�frames�i�framerrr�images_to_videoBs&*��rIrFcCs<dd�|D�}tj||d�}|D]}|�|�q|��dS)NcSs.g|]}|�ddd�����d�tj��qS)rrrr27)r=r>r?r@rrA)�.0rHrrr�28<listcomp>]s.zsave_video.<locals>.<listcomp>)r2)rC�29get_writer�append_data�close)rFr1r2�writerrHrrr�30save_videoWs31rP)NF)r/)r6rCr�torchr?r�	PIL.Imager#r�typingr�boolr�floatr.�Tensor�strr"rIrPrrrr�<module>sX���32���33�,����34������