U
    h$                     @   s   d Z ddlmZ dgZddlZddlZddlZddlmZm	Z	 dd d	D Z
d
ZdZdd Zdd ZejdddfddZdS )zp
This code file mainly comes from https://github.com/dmlc/gluon-cv/blob/master/gluoncv/model_zoo/model_store.py
    )print_functionget_model_fileN   )download
check_sha1c                 C   s   i | ]\}}||qS  r   ).0Zchecksumnamer   r   E/tmp/pip-unpacked-wheel-5oclok7i/insightface/model_zoo/model_store.py
<dictcomp>   s    r   ))Z(95be21b58e29e9c1237f229dae534bd854009ce0Zarcface_r100_v1) Zarcface_mfn_v1)Z(39fd1e087a2a2ed70a154ac01fecaa86c315d01bZretinaface_r50_v1)Z(2c9de8116d1f448fd1d4661f90308faae34c990aZretinaface_mnet025_v1)Z(0db1d07921d005e6c9a5b38e059452fc5645e5a4Zretinaface_mnet025_v2)Z(7dd8111652b7aac2490c5dcddeb268e53ac643e6Zgenderage_v1zhttps://insightface.ai/files/z {repo_url}models/{file_name}.zipc                 C   s(   | t krtdj| dt |  d d S )Nz-Pretrained model for {name} is not available.r	      )_model_sha1
ValueErrorformatr   r   r   r
   
short_hash   s
    
r   c                 C   s>   t j| sd S td|  }t|dkr.d S t|}|d S )Nz%s/*.paramsr   )ospathexistsgloblensorted)dir_pathpathsr   r   r
   find_params_file$   s    r   ~z.insightfacemodelsc           	   	   C   s  | }t j|}t j|| }t|}t|  }|dk	rNt||rD|S td ntd t j|slt 	| t j|st 	| t j||d }t
}|d dkr|d }ttj||d|dd	 t|}|| W 5 Q R X t | t|}t||r|S td
dS )a  Return location for the pretrained on local file system.

    This function will download from online model zoo when model cannot be found or has mismatch.
    The root directory will be created if it doesn't exist.

    Parameters
    ----------
    name : str
        Name of the model.
    root : str, default '~/.mxnet/models'
        Location for keeping the model parameters.

    Returns
    -------
    file_path
        Path to the requested pretrained model file.
    NzBMismatch in the content of model file detected. Downloading again.z%Model file is not found. Downloading.z.zipr   /)repo_url	file_nameT)r   	overwritez5Downloaded file has different hash. Please try again.)r   r   
expanduserjoinr   r   r   printr   makedirsbase_repo_urlr   _url_formatr   zipfileZipFile
extractallremover   )	r	   rootr!   r   	file_pathZ	sha1_hashZzip_file_pathr    zfr   r   r
   r   .   sB    



)__doc__
__future__r   __all__r   r)   r   utilsr   r   r   r'   r(   r   r   r   r$   r   r   r   r   r
   <module>   s   
