o
    e                     @   s   d dl Z d dlZd dlZd dlZd dlZd dlZd dlZdZdd Zdd Z	de
fdd	ZG d
d dejZG dd dZe	 ZeeZdS )    Nz)http://paddlepaddle.org.cn/paddlehub/statc                 C   s
   d | S )u    生成字符串。
    z'{}')format)param r   >D:\Projects\ConvertPro\env\Lib\site-packages\x2paddle/utils.pystring   s   
r   c                  C   sN   t j} | d\}}}|dkr|dkr|dks%t|dkr#t|dks%dS dS )N.0      FT)paddle__version__splitint)versionZv0v1v2r   r   r   check_version!   s   r   textc                 C   s   t |  }| S )z*Calculate the md5 value of the input text.)hashlibmd5encode	hexdigest)r   Zmd5coder   r   r   _md5+   s   r   c                   @   s,   e Zd ZdZ					dddZdd ZdS )	ConverterCheckz7
    Count the number of calls to model convertion
    ONNXNc                 C   sV   t j|  || _tj| _|| _|| _|| _	t
tt dd  d t| | _d S )Ni-)	threadingThread__init___taskx2paddler   _version_convert_state_lite_state_extra_infor   struuiduuid1_convert_id)selftaskZ	time_infoconvert_state
lite_stateZ
extra_infor   r   r   r   6   s   *zConverterCheck.__init__c                 C   s   | j | jtjdd}| j| jd}| jd ur|d| ji | jd ur)|| j |dt	
|i ztjtjd tjt|dd W d S  tyO   Y d S w )	Nr    )r*   Zx2paddle_versionZpaddle_versionfrom)r+   Z
convert_idr,   extra)levelr	   )timeout)r   r!   r   r   r"   r(   r#   updater$   jsondumpsloggingbasicConfigINFOrequestsget	stats_api	Exception)r)   paramsr.   r   r   r   runD   s*   

zConverterCheck.run)r   NNNN)__name__
__module____qualname____doc__r   r<   r   r   r   r   r   1   s    
r   c                   @   s   e Zd ZdddZdS )PaddleDtypesTc                 C   sX   |r(t j| _t j| _t j| _t j| _t j	| _
t j| _t j| _t j| _t j| _d S td)Nz1Paddle>=2.0.0 is required, Please update version!)r   Zfloat16Z	t_float16Zfloat32Z	t_float32Zfloat64Z	t_float64Zuint8Zt_uint8Zint8Zt_int8Zint16Zt_int16Zint32Zt_int32Zint64Zt_int64boolZt_boolr:   )r)   is_new_versionr   r   r   r   _   s   zPaddleDtypes.__init__N)T)r=   r>   r?   r   r   r   r   r   rA   ^   s    rA   )r   r    r   r7   r   r&   r2   r9   r   r   r%   r   r   r   rA   rC   Zpaddle_dtypesr   r   r   r   <module>   s   
-