o
    ‹ÄŽiÁ	  ã                   @   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                   @   sJ   e Zd Zdd„ Zdejfdd„Zdd„ Zdd	„ Zdejd
e	j
fdd„ZdS )ÚOnnxProfilec                 C   s   d S )N© )Úselfr   r   úM/home/jeff/fluffinator/venv/lib/python3.10/site-packages/thop/onnx_profile.pyÚ__init__
   s   zOnnxProfile.__init__Úmodelc                 C   s\   |j j}d}|D ]#}zt |¡}|t |j¡7 }W q ty+ } zW Y d }~qd }~ww |S ©Nr   )ÚgraphÚinitializerr   Úto_arrayÚnpÚprodÚshapeÚ	Exception)r   r	   Úonnx_weightsÚparamsÚ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 ]9}t  |jjj	j
d j¡}g }|jjj	j
D ]}t  |t|jƒ¡}q<||t|jƒ< |jdkr_t  d|¡|t|jƒ< q&|D ]&}	t  |	jjj	j
d j¡}|g|t|	jƒ< |jdkrˆt  d|¡|t|	jƒ< qb|S )Né   r   )r   ÚarrayÚdimsÚstrÚnameÚsizeÚappendÚtypeÚtensor_typer   ÚdimÚ	dim_valueÚint)
r   r   ÚinputÚoutputÚdictionÚwr!   ÚiÚkeyÚor   r   r   Úcreate_dict   s.   
€
€
€zOnnxProfile.create_dictc                 C   s0   |j tvrtd|j dƒ dS t|j  }|||ƒS )NzSorry, we haven't add zinto dictionary.)r   NN)Úop_typer   Úprint)r   r&   ÚnodeÚfnr   r   r   Únodes_counter5   s
   


zOnnxProfile.nodes_counterÚ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+   r0   r   r   )r   r	   ÚmacsÚ	name2dimsr   Únodesr$   r%   ÚnÚmacs_addingÚout_sizeÚoutnamer   r   r   Úcalculate_macs=   s   
zOnnxProfile.calculate_macsN)Ú__name__Ú
__module__Ú__qualname__r   ÚonnxÚ
ModelProtor   r+   r0   ÚtorchÚDoubleTensorr9   r   r   r   r   r   	   s    r   )	r?   Útorch.nnr=   r   Únumpyr   Úthop.vision.onnx_counterr   r   r   r   r   r   Ú<module>   s    