
    `i                     D    S SK Jr  S SKrS SKrS SKrS rS rS rSS jr	g)    )ImageNc                 $    [         [        S.nX   $ )z
Set up the data preprocess function name and function dict. 
    parameter preprocess_func_name: name of the preprocess function 
    return: function pointer 
preprocess_method1preprocess_method2r   )preprocess_func_namefuncdicts     m/var/www/html/ai-image-ml/venv/lib/python3.13/site-packages/onnxruntime_tools/quantization/data_preprocess.pyset_preprocessr      s     '9PbcH))    c                 \   [         R                  " SX!45      nUR                  [         R                  " U 5      R	                  X!45      5        [
        R                  " U5      S-  S-
  nU[
        R                  " U5      -  n[
        R                  " USS9nUR                  SSSS5      nU$ )	aC  
Resizes image to NCHW format. Image is scaled to range [-1, 1].
This method is suitable for the mobilenet model from mlperf inference git repo.
    parameter image_filepath: path to image files
    parameter height: image height in pixels
    parameter width: image width in pixels
    return: matrix characterizing image
RGBg     _@g      ?r   axis         )
r   newpasteopenresizenpfloat32meanexpand_dims	transposeimage_filepathheightwidth
pillow_img
input_data	nhwc_data	nchw_datas          r
   r   r      s     55/2JUZZ/66GHJ'%/#5J"''*%%Jz2I##Aq!Q/Ir   c                 j   [         R                  " SX!45      nUR                  [         R                  " U 5      R	                  X!45      5        [
        R                  " U5      [
        R                  " / SQ[
        R                  S9-
  n[
        R                  " USS9nUR                  SSSS5      nU$ )	a1  
Resizes and normalizes image to NCHW format. 
This method is suitable for the resnet50 model from mlperf inference git repo. 
    parameter image_filepath: path to image files
    parameter height: image height in pixels
    parameter width: image width in pixels
    return: matrix characterizing image
r   )gQ^@gR1]@g\(Y@)dtyper   r   r   r   r   )
r   r   r   r   r   r   r   arrayr   r   r   s          r
   r   r   *   s     55/2JUZZ/66GHJ'
)<=Jz2I##Aq!Q/Ir   c                 f   [         R                  " U 5      nUS:  a-  [        U5      U:  a  [        U5       Vs/ s H  oeU   PM	     nnOUn/ n[	        U5      n	U H%  n
U S-   U
-   nU	" XU5      nUR                  U5        M'     [        R                  " [        R                  " USS9SS9nU$ s  snf )ax  
Loads a batch of images
parameter images_folder: path to folder storing images
parameter height: image height in pixels
parameter width: image width in pixels
parameter size_limit: number of images to load. Default is 0 which means all images are picked.
parameter preprocess_func_name: name of the preprocess function
return: list of matrices characterizing multiple images
r   /r   )	oslistdirlenranger   appendr   concatenater   )images_folderr   r    r   
size_limitimage_namesibatch_filenamesunconcatenated_batch_datapreprocess_func
image_namer   r$   
batch_datas                 r
   
load_batchr9   <   s     **]+KA~#k*j8383DE3Daq>3DE% "$%9:O%
&,z9#NEB	!((3 & /Hq QXYZJ Fs   B.)r   )
PILr   r*   sysnumpyr   r   r   r   r9    r   r
   <module>r>      s'     	 
 *$$r   