a
    ECCfÁ	  ã                   @   sJ   d dl Z d dlZ d dlZd dlmZ d dlZd dlmZ G dd„ dƒZdS )é    N)Únumpy_helper)Úonnx_operatorsc                   @   sH   e Zd Zdd„ Zejdœdd„Zdd„ Zdd	„ Zeje	j
d
œdd„ZdS )ÚOnnxProfilec                 C   s   d S )N© )Úselfr   r   úM/var/www/html/django/DPS/env/lib/python3.9/site-packages/thop/onnx_profile.pyÚ__init__
   s    zOnnxProfile.__init__)Úmodelc                 C   s^   |j j}d}|D ]H}zt |¡}|t |j¡7 }W q tyV } zW Y d }~qd }~0 0 q|S ©Nr   )ÚgraphÚinitializerr   Zto_arrayÚnpÚprodÚshapeÚ	Exception)r   r	   Zonnx_weightsÚparamsZonnx_wÚweightÚ_r   r   r   Úcalculate_params   s    
zOnnxProfile.calculate_paramsc           
      C   s  i }|D ]>}t  |j¡}||t|jƒ< |jdkrt  d|¡|t|jƒ< q|D ]r}t  |jjj	j
d j¡}g }|jjj	j
D ]}t  |t|jƒ¡}qx||t|jƒ< |jdkrLt  d|¡|t|jƒ< qL|D ]L}	t  |	jjj	j
d j¡}|g|t|	jƒ< |jdkrÄt  d|¡|t|	jƒ< qÄ|S )Né   r   )r   ÚarrayÚdimsÚstrÚnameÚsizeÚappendÚtypeZtensor_typer   ÚdimZ	dim_valueÚint)
r   r   ÚinputÚoutputÚdictionÚwr   ÚiÚkeyÚor   r   r   Úcreate_dict   s(    


zOnnxProfile.create_dictc                 C   s4   |j tvrtd|j dƒ dS t|j  }|||ƒS d S )NzSorry, we haven't add zinto dictionary.)r   NN)Zop_typer   Úprint)r   r!   ÚnodeÚfnr   r   r   Únodes_counter5   s
    

zOnnxProfile.nodes_counter)r	   Úreturnc                 C   st   d}i }|j j}|j j}|j j}|j j}|  |||¡}d}|D ]&}|  ||¡\}	}
}|
||< ||	7 }q>t |d ¡S r
   )	r   r   r(   r   r    r&   r*   r   r   )r   r	   ZmacsZ	name2dimsr   Únodesr   r    ÚnZmacs_addingZout_sizeÚoutnamer   r   r   Úcalculate_macs=   s    
zOnnxProfile.calculate_macsN)Ú__name__Ú
__module__Ú__qualname__r   ÚonnxZ
ModelProtor   r&   r*   ÚtorchZDoubleTensorr/   r   r   r   r   r   	   s
   r   )	r4   Ztorch.nnr3   r   Únumpyr   Zthop.vision.onnx_counterr   r   r   r   r   r   Ú<module>   s   