o
    ߥi>                  	   @   s   d dl Z d dlmZ d dlmZmZmZmZmZ d dl	Z	d dl
Zd dlZ	ddeeef dee deeef fddZd	ejdejfd
dZd	ejdeeeef  dejfddZdS )    N)Path)AnyDictListOptionalUnion	file_pathrename_in_layersreturnc           	      C   sl   t j| dd d}|dur4|d }i }| D ]\}}| D ]\}}t|||}q|||< q||d< |S )zLoads PyTorch checkpoint, optionally renaming layer names.
    Args:
        file_path: path to the torch checkpoint.
        rename_in_layers: {from_name: to_name}
            ex: {"model.0.": "",
                 "model.": ""}
    Returns:
    c                 S   s   | S N )storagelocr   r   i/home/ubuntu/.local/lib/python3.10/site-packages/modelscope/models/cv/skin_retouching/retinaface/utils.py<lambda>   s    z!load_checkpoint.<locals>.<lambda>)map_locationN
state_dict)torchloaditemsresub)	r   r	   
checkpointmodel_state_dictresultkeyvaluekey_rvalue_rr   r   r   load_checkpoint   s   

r   imagec                 C   s   t | d} t| S )N)   r      )np	transposer   
from_numpy)r    r   r   r   tensor_from_rgb_image'   s   
r&   annotationsc              	   C   s   |   }|D ]K}|d }g d}t|D ]\}\}}tj|||fd|| dd}q|d \}	}
}}t|	d|d }	t|
d|d }
tj||	|
f||fdd	d
}q|S )N	landmarks))   r   r   )   r)   r   )r)      f   )r,   r*   r)   )r   r)   r)      )radiuscolor	thicknessbboxr   r"   )r   r)   r   r!   )r/   r0   )copy	enumeratecv2circler#   clip	rectangle)r    r'   	vis_image
annotationr(   colorslandmark_idxyx_miny_minx_maxy_maxr   r   r   vis_annotations,   s(   rB   r   )r   pathlibr   typingr   r   r   r   r   r4   numpyr#   r   strdictr   ndarrayTensorr&   rB   r   r   r   r   <module>   s$   

