§
    l¬¸j˜	  ã            	       óL   — d dl Zd dlmZ ddedefd„Z	 	 	 ddededed	efd
„ZdS )é    N)ÚLOGGERÚimagesÚ
input_nameÚbatchc                 óP   ‡ ‡‡‡— ddl m}  G ˆˆ ˆˆfd„d|¦  «        } |¦   «         S )aG  Create an ONNX Runtime calibration data reader from an Ultralytics calibration dataloader.

    `batch` is the graph's static batch dimension (0 for dynamic-batch models): calibration datasets smaller than the
    export batch yield undersized batches that static graphs reject, so samples are tiled up to exactly `batch`.
    r   )ÚCalibrationDataReaderc                   ó2   •— e Zd Zˆfd„Zˆ ˆˆfd„Zˆfd„ZdS )ú3onnx_calibration_reader.<locals>._CalibrationReaderc                 ó0   •— t          ‰¦  «        | _        dS )z)Initialize calibration dataset iteration.N©ÚiterÚiterator©ÚselfÚdatasets    €úm/root/private/project/pallet_detection_v2/.venv/lib/python3.11/site-packages/ultralytics/utils/export/onnx.pyÚ__init__z<onnx_calibration_reader.<locals>._CalibrationReader.__init__   ó   ø€ å  ™MœMˆDŒMˆMˆMó    c                 óÜ   •— t          | j        d¦  «        x}€dS  ‰|¦  «        }‰rB|j        d         ‰k    r1t          j        |‰ |j        d         z   dddf¦  «        d‰…         }‰|iS )z;Return the next calibration sample, or None when exhausted.Nr   é   )Únextr   ÚshapeÚnpÚtile)r   ÚbÚimr   r   Útransform_fns      €€€r   Úget_nextz<onnx_calibration_reader.<locals>._CalibrationReader.get_next   sƒ   ø€ å˜$œ-¨Ñ.Ô.Ð.�Ð7Ø�tØ�˜a‘”ˆBØð N˜œ !œ¨Ò-Ð-Ý”W˜R U F¨b¬h°q¬kÑ$9Ð":¸A¸qÀ!Ð!DÑEÔEÀfÀuÀfÔM�Ø Ð#Ð#r   c                 ó0   •— t          ‰¦  «        | _        dS )z6Reset the iterator for an additional calibration pass.Nr   r   s    €r   Úrewindz:onnx_calibration_reader.<locals>._CalibrationReader.rewind   r   r   N)Ú__name__Ú
__module__Ú__qualname__r   r   r!   )r   r   r   r   s   €€€€r   Ú_CalibrationReaderr
      sj   ø€ € € € € ð	*ð 	*ð 	*ð 	*ð 	*ð	$ð 	$ð 	$ð 	$ð 	$ð 	$ð 	$ð	*ð 	*ð 	*ð 	*ð 	*ð 	*ð 	*r   r%   )Úonnxruntime.quantizationr   )r   r   r   r   r   r%   s   ````  r   Úonnx_calibration_readerr'      so   øøøø€ ð ?Ð>Ð>Ð>Ð>Ð>ð*ð *ð *ð *ð *ð *ð *ð *ð *ð *Ð2ñ *ô *ð *ð$ ÐÑÔÐr   Ú ÚprefixÚreturnc           
      óø   — ddl }ddlm} |                     | ¦  «        j        }	d„ |	j        D ¦   «         }
~	t          j        |› d�¦  «          || |t          ||||¦  «        |
¬¦  «         t          |¦  «        S )zFQuantize an ONNX model to INT8 using ONNX Runtime static quantization.r   N)Úquantize_staticc                 ó.   — g | ]}|j         d v¯|j        ‘ŒS )>   ÚConvÚGemmÚMatMul)Úop_typeÚname)Ú.0Úns     r   ú
<listcomp>z&onnx_int8_quantize.<locals>.<listcomp>6   s'   € ÐYÐYÐY˜!¨Q¬YÐ>XÐ-XÐ-XˆqŒvÐ-XÐ-XÐ-Xr   z% quantizing INT8 with ONNX Runtime...)Únodes_to_exclude)
Úonnxr&   r,   ÚloadÚgraphÚnoder   Úinfor'   Ústr)Ú	onnx_fileÚoutput_filer   r   r   r   r)   r7   r,   r9   Úexcludes              r   Úonnx_int8_quantizer@   %   s©   € ð €K€K€KØ8Ð8Ð8Ð8Ð8Ð8ð
 �IŠI�iÑ Ô Ô&€EØYÐY˜uœzÐYÑYÔY€GØå
„K�6Ð@Ð@Ð@ÑAÔAÐAØ€OØØÝ ¨°zÀ5ÑIÔIØ ð	ñ ô ð õ ˆ{ÑÔÐr   )r   r   )r   r   r(   )Únumpyr   Úultralytics.utilsr   r<   Úintr'   r@   © r   r   ú<module>rE      s¤   ðð Ð Ð Ð à $Ð $Ð $Ð $Ð $Ð $ð ð  ¸sð  ÐVYð  ð  ð  ð  ðD ØØðð ð
 ðð ðð ðð 	ðð ð ð ð ð r   