
    NgiJ              7          d Z ddlZddlmZmZmZ ddlZddlmZ ddl	m
Z
mZmZ ddlmZmZmZ ddlmZmZmZmZmZmZmZmZmZmZ ddlmZ d	d
e
eddfdeeeeef         f         dedee df         dee df         de!de!fdZ"d	dddddddddddde
edddddddfdeeeeef         f         deee e f                  deee e f                  dee         de de d ee ee df         f         d!ee          d"e!d#e d$e d%ee         dedee df         dee df         d&e d'ed(ed)ede!de!d*e!f,d+Z#d	dddd
e
eddf	deeeeef         f         d,ee          d-ee         d.ee         dedee df         dee df         de!de!fd/Z$d	ddddddddddddd
e
edddddddddddfd0eeeeef         eeeef         f         d1e!d2e!dee         deee e f                  deee e f                  de de d ee ee df         f         d!ee          d#e d$e d%ee         dedee df         dee df         d&e d'ed(ed)ed,ee          d-ee         d.ee         d3e!de!de!d*e!f6d4Z%dS )5z Transforms Factory
Factory methods for building image transforms for use with TIMM (PyTorch Image Models)

Hacked together by / Copyright 2019, Ross Wightman
    N)OptionalTupleUnion)
transforms)IMAGENET_DEFAULT_MEANIMAGENET_DEFAULT_STDDEFAULT_CROP_PCT)rand_augment_transformaugment_and_mix_transformauto_augment_transform)
str_to_interp_modestr_to_pil_interp!RandomResizedCropAndInterpolationResizeKeepRatioCenterCropOrPadRandomCropOrPad
TrimBorderToNumpyMaybeToTensorMaybePILToTensor)RandomErasing   bilinearFTimg_sizeinterpolationmean.stduse_prefetcher	normalizec                    |dk    rd}t          j        | t          |                    t          j        |           g}|r|t	                      gz  }n`|s|t                      gz  }nK|t                      t          j        t          j	        |          t          j	        |                    gz  }t          j
        |          S )a   No-augmentation image transforms for training.

    Args:
        img_size: Target image size.
        interpolation: Image interpolation mode.
        mean: Image normalization mean.
        std: Image normalization standard deviation.
        use_prefetcher: Prefetcher enabled. Do not convert image to tensor or normalize.
        normalize: Normalization tensor output w/ provided mean/std (if prefetcher not used).

    Returns:

    randomr   r   r   r   )r   Resizer   
CenterCropr   r   r   	NormalizetorchtensorCompose)r   r   r   r   r   r   tfls          X/var/www/html/ai-engine/env/lib/python3.11/site-packages/timm/data/transforms_factory.pytransforms_noaug_trainr,      s    *   "(2D]2S2STTTh''C  
		{ 

 ""##OO \$''L%%  
 	
 c"""          ?        g?r!   const   scaleratiotrain_crop_modehflipvflipcolor_jittercolor_jitter_probforce_color_jittergrayscale_probgaussian_blur_probauto_augmentre_probre_modere_countre_num_splitsseparatec           	      `   |pd}|dv sJ |dv rat          |pd          }t          |pd          }t          | |d|dd|          |d	k    rt          | d
          nt          | d
          g}n6t          |pd          }t          |pd          }t	          | |||          g}|dk    r|t          j        |          gz  }|dk    r|t          j        |          gz  }g }d}|rt          |t                    sJ |pd|v  }t          | t           t          f          rt          |           }n| }t          t          |dz            t          d |D                                 }|r|dk    rt          |          |d<   |                    d          r|t!          ||          gz  }nC|                    d          rd|d<   |t#          ||          gz  }n|t%          ||          gz  }||st          |t          t           f          rt'          |          dv sJ nt)          |          fdz  }|(|t          j        t          j        | g|          gz  }n|t          j        | gz  }|	r|t          j        |	          gz  }|
r.|t          j        t          j        d           g|
          gz  }g }|r|t3                      gz  }n~|s|t5                      gz  }ni|t7                      t          j        t;          j        |          t;          j        |          !          gz  }|dk    r|t?          ||||d"#          gz  }|r;t          j         |          t          j         |          t          j         |          fS t          j         ||z   |z             S )$a   ImageNet-oriented image transforms for training.

    Args:
        img_size: Target image size.
        train_crop_mode: Training random crop mode ('rrc', 'rkrc', 'rkrr').
        scale: Random resize scale range (crop area, < 1.0 => zoom in).
        ratio: Random aspect ratio range (crop ratio for RRC, ratio adjustment factor for RKR).
        hflip: Horizontal flip probability.
        vflip: Vertical flip probability.
        color_jitter: Random color jitter component factors (brightness, contrast, saturation, hue).
            Scalar is applied as (scalar,) * 3 (no hue).
        color_jitter_prob: Apply color jitter with this probability if not None (for SimlCLR-like aug).
        force_color_jitter: Force color jitter where it is normally disabled (ie with RandAugment on).
        grayscale_prob: Probability of converting image to grayscale (for SimCLR-like aug).
        gaussian_blur_prob: Probability of applying gaussian blur (for SimCLR-like aug).
        auto_augment: Auto augment configuration string (see auto_augment.py).
        interpolation: Image interpolation mode.
        mean: Image normalization mean.
        std: Image normalization standard deviation.
        re_prob: Random erasing probability.
        re_mode: Random erasing fill mode.
        re_count: Number of random erasing regions.
        re_num_splits: Control split of random erasing across batch size.
        use_prefetcher: Prefetcher enabled. Do not convert image to tensor or normalize.
        normalize: Normalize tensor output w/ provided mean/std (if prefetcher not used).
        separate: Output transforms in 3-stage tuple.

    Returns:
        If separate==True, the transforms are returned as a tuple of 3 separate transforms
        for use in a mixing dataset that passes
         * all data through the first (primary) transform, called the 'clean' data
         * a portion of the data through the secondary transform
         * normalizes and converts the branches above with the third, final transform
    rrc>   rC   rkrcrkrr)rD   rE   )g?      ?)g?grq?r.   T)r   random_scale_probrandom_scale_rangerandom_scale_arearandom_aspect_probrandom_aspect_rangerD   reflect)padding_mode)g{Gz?rF   )g      ?gUUUUUU?)r2   r3   r   r/   )pF3ag?c           	      N    g | ]"}t          d t          d |z                      #S    )minround).0xs     r+   
<listcomp>z-transforms_imagenet_train.<locals>.<listcomp>   s,    CCCCU37^^44CCCr-   )translate_constimg_meanr!   r   randaugmixg333333?translate_pctN)      r]      )kernel_sizer#   cpu)mode	max_count
num_splitsdevice)!tupler   r   r   r   r   RandomHorizontalFlipRandomVerticalFlip
isinstancestrlistrS   dictintr   
startswithr
   r   r   lenfloatRandomApplyColorJitterRandomGrayscaleGaussianBlurr   r   r   r&   r'   r(   r   r)   )r   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   r<   r   r   r   r=   r>   r?   r@   r   r   rA   primary_tflsecondary_tfldisable_color_jitterimg_size_min	aa_params	final_tfls                               r+   transforms_imagenet_trainr{   @   s   t &.O55555***e*{++e*{+++"%#("&#&$)   &(( H9====H9===
 e*{++e1122-+	  
 rzz
7%@@@AArzz
5>>>??M  O,,,,,, %7$N$,:NOh.. 	$x==LL#Lt 344CCdCCCDD
 
 
	  	J]h66):=)I)IIo&""6** 	O4\9MMNNMM$$X.. 	O),Io&7iPPQQMM4\9MMNNM(<lT5M22 	6 |$$..... ",//1A5L(&".=( (   MM j4lCDDM H*4~FFFGG 
"+;;;$ %  
 	
 I gii[ 		 &(())		OO \$''L%%  
 	
	 R<< &,    I  K!+..
0B=0Q0QS]SefoSpSppp!+"=	"IJJJr-   crop_pct	crop_modecrop_border_pixelsc	                    pt           t          | t          t          f          r1t	          |           dk    sJ t          fd| D                       }	nt          j        | z            }	|	|	f}	g }
|r|
t          |          gz  }
|dk    r;|
t          j	        |	t          |                    t          j        |           gz  }
n|dk    r3d |D             }|
t          |	|d          t          | |	          gz  }
nk|	d
         |	d         k    r.|
t          j	        |	d
         t          |                    gz  }
n|
t          |	          gz  }
|
t          j        |           gz  }
|r|
t                      gz  }
n`|s|
t                      gz  }
nK|
t!                      t          j        t%          j        |          t%          j        |                    gz  }
t          j        |
          S )a   ImageNet-oriented image transform for evaluation and inference.

    Args:
        img_size: Target image size.
        crop_pct: Crop percentage. Defaults to 0.875 when None.
        crop_mode: Crop mode. One of ['squash', 'border', 'center']. Defaults to 'center' when None.
        crop_border_pixels: Trim a border of specified # pixels around edge of original image.
        interpolation: Image interpolation mode.
        mean: Image normalization mean.
        std: Image normalization standard deviation.
        use_prefetcher: Prefetcher enabled. Do not convert image to tensor or normalize.
        normalize: Normalize tensor output w/ provided mean/std (if prefetcher not used).

    Returns:
        Composed transform pipeline
       c                 >    g | ]}t          j        |z            S  )mathfloor)rU   rV   r|   s     r+   rW   z,transforms_imagenet_eval.<locals>.<listcomp>  s'    GGGDJq8|44GGGr-   squashr"   borderc                 2    g | ]}t          d |z            S rQ   )rT   )rU   vs     r+   rW   z,transforms_imagenet_eval.<locals>.<listcomp>*  s"    ---1cAg---r-   rF   )r   longest)fillr   r1   r#   )r	   ri   rf   rk   ro   r   r   r   r   r$   r   r%   r   r   r   r   r   r&   r'   r(   r)   )r   r|   r}   r~   r   r   r   r   r   
scale_sizer*   r   s    `          r+   transforms_imagenet_evalr      sE   6 ++H(UDM** .8}}!!!!GGGGhGGGHH

Z8 344
 *-

C 0
-..//H 	j8J=8Y8YZZZ!(++
 	
 
h		 .----JmSQQQH4000
 	
 a=JqM))!*Q-?QR_?`?`aaa CC
 OJ//00C
%h//00 
		{ 

 ""##OO \$''L%%  
 	
 c"""r-   
input_sizeis_trainingno_augtf_preprocessingc                    t          | t          t          f          r| dd         }n| }|r#|r!|r
J d            ddlm}  ||||          }n|r$|r"|r
J d            t          ||||||          }nn|rHt          |fi d	|d
|d|d|d|d|d|	d|
d|d|d|d|d|d|d|d|d|d|d|d|}n$|r
J d            t          |||||||||	  	        }|S )a;  

    Args:
        input_size: Target input size (channels, height, width) tuple or size scalar.
        is_training: Return training (random) transforms.
        no_aug: Disable augmentation for training (useful for debug).
        train_crop_mode: Training random crop mode ('rrc', 'rkrc', 'rkrr').
        scale: Random resize scale range (crop area, < 1.0 => zoom in).
        ratio: Random aspect ratio range (crop ratio for RRC, ratio adjustment factor for RKR).
        hflip: Horizontal flip probability.
        vflip: Vertical flip probability.
        color_jitter: Random color jitter component factors (brightness, contrast, saturation, hue).
            Scalar is applied as (scalar,) * 3 (no hue).
        color_jitter_prob: Apply color jitter with this probability if not None (for SimlCLR-like aug).
        grayscale_prob: Probability of converting image to grayscale (for SimCLR-like aug).
        gaussian_blur_prob: Probability of applying gaussian blur (for SimCLR-like aug).
        auto_augment: Auto augment configuration string (see auto_augment.py).
        interpolation: Image interpolation mode.
        mean: Image normalization mean.
        std: Image normalization standard deviation.
        re_prob: Random erasing probability.
        re_mode: Random erasing fill mode.
        re_count: Number of random erasing regions.
        re_num_splits: Control split of random erasing across batch size.
        crop_pct: Inference crop percentage (output size / resize size).
        crop_mode: Inference crop mode. One of ['squash', 'border', 'center']. Defaults to 'center' when None.
        crop_border_pixels: Inference crop border of specified # pixels around edge of original image.
        tf_preprocessing: Use TF 1.0 inference preprocessing for testing model ports
        use_prefetcher: Pre-fetcher enabled. Do not convert image to tensor or normalize.
        normalize: Normalization tensor output w/ provided mean/std (if prefetcher not used).
        separate: Output transforms in 3-stage tuple.

    Returns:
        Composed transforms or tuple thereof
    Nz6Separate transforms not supported for TF preprocessingr   )TfPreprocessTransform)r   sizer   z-Cannot perform split augmentation with no_aug)r   r   r   r   r   r4   r2   r3   r5   r6   r7   r8   r:   r;   r<   r   r   r   r=   r>   r?   r@   r   r   rA   z>Separate transforms not supported for validation preprocessing)r   r   r   r|   r}   r~   r   r   )ri   rf   rk   timm.data.tf_preprocessingr   r,   r{   r   )r   r   r   r4   r2   r3   r5   r6   r7   r8   r:   r;   r<   r   r   r   r=   r>   r?   r@   r|   r}   r~   r   r   r   rA   r   r   	transforms                                 r+   create_transformr   N  s6   @ *udm,, bcc? 7N 7UUUUUUDDDDDD))#'
 
 
		  .	6 .	PP!PPPP.+-#  II  $	1   / e e	
 e e *\ #4"3  .~ $6#5 *\ ,m T C     !" "#$ ,m%&  .~'( $))* "+II0  aa!aaaa0+!##5-#
 
 
I r-   )&__doc__r   typingr   r   r   r'   torchvisionr   timm.data.constantsr   r   r	   timm.data.auto_augmentr
   r   r   timm.data.transformsr   r   r   r   r   r   r   r   r   r   timm.data.random_erasingr   rm   rj   rp   boolr,   r{   r   r   r   r-   r+   <module>r      sm   
  ) ) ) ) ) ) ) ) ) )  " " " " " " ] ] ] ] ] ] ] ] ] ] l l l l l l l l l ll l l l l l l l l l l l l l l l l l l l l l l l 2 2 2 2 2 2 14'"7!5$*# *#U38_,-*#*# E3J*# 5#:	*#
 *# *# *# *# *#\ 14/3/3)-8;-1#( "$&&*%"7!5$-tK tKU38_,-tKeUl+,tK eUl+,tK "#	tK
 tK tK E5#445tK $E?tK !tK tK "tK smtK tK E3JtK 5#:tK  !tK" #tK$ %tK& 'tK( )tK* +tK, -tK tK tK tKp 14$(#',0'"7!5$T# T#U38_,-T#5/T# C=T# %SM	T#
 T# E3JT# 5#:T# T# T# T# T# T#p IL!)-/3/38;-1 "$&&*'"7!5$(#',0!&$7~ ~#uS#Xc3m0DDE~~ ~ "#	~
 eUl+,~ eUl+,~ ~ ~ E5#445~ $E?~ ~ "~ sm~ ~ E3J~  5#:!~" #~$ %~& '~( )~* 5/+~, C=-~. %SM/~0 1~2 3~4 5~6 7~ ~ ~ ~ ~ ~r-   