
    RЦiS              ?       F   S r SSKrSSKJrJrJr  SSKrSSKJr  SSK	J
r
JrJr  SSKJrJrJr  SSKJrJrJrJrJrJrJrJrJr  SSKJrJrJr  SS	KJ r   S
S\
\SS4S\\!\\!\!4   4   S\"S\\#S4   S\\#S4   S\$S\$4S jjr%S
SSSSSSSSSSSS\
\SSSSSSSSSSS4S\\!\\!\!4   4   S\\\#\#4      S\\\#\#4      S \\"   S!\#S"\#S#\\#\\#S4   4   S$\\#   S%\$S&\#S'\#S(\\"   S\"S\\#S4   S\\#S4   S)\#S*\"S+\!S,\!S\$S\$S-\$S.\$S/\\!\\!\!4   4   S0\!S1\$44S2 jjr&S
SSSS\
\SSSSSS4S\\!\\!\!4   4   S3\\#   S4\\"   S5\\!   S\"S\\#S4   S\\#S4   S\$S\$S.\$S/\\!\\!\!4   4   S0\!S1\$4S6 jjr'S
SSSSSSSSSSSSS\
\SSSSSSSSSSSSSSS4S7\\!\\!\!4   \\!\!\!4   4   S8\$S9\$S \\"   S\\\#\#4      S\\\#\#4      S!\#S"\#S#\\#\\#S4   4   S$\\#   S&\#S'\#S(\\"   S\"S\\#S4   S\\#S4   S)\#S*\"S+\!S,\!S3\\#   S4\\"   S5\\!   S:\$S\$S\$S-\$S.\$S/\\!\\!\!4   4   S0\!S1\$4>S; jjr(g)<zTransforms 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MaybeToTensorMaybePILToTensor)RandomResizedCropToSequenceResizeToSequencePatchify)RandomErasing   bilinearFTimg_sizeinterpolationmean.stduse_prefetcher	normalizec                    US:X  a  Sn[         R                  " U [        U5      S9[         R                  " U 5      /nU(       a  U[	        5       /-  nO`U(       d  U[	        5       /-  nOJU[        5       [         R                  " [        R                  " U5      [        R                  " U5      S9/-  n[         R                  " U5      $ )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   	NormalizetorchtensorCompose)r   r   r   r   r    r!   tfls          [/var/www/html/ai-image-ml/venv/lib/python3.13/site-packages/timm/data/transforms_factory.pytransforms_noaug_trainr.      s    *  "(2D]2STh'C  "## "##O  \\$'LL%
 	
 c""          ?        g?r#   const      i@  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separatenaflex
patch_sizemax_seq_lenpatchifyc                 f   U=(       d    SnUS;   d   e/ nU(       a:  [        U=(       d    S5      n[        U=(       d    S5      nU[        UUUUUS9/-  nOUS;   aU  [        U=(       d    S5      n[        U=(       d    S5      nU[        U US	US
S	US9US:X  a
  [        U SS9O	[	        U SS9/-  nO8[        U=(       d    S5      n[        U=(       d    S5      nU[        U UUUS9/-  nUS:  a  U[        R                  " US9/-  nUS:  a  U[        R                  " US9/-  n/ nSnU(       Ga  [        U[        5      (       d   eU=(       d    SU;   (       + n[        U [         [        45      (       a  [        U 5      nOU n[        [        US-  5      [        U Vs/ s H  n[        S[        SU-  5      5      PM     sn5      S9nU(       a  US:w  a  [!        U5      US'   UR#                  S5      (       a  U[%        UU5      /-  nO<UR#                  S5      (       a  SUS'   U['        UU5      /-  nOU[)        UU5      /-  nUb  U(       d  [        U[        [         45      (       a  [+        U5      S;   d   eO[-        U5      4S-  nUb,  U[        R.                  " [        R0                  " U6 /US9/-  nOU[        R0                  " U6 /-  nU	(       a  U[        R2                  " U	S9/-  nU
(       a,  U[        R.                  " [        R4                  " SS 9/U
S9/-  n/ n U(       a  U [7        5       /-  n OwU(       d  U [7        5       /-  n OaU [9        5       [        R:                  " [<        R>                  " U5      [<        R>                  " U5      S!9/-  n US:  a  U [A        UUUUS"S#9/-  n U(       a  U [C        US$9/-  n U(       aA  [        RD                  " U5      [        RD                  " U5      [        RD                  " U 5      4$ [        RD                  " UU-   U -   5      $ s  snf )%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.
    naflex: Enable NaFlex mode, sequence constrained patch output
    patch_size: Patch size for NaFlex mode.
    max_seq_len: Max sequence length for NaFlex mode.

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>   rJ   rkrcrkrr)g{Gz?      ?)g      ?gUUUUUU?)rF   rG   r5   r6   r   )rK   rL   )g?rM   )g?grq?r0   T)r   random_scale_probrandom_scale_rangerandom_scale_arearandom_aspect_probrandom_aspect_rangerK   reflect)padding_mode)r5   r6   r   r1   )pF3ag?   )translate_constimg_meanr#   r   randaugmixg333333?translate_pct)      r]      )kernel_sizer%   cpu)mode	max_count
num_splitsdevicerF   )#tupler   r   r   r   r   r   RandomHorizontalFlipRandomVerticalFlip
isinstancestrlistmindictintroundr   
startswithr
   r   r   lenfloatRandomApplyColorJitterRandomGrayscaleGaussianBlurr   r   r(   r)   r*   r   r   r+   )!r   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   r   r   r   r@   rA   rB   rC   r    r!   rD   rE   rF   rG   rH   primary_tflsecondary_tfldisable_color_jitterimg_size_minx	aa_params	final_tfls!                                    r-   transforms_imagenet_trainr   A   sk   B &.O5555Ke*{+e1123!#'
  	 ..%.;/E%.;/E"/&)',&*'*(- #f,  yAyA K %.;/E%5#56E1"/	 K rz
77%@AArz
55>??M ,,,,, %7$N$,:NOh..x=L#Lt 34dCdCU37^4dCD
	 ]h6):=)IIo&""6**4\9MNNM$$X..),Io&7iPQQM4\9MNNM(<lT5M22 |$... ",/1A5L(&&"..=( ( M j44lCDDM*44~FGG""++;$ %
 	
 I&())	&())	O  \\$'LL%
 	
	 R< &,  I h*566	!!+.
0B0B=0QS]SeSefoSppp!!+"=	"IJJY Ds    "P.crop_pct	crop_modecrop_border_pixelsc           	      p   U=(       d    [         n[        U [        [        45      (       aD  [	        U 5      S:X  d   e[        U  Vs/ s H  n[
        R                  " X-  5      PM     sn5      nO[
        R                  " X-  5      nX4n/ nU(       a  U[        U5      /-  nU	(       a  U[        U
UUS9/-  nOUS:X  a8  U[        R                  " U[        U5      S9[        R                  " U 5      /-  nOUS:X  a6  U Vs/ s H  n[        SU-  5      PM     nnU[        XSS9[        U US	9/-  nO[US
   US   :X  a&  U[        R                  " US
   [        U5      S9/-  nOU[        U5      /-  nU[        R                  " U 5      /-  nU(       a  U[!        5       /-  nO`U(       d  U[!        5       /-  nOJU[#        5       [        R$                  " [&        R(                  " U5      [&        R(                  " U5      S9/-  nU(       a  U[+        U
S9/-  n[        R,                  " U5      $ s  snf s  snf )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).
    naflex: Enable NaFlex mode, sequence constrained patch output
    patch_size: Patch size for NaFlex mode.
    max_seq_len: Max sequence length for NaFlex mode.
    patchify: Patchify the output instead of relying on prefetcher

Returns:
    Composed transform pipeline
   )rF   rG   r   squashr$   borderrW   rM   )r   longest)fillr   r3   r%   rf   )r	   rj   rg   rl   rr   mathfloorr   r   r   r&   r   r'   rp   r   r   r   r   r(   r)   r*   r   r+   )r   r   r   r   r   r   r   r    r!   rE   rF   rG   rH   r|   
scale_sizer,   vr   s                     r-   transforms_imagenet_evalr     s7   F ++H(UDM**8}!!!hGhDJJq|4hGH
ZZ 34
 -

C
-.// !#'
  	   !!*<N}<]^%%h/ C (" -11DqE#'NDD1
QTUt4 C !}
1-%%jmCUVcCde 
 
344J))(344C "## "##O  \\$'LL%
 	
 J/00c"" H6 2s   "H.H3
input_sizeis_trainingno_augtf_preprocessingc                    [        U [        [        45      (       a  U SS nOU nU(       a%  U(       a  U(       a   S5       eSSKJn   U " UUUS9n!U!$ U(       a%  U(       a  U(       a   S5       e[        UUUUUUS9n!U!$ U(       aT  [        U40 S	U_S
U_SU_SU_SU_SU_SU	_SU
_SU_SU_SU_SU_SU_SU_SU_SU_SU_SU_SU_SU_SU_SU_SU_S U_6n!U!$ U(       a   S!5       e[        UUUUUUUUUUUUUS"9n!U!$ )#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!   r7   r5   r6   r8   r9   r:   r;   r=   r>   r?   r   r   r   r@   rA   rB   rC   r    r!   rD   rE   rF   rG   rH   z>Separate transforms not supported for validation preprocessing)r   r   r   r   r   r   r    r!   rE   rF   rG   rH   )rj   rg   rl   timm.data.tf_preprocessingr   r.   r   r   )"r   r   r   r7   r5   r6   r8   r9   r:   r;   r=   r>   r?   r   r   r   r@   rA   rB   rC   r   r   r   r   r    r!   rD   rE   rF   rG   rH   r   r   	transforms"                                     r-   create_transformr   y  s   H *udm,,bc?NUUU|D)#'
	| q 6P!PP<.+-#Il ] 1 /  	
   * #4  . $6 * ,       !" "#$ ,%&  .'( $)* "+, -. &/0 (12 "3IZ #  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   timm.data.naflex_transformsr   r   r   timm.data.random_erasingr   ro   rk   rs   boolr.   r   r   r    r/   r-   <module>r      s  
  ) )  " ] ] l lc c c _ _ 2 14'"7!5$*#U38_,-*#*# E3J*# 5#:	*#
 *# *#\ 14/3/3)-8;-1#( "$&&*%"7!5$245LKU38_,-LKeUl+,LK eUl+,LK "#	LK
 LK LK E5#445LK $E?LK !LK LK "LK smLK LK E3JLK 5#:LK  !LK" #LK$ %LK& 'LK( )LK* +LK, -LK. /LK0 #uS#X./1LK2 3LK4 5LK` 14$(#',0'"7!5$24f#U38_,-f#5/f# C=f# %SM	f#
 f# E3Jf# 5#:f# f# f# f# #uS#X./f# f# f#T IL!)-/3/38;-1 "$&&*'"7!5$(#',0!&$24?J#uS#Xc3m0DDEJJ J "#	J
 eUl+,J eUl+,J J J E5#445J $E?J J "J smJ J E3JJ  5#:!J" #J$ %J& 'J( )J* 5/+J, C=-J. %SM/J0 1J2 3J4 5J6 7J8 9J: #uS#X./;J< =J> ?Jr/   