a
    yfj                     @   s(  d dl Z d dlZd dlmZ d dlmZ d dlZd dlmZm	Z	 d dl
mZ d dlmZmZmZ d dlmZmZmZmZmZ d dlmZmZ d	d
 Zdd Zejje dddd Zejjejje ddejddd eeddgddgddgddgD dd Z ejjejdeeddgdgdgddgddgdd Z!ejjejdeedgdgdgddgdd Z"ejjejje ddejje d dejjej#d!dejdd"d eedgddgddgdgD d#d$ Z$ejjejjej% d%dejje d&dejdd'd eedgddgddgdgD d(d) Z&ejje d dejjed*dejjed+dejjej#d!dd,d- Z'ejjej% d%dejje d&dd.d/ Z(ejjdd0dejje d1dd2d3 Z)ejjdd4dd5d6 Z*ejjd7d8 Z+dS )9    N)product)Path)MODELSOURCE)YOLO)	TASK2DATA
TASK2MODELTASKS)IS_RASPBERRYPILINUXMACOSWINDOWSchecks)	TORCH_1_9
TORCH_1_13c                  C   s(   t tjdddd} t | tdd dS )zRTest YOLO model exporting to TorchScript format for compatibility and correctness.torchscriptF    )formatoptimizeimgszr   Nr   r   exportr   file r   N/var/www/html/django/DPS/env/lib/python3.9/site-packages/tests/test_exports.pytest_export_torchscript   s    r   c                  C   s(   t tjdddd} t | tdd dS )z8Test YOLO model export to ONNX format with dynamic axes.onnxTr   )r   dynamicr   r   Nr   r   r   r   r   test_export_onnx   s    r    zOpenVINO requires torch>=1.13)reasonc                  C   s&   t tjddd} t | tdd dS )zGTest YOLO exports to OpenVINO format for model inference compatibility.openvinor   r   r   r   Nr   r   r   r   r   test_export_openvino#   s    r$   z task, dynamic, int8, half, batchc                 C   s,   g | ]$\}}}}}|r|s|||||fqS r   r   .0taskr   int8halfbatchr   r   r   
<listcomp>.   s   r+   TF      c              	   C   s   t t|  jdd||||t|  d}trPt|}|||j dt	
  }t |tg| |rfdndd tj|dd d	S )
zRTest YOLO model exports to OpenVINO under various configuration matrix conditions.r"   r   )r   r   r   r(   r)   r*   data-@   r   T)ignore_errorsN)r   r   r   r   r   r   rename	with_stemstemuuiduuid4r   shutilrmtreer'   r   r(   r)   r*   r   r   r   r   test_export_openvino_matrix*   s    	 r:   z*task, dynamic, int8, half, batch, simplifyc              	   C   sN   t t|  jdd|||||d}t |tg| |r6dndd t|  dS )zLTest YOLO exports to ONNX format with various configurations and parameters.r   r   )r   r   r   r(   r)   r*   simplifyr0   r   Nr   r   r   r   r   unlink)r'   r   r(   r)   r*   r;   r   r   r   r   test_export_onnx_matrixH   s    	r>   c                 C   sL   t t|  jdd||||d}t |tgd |r4dndd t|  dS )zKTests YOLO model exports to TorchScript format under varied configurations.r   r   r   r   r   r(   r)   r*      r0   r   Nr<   r9   r   r   r   test_export_torchscript_matrix[   s    rA   z(CoreML inference only supported on macOSz+CoreML>=7.2 not supported with PyTorch<=1.8z#CoreML not supported in Python 3.12c                 C   s,   g | ]$\}}}}}|r|s|||||fqS r   r   r%   r   r   r   r+   q   s   c                 C   sB   t t|  jdd||||d}t |tg| dd t| dS )zITest YOLO exports to CoreML format with various parameter configurations.coremlr   r?   r   N)r   r   r   r   r7   r8   r9   r   r   r   test_export_coreml_matrixk   s    rC   z#TFLite export requires Python>=3.10zGTest disabled as TF suffers from install conflicts on Windows and macOSc                 C   s,   g | ]$\}}}}}|r|s|||||fqS r   r   r%   r   r   r   r+      s   c                 C   sD   t t|  jdd||||d}t |tg| dd t|  dS )zMTest YOLO exports to TFLite format considering various export configurations.tfliter   r?   r   Nr<   r9   r   r   r   test_export_tflite_matrix   s    rE   zCoreML not supported on Windowsz$CoreML not supported on Raspberry Pic                  C   s@   t r(ttjddd} t| tdd nttjdddd dS )z=Test YOLO exports to CoreML format, optimized for macOS only.rB   r   r#   r   T)r   Znmsr   N)r   r   r   r   r   r   r   r   r   test_export_coreml   s    rF   c                  C   s*   t t} | jddd}t |tdd dS )zSTest YOLO exports to TFLite format under specific OS and Python version conditions.rD   r   r#   r   Nr   modelr   r   r   r   test_export_tflite   s    rI   zTest disabledz6TF suffers from install conflicts on Windows and macOSc                  C   s*   t t} | jddd}t |tdd dS )z9Test YOLO exports to TensorFlow's Protobuf (*.pb) format.Zpbr   r#   r   Nr   rG   r   r   r   test_export_pb   s    rJ   zITest disabled as Paddle protobuf and ONNX protobuf requirements conflict.c                   C   s   t tjddd dS )zHTest YOLO exports to Paddle format, noting protobuf conflicts with ONNX.Zpaddler   r#   N)r   r   r   r   r   r   r   test_export_paddle   s    rK   c                  C   s&   t tjddd} t | tdd dS )z!Test YOLO exports to NCNN format.Zncnnr   r#   r   Nr   r   r   r   r   test_export_ncnn   s    rL   ),r7   r5   	itertoolsr   pathlibr   Zpytesttestsr   r   Zultralyticsr   Zultralytics.cfgr   r   r	   Zultralytics.utilsr
   r   r   r   r   Zultralytics.utils.torch_utilsr   r   r   r    markZskipifr$   ZslowZparametrizer:   r>   rA   ZIS_PYTHON_3_12rC   ZIS_PYTHON_MINIMUM_3_10rE   rF   rI   rJ   rK   rL   r   r   r   r   <module>   s   
""	
