CoolFace
Apppublic

undercovercd/Swap-Face-Model

sourceHugging Facemitupdated 3y agoView on Hugging Face
0likes
transforms.cpython-39.pyc84 linesDownload Raw Back to __pycache__
1a

2��e�@sBddlZddlZddlZdd�Zd
dd�Zddd	�Zddd�ZdS)�NcCsp|��}|jdvrZ|jd|jd}}||||}}|d||�d||�df}ntd|j�d���|S)z�Mod crop images, used during testing.3 4    Args:5        img (ndarray): Input image.6        scale (int): Scale factor.7 8    Returns:9        ndarray: Result image.10    )��r�N.zWrong img ndim: �.)�copy�ndim�shape�11ValueError)�img�scale�h�wZh_remainderZw_remainder�r�'D:\face swap\basicsr\data\transforms.py�mod_crops1213 rc14st|t�s|g}t|t�s |g}t�|d�r2dnd}|dkrp|d��dd�\}}|d��dd�\}}	n,|djdd�\}}|djdd�\}}	�|�|||ks�|	||kr�td|�d|	�d	|�d15�d|�d|�d���|�ks�|�k�r"td
|�d|�d��d��d|�d���t�d|���t�d|���|dk�rd���fdd�|D�}n���fdd�|D�}t	�|�t	�|���|dk�r����fdd�|D�}n���fdd�|D�}t16|�dk�r�|d}t17|�dk�r�|d}||fS)aePaired random crop. Support Numpy array and Tensor inputs.18 19    It crops lists of lq and gt images with corresponding locations.20 21    Args:22        img_gts (list[ndarray] | ndarray | list[Tensor] | Tensor): GT images. Note that all images23            should have the same shape. If the input is an ndarray, it will24            be transformed to a list containing itself.25        img_lqs (list[ndarray] | ndarray): LQ images. Note that all images26            should have the same shape. If the input is an ndarray, it will27            be transformed to a list containing itself.28        gt_patch_size (int): GT patch size.29        scale (int): Scale factor.30        gt_path (str): Path to ground-truth. Default: None.31 32    Returns:33        list[ndarray] | ndarray: GT images and LQ images. If returned results34            only have one element, just return ndarray.35    r�TensorZNumpy�����NrzScale mismatches. GT (z, z	) is not zx zmultiplication of LQ (z).zLQ (z) is smaller than patch size (z). Please remove rc	s4g|],}|dd�dd���������f�qS�Nr��.0�v��left�
lq_patch_size�toprr�36<listcomp>M�z&paired_random_crop.<locals>.<listcomp>cs*g|]"}|��������df�qS�.rrrrrrOrc	s4g|],}|dd�dd���������f�qSrrr��
gt_patch_size�left_gt�top_gtrrrTrcs*g|]"}|��������df�qSrrrrrrrVrr)�37isinstance�list�torch�	is_tensor�sizerr	�random�randint�int�len)38Zimg_gtsZimg_lqsrr�gt_path�39input_typeZh_lqZw_lq�h_gt�w_gtr)rrr rrr!r�paired_random_cropsJ4041����424344r/TFcs��ot��dk�|ot��dk�|o.t��dk����fdd�����fdd��t|t�s`|g}�fdd�|D�}t|�dkr�|d	}|d45ur�t|t�s�|g}�fdd�|D�}t|�dkr�|d	}||fS|r�|���ffS|Sd46S)amAugment: horizontal flips OR rotate (0, 90, 180, 270 degrees).47 48    We use vertical flip and transpose for rotation implementation.49    All the images in the list use the same augmentation.50 51    Args:52        imgs (list[ndarray] | ndarray): Images to be augmented. If the input53            is an ndarray, it will be transformed to a list.54        hflip (bool): Horizontal flip. Default: True.55        rotation (bool): Ratotation. Default: True.56        flows (list[ndarray]: Flows to be augmented. If the input is an57            ndarray, it will be transformed to a list.58            Dimension is (h, w, 2). Default: None.59        return_status (bool): Return the status of flip and rotation.60            Default: False.61 62    Returns:63        list[ndarray] | ndarray: Augmented images and flows. If returned64            results only have one element, just return ndarray.65 66    g�?cs:�rt�|d|��r$t�|d|��r6|�ddd�}|S)Nrrr��cv2�flip�	transpose)r67��hflip�rot90�vfliprr�_augmentxszaugment.<locals>._augmentcs��r0t�|d|�|dd�dd�dfd9<�r`t�|d|�|dd�dd�dfd9<�r�|�ddd�}|dd�dd�ddgf}|S)Nrr�����rr0)�flowr4rr�
_augment_flow�szaugment.<locals>._augment_flowcsg|]}�|��qSrr)rr68)r8rrr�rzaugment.<locals>.<listcomp>rrNcsg|]}�|��qSrr)rr:)r;rrr�r)r'r"r#r*)�imgsr5�rotation�flowsZ
return_statusr)r8r;r5r6r7r�augment^s(	6970r?��?cCsN|jdd�\}}|dur*|d|df}t�|||�}t�||||f�}|S)aRotate image.71 72    Args:73        img (ndarray): Image to be rotated.74        angle (float): Rotation angle in degrees. Positive values mean75            counter-clockwise rotation.76        center (tuple[int]): Rotation center. If the center is None,77            initialize it as the center of the image. Default: None.78        scale (float): Isotropic scale factor. Default: 1.0.79    Nr)rr1�getRotationMatrix2D�80warpAffine)r81�angle�centerrrr
�matrixZrotated_imgrrr�82img_rotate�srF)N)TTNF)Nr@)r1r'r$rr/r?rFrrrr�<module>s83D84C