
    6bi_                        S r SSKJs  Jr  SSKJr  SSKJr  SSKJ	r	  SSK
Jr  SSKJr  SSKJr  SS	KJr  SS
KJr  SrSSSSSSS.r\" 5       rSr            S&S jr\" S5                 S'S j5       r\" S5                 S'S j5       r\R7                  SS9\l         \R7                  SS9\l         S rS rS rS(S jrS  r S! r!\" S"5      S)S# j5       r"\" S$5      S*S% j5       r#\	RF                  R                   \#l         g)+z!MobileNet v3 models for TF-Keras.    N)backend)models)imagenet_utils)VersionAwareLayers)
data_utils)layer_utils)
tf_logging)keras_exportzJhttps://storage.googleapis.com/tensorflow/keras-applications/mobilenet_v3/) 765b44a33ad4005b3ac83185abf1d0eb 40af19a13ebea4e2ee0c676887f69a2e) 59e551e166be033d707958cf9e29a6a7 07fb09a5933dd0c8eaafa16978110389) 675e7b876c45c57e9e63e6d90a36599c ec5221f64a2f6d1ef965a614bdae7973) cb65d4e5be93758266aa0a7f2c6708b7 ebdb5cc8e0b497cd13a7c275d475c819) 8768d4c2e7dee89b9d02b2d03d65d862 d3e8ec802a04aa4fc771ee12a9a9b836) 99cd97fb2fcdad2bf028eb838de69e37 cde8136e733e811080d9fcd8a252f7e4)zlarge_224_0.75_floatzlarge_224_1.0_floatz large_minimalistic_224_1.0_floatzsmall_224_0.75_floatzsmall_224_1.0_floatz small_minimalistic_224_1.0_floata  Instantiates the {name} architecture.

  Reference:
  - [Searching for MobileNetV3](
      https://arxiv.org/pdf/1905.02244.pdf) (ICCV 2019)

  The following table describes the performance of MobileNets v3:
  ------------------------------------------------------------------------
  MACs stands for Multiply Adds

  |Classification Checkpoint|MACs(M)|Parameters(M)|Top1 Accuracy|Pixel1 CPU(ms)|
  |---|---|---|---|---|
  | mobilenet_v3_large_1.0_224              | 217 | 5.4 |   75.6   |   51.2  |
  | mobilenet_v3_large_0.75_224             | 155 | 4.0 |   73.3   |   39.8  |
  | mobilenet_v3_large_minimalistic_1.0_224 | 209 | 3.9 |   72.3   |   44.1  |
  | mobilenet_v3_small_1.0_224              | 66  | 2.9 |   68.1   |   15.8  |
  | mobilenet_v3_small_0.75_224             | 44  | 2.4 |   65.4   |   12.8  |
  | mobilenet_v3_small_minimalistic_1.0_224 | 65  | 2.0 |   61.9   |   12.2  |

  For image classification use cases, see
  [this page for detailed examples](
    https://keras.io/api/applications/#usage-examples-for-image-classification-models).

  For transfer learning use cases, make sure to read the
  [guide to transfer learning & fine-tuning](
    https://keras.io/guides/transfer_learning/).

  Note: each TF-Keras Application expects a specific kind of input
  preprocessing. For MobileNetV3, by default input preprocessing is included as
  a part of the model (as a `Rescaling` layer), and thus
  `tf.keras.applications.mobilenet_v3.preprocess_input` is actually a
  pass-through function. In this use case, MobileNetV3 models expect their
  inputs to be float tensors of pixels with values in the [0-255] range.
  At the same time, preprocessing as a part of the model (i.e. `Rescaling`
  layer) can be disabled by setting `include_preprocessing` argument to False.
  With preprocessing disabled MobileNetV3 models expect their inputs to be float
  tensors of pixels with values in the [-1, 1] range.

  Args:
    input_shape: Optional shape tuple, to be specified if you would
      like to use a model with an input image resolution that is not
      (224, 224, 3).
      It should have exactly 3 inputs channels (224, 224, 3).
      You can also omit this option if you would like
      to infer input_shape from an input_tensor.
      If you choose to include both input_tensor and input_shape then
      input_shape will be used if they match, if the shapes
      do not match then we will throw an error.
      E.g. `(160, 160, 3)` would be one valid value.
    alpha: controls the width of the network. This is known as the
      depth multiplier in the MobileNetV3 paper, but the name is kept for
      consistency with MobileNetV1 in TF-Keras.
      - If `alpha` < 1.0, proportionally decreases the number
          of filters in each layer.
      - If `alpha` > 1.0, proportionally increases the number
          of filters in each layer.
      - If `alpha` = 1, default number of filters from the paper
          are used at each layer.
    minimalistic: In addition to large and small models this module also
      contains so-called minimalistic models, these models have the same
      per-layer dimensions characteristic as MobilenetV3 however, they don't
      utilize any of the advanced blocks (squeeze-and-excite units, hard-swish,
      and 5x5 convolutions). While these models are less efficient on CPU, they
      are much more performant on GPU/DSP.
    include_top: Boolean, whether to include the fully-connected
      layer at the top of the network. Defaults to `True`.
    weights: String, one of `None` (random initialization),
      'imagenet' (pre-training on ImageNet),
      or the path to the weights file to be loaded.
    input_tensor: Optional TF-Keras tensor (i.e. output of
      `layers.Input()`)
      to use as image input for the model.
    pooling: String, optional pooling mode for feature extraction
      when `include_top` is `False`.
      - `None` means that the output of the model
          will be the 4D tensor output of the
          last convolutional block.
      - `avg` means that global average pooling
          will be applied to the output of the
          last convolutional block, and thus
          the output of the model will be a
          2D tensor.
      - `max` means that global max pooling will
          be applied.
    classes: Integer, optional number of classes to classify images
      into, only to be specified if `include_top` is True, and
      if no `weights` argument is specified.
    dropout_rate: fraction of the input units to drop on the last layer.
    classifier_activation: A `str` or callable. The activation function to use
      on the "top" layer. Ignored unless `include_top=True`. Set
      `classifier_activation=None` to return the logits of the "top" layer.
      When loading pretrained weights, `classifier_activation` can only
      be `None` or `"softmax"`.
    include_preprocessing: Boolean, whether to include the preprocessing
      layer (`Rescaling`) at the bottom of the network. Defaults to `True`.

  Call arguments:
    inputs: A floating point `numpy.array` or a `tf.Tensor`, 4D with 3 color
      channels, with values in the range [0, 255] if `include_preprocessing`
      is True and in the range [-1, 1] otherwise.

  Returns:
    A `keras.Model` instance.
c           
         US;   d<  [         R                  R                  R                  U5      (       d  [	        SU 35      eUS:X  a  U(       a  U	S:w  a  [	        SU	 35      eUb  Ub   [
        R                  " U5      nU(       a  [
        R                  " 5       S:X  aF  [
        R                  " U5      S	   US	   :w  a%  [	        S
U S[
        R                  " U5       35      eOS[
        R                  " U5      S   US	   :w  a%  [	        SU S[
        R                  " U5       35      eO[	        SUS5      eUc  Ub   [
        R                  " U5        [
        R                  " U5      (       a  [
        R                  " 5       S:X  a8  [
        R                  " U5      S   n[
        R                  " U5      S   nSUU4nO7[
        R                  " U5      S	   n[
        R                  " U5      S   nUUS4nUc  Uc  Sn[
        R                  " 5       S:X  a  Su  nnOSu  nnUU   nUU   nU(       a"  U(       a  US:  d  US:  a  [	        SU S35      eUS:X  aG  U(       d  US;  d  U(       a  US:w  a  [	        S5      eUU:w  d  US:w  a  [        R                  " S5        Uc  [        R                  US9nO1[
        R                  " U5      (       d  [        R                  XS 9nOUn[
        R                  " 5       S:X  a  S	OS!nU(       a  Sn[         nS nO
S"n["        nS#nUnU(       a  [        R%                  S$S%S&9" U5      n[        R'                  S'SS(S)S*S+S,9" U5      n[        R)                  US-S.S/S09" U5      nU" U5      nU " UUUU5      n[+        [
        R                  " U5      U   S1-  5      nUS:  a  [+        X-  5      n[        R'                  US	S)S*S2S39" U5      n[        R)                  US-S.S4S09" U5      nU" U5      nU(       a  [        R-                  S5S69" U5      n[        R'                  US	S)S5S7S39" U5      nU" U5      nUS8:  a  [        R/                  U5      " U5      n[        R'                  U	S	S)S9S:9" U5      n[        R1                  5       " U5      n[2        R4                  " X5        [        R7                  US;S<9" U5      nO?U
S=:X  a  [        R-                  S>S?9" U5      nOU
S@:X  a  [        R9                  SAS?9" U5      nUb  [        R                  " U5      nOUn[:        R<                  " UUSBU-   S?9nUS:X  a  SCR?                  XE(       a  SDOSE[A        U5      5      nU(       a  SFU-   SG-   n[B        U   S8   nOSFU-   SH-   n[B        U   S	   n[D        RF                  " U[H        U-   SIUSJ9nURK                  U5        U$ Ub  URK                  U5        U$ ! [         aV     [
        R                  " [        R                  " U5      5      n GN! [         a    [	        SUS[        U5       35      ef = ff = f! [         a    [	        SUS[        U5      S5      ef = f)KN>   NimagenetzThe `weights` argument should be either `None` (random initialization), `imagenet` (pre-training on ImageNet), or the path to the weights file to be loaded.  Received weights=r     zkIf using `weights` as `"imagenet"` with `include_top` as true, `classes` should be 1000.  Received classes=zinput_tensor: z7is not type input_tensor.  Received type(input_tensor)=channels_first   zWhen backend.image_data_format()=channels_first, input_shape[1] must equal backend.int_shape(input_tensor)[1].  Received input_shape=z", backend.int_shape(input_tensor)=   zTinput_shape[1] must equal backend.int_shape(input_tensor)[2].  Received input_shape=zinput_tensor specified: zis not a keras tensorz	is type: zwhich is not a valid type   )NNr   channels_last)r   r   )r   r       z9Input size must be at least 32x32; Received `input_shape=`)g      ?      ?r!   z|If imagenet weights are being loaded, alpha can be one of `0.75`, `1.0` for non minimalistic or `1.0` for minimalistic only.   z`input_shape` is undefined or non-square, or `rows` is not 224. Weights for input shape (224, 224) will be loaded as the default.)shape)tensorr#      g      ?g?g      )scaleoffset   )r   r   sameFConv)kernel_sizestridespaddinguse_biasnameMbP?+?zConv/BatchNormaxisepsilonmomentumr0      Conv_1r,   r.   r/   r0   zConv_1/BatchNormT)keepdimsConv_2r   Logitsr,   r.   r0   Predictions)
activationr0   avgavg_poolr0   maxmax_poolMobilenetV3z{}{}_224_{}_float_minimalistic weights_mobilenet_v3_z.h5z_no_top_v2.h5r   )cache_subdir	file_hash)&tfiogfileexists
ValueErrorr   is_keras_tensorr   get_source_inputstypeimage_data_format	int_shapeloggingwarninglayersInputrelu
hard_swish	RescalingConv2DBatchNormalization_depthGlobalAveragePooling2DDropoutFlattenr   validate_activation
ActivationGlobalMaxPooling2Dr   ModelformatstrWEIGHTS_HASHESr   get_fileBASE_WEIGHT_PATHload_weights) stack_fnlast_point_chinput_shapealpha
model_typeminimalisticinclude_topweightsinput_tensorclassespoolingdropout_rateclassifier_activationinclude_preprocessingis_input_t_tensorrowscolsrow_axiscol_axis	img_inputchannel_axiskernelr?   se_ratioxlast_conv_chinputsmodel
model_name	file_namerJ   weights_paths                                    `/home/james-whalen/.local/lib/python3.13/site-packages/tf_keras/src/applications/mobilenet_v3.pyMobileNetV3r      s2     ))RUU[[-?-?-H-H  !(y	*
 	
 *D  'y*
 	
 <#;	 ' 7 7 E ((*.>>$$\215QG$' (3m 4;",,\:;=  H $$\215QG$''2m 4;",,\:;	=  H *'  |7		##L1 ""<00((*.>>((6q9((6q9 $o((6q9((6q9#T1o|3%  "o5#(#(x Dx D$)tbyGm1
 	
 *[(2  4<43;OO) LL{L3	&&|44LLI$I1137GG1RL

A;t<Q?
 	 	 		A 	!!4%>N 	" 			A 	1AFJ1A'++A.|<q@AL s{}45 	 	 		A 	!!4%>P 	" 			A 	1A))4)8;MM  
  qM!|,Q/AMMF  

 NNQ**+@J,=  

 e--:->qAA))z):1=A ..|< LL)CDE *(//<RU

 /*<uDI&z215I/*<NI&z215I!**y(!	
 	<( L 
	7#La  	
$+$;$;11,?%!   $ 3373E2FH 	V  	 \"+ 	s*   +W2 Y 2
Y=*X**$YY#Y8z#keras.applications.MobileNetV3Smallc                 @   ^ U4S jn[        USU TSUUUUUUUU	U
5      $ )Nc           
      ,  > U4S jn[        U SU" S5      SSU[        S5      n [        U SU" S5      SSS [        S5      n [        U S	U" S5      SSS [        S5      n [        U S
U" S5      USX2S5      n [        U SU" S5      USX2S
5      n [        U SU" S5      USX2S5      n [        U SU" S5      USX2S5      n [        U SU" S5      USX2S5      n [        U SU" S5      USX2S5      n [        U SU" S5      USX2S5      n [        U SU" S5      USX2S5      n U $ )Nc                     > [        U T-  5      $ Nr^   dro   s    r   depth1MobileNetV3Small.<locals>.stack_fn.<locals>.depth      !e)$$    r   r)   r   r   r   g      @   gUUUUUU@   (   r7   r&   0      `      	   
   _inverted_res_blockrY   r   r   r?   r   r   ro   s        r   rl   "MobileNetV3Small.<locals>.stack_fn  s[   	%  1eBiAxqI9eBiAtT1M9eBiAtT1Mq%)VQa
  q%)VQa
  q%)VQa
  q%)VQa
  q%)VQa
  q%)VQa
  q%)VQa
  q%)VQb
 r   i   smallr   rn   ro   rq   rr   rs   rt   ru   rv   rw   rx   ry   rl   s    `          r   MobileNetV3Smallr     sB    B  r   z#keras.applications.MobileNetV3Largec                 @   ^ U4S jn[        USU TSUUUUUUUU	U
5      $ )Nc           
      
  > U4S jn[        U SU" S5      SSS [        S5      n [        U SU" S5      SSS [        S5      n [        U SU" S5      SSS [        S5      n [        U SU" S	5      USU[        S5      n [        U SU" S	5      USU[        S5      n [        U SU" S	5      USU[        S
5      n [        U SU" S5      SSS US5      n [        U SU" S5      SSS US5      n [        U SU" S5      SSS US5      n [        U SU" S5      SSS US5      n [        U SU" S5      SSX2S5      n [        U SU" S5      SSX2S5      n [        U SU" S5      USX2S5      n [        U SU" S5      USX2S5      n [        U SU" S5      USX2S5      n U $ )Nc                     > [        U T-  5      $ r   r   r   s    r   r   1MobileNetV3Large.<locals>.stack_fn.<locals>.depth  r   r   r   r)   r   r   r   r   r   r   r&   r7   P   g      @r   gffffff@r   r   p   r                  r   r   s        r   rl   "MobileNetV3Large.<locals>.stack_fn  s   	%  1eBiAtT1E1eBiAtT1E1eBiAtT1E1eBiHdAN1eBiHdAN1eBiHdAN1eBiAtZK3b	1az1M3b	1az1M3b	1az1Mq%*aH"
  q%*aH"
  q%*far
  q%*far
  q%*far
 r   i   larger   r   s    `          r   MobileNetV3Larger     sA    >  r   r   rB   r   c                 6    [         R                  5       " U 5      $ r   rW   ReLUr   s    r   rY   rY   (  s    ;;=r   c                 D    [         R                  S5      " U S-   5      S-  $ )Ng      @g      @gUUUUUU?r   r   s    r   hard_sigmoidr   ,  s    ;;sAG$	22r   c                 L    [         R                  5       " U [        U 5      /5      $ r   )rW   Multiplyr   r   s    r   rZ   rZ   0  s    ??aa122r   c                 j    Uc  Un[        U[        XS-  -   5      U-  U-  5      nUSU -  :  a  X1-  nU$ )Nr   g?)rC   int)vdivisor	min_valuenew_vs       r   r^   r^   ;  sF    		3qQ;/7:WDEEsQwLr   c                 Z   [         R                  SUS-   S9" U 5      n[         R                  [        X-  5      SSUS-   S9" U5      n[         R	                  US-   S	9" U5      n[         R                  USSUS
-   S9" U5      n[        U5      n[         R                  US-   S	9" X/5      nU$ )NTzsqueeze_excite/AvgPool)r:   r0   r   r*   zsqueeze_excite/Convr=   zsqueeze_excite/RelurB   zsqueeze_excite/Conv_1zsqueeze_excite/Mul)rW   r_   r\   r^   r   r   r   )r   filtersr   prefixr   s        r   	_se_blockr   E  s    %%F%== 	& 		A 	w!"++	 	 	
 		A 	"778;A--	 	 	
 		A 	QAV&::;VKHAHr   c                 P   [         R                  " 5       S:X  a  SOSnU n	Sn
[         R                  " U 5      U   nU(       aX  SU S3n
[        R	                  [        X-  5      SSSU
S	-   S
9" U 5      n [        R                  USSU
S-   S9" U 5      n U" U 5      n US:X  a1  [        R                  [        R                  " X5      U
S-   S9" U 5      n [        R                  UUUS:X  a  SOSSU
S-   S9" U 5      n [        R                  USSU
S-   S9" U 5      n U" U 5      n U(       a  [        U [        X-  5      XZ5      n [        R	                  USSSU
S-   S
9" U 5      n [        R                  USSU
S-   S9" U 5      n US:X  a"  X:X  a  [        R                  U
S-   S9" X/5      n U $ )Nr   r   r%   zexpanded_conv/expanded_conv_/r*   Fexpandr9   r1   r2   zexpand/BatchNormr3   r   zdepthwise/pad)r.   r0   valid	depthwise)r-   r.   r/   r0   zdepthwise/BatchNormprojectzproject/BatchNormAddrB   )r   rS   rT   rW   r\   r^   r]   ZeroPadding2Dr   correct_padDepthwiseConv2Dr   r   )r   	expansionr   r,   strider   r?   block_idr   shortcutr   	infilterss               r   r   r   [  s%     1137GG1RLHF!!!$\2I!(1-MM9()("  
  %%,,	 & 

  qM{  "..q>/) ! 
  	 A+7k! 	 	 		A 	!!++	 	" 	
 		A 	1Aa	 56Ii 	 	 		A 	!!))	 	" 	
 		A {y+JJFUNJ+XM:Hr   z0keras.applications.mobilenet_v3.preprocess_inputc                     U $ )a  A placeholder method for backward compatibility.

The preprocessing logic has been included in the mobilenet_v3 model
implementation. Users are no longer required to call this method to
normalize the input data. This method does nothing and only kept as a
placeholder to align the API surface between old and new version of model.

Args:
  x: A floating point `numpy.array` or a `tf.Tensor`.
  data_format: Optional data format of the image tensor/array. `None` means
    the global setting `tf.keras.backend.image_data_format()` is used
    (unless you changed it, it uses "channels_last").
    Defaults to `None`.

Returns:
  Unchanged `numpy.array` or `tf.Tensor`.
 )r   data_formats     r   preprocess_inputr     s	    & Hr   z2keras.applications.mobilenet_v3.decode_predictionsc                 *    [         R                  " XS9$ )N)top)r   decode_predictions)predsr   s     r   r   r     s    ,,U<<r   )Nr!   r   FTr   Nr   N皙?softmaxT)Nr!   FTr   Nr   Nr   r   T)r   Nr   )r&   )$__doc__tensorflow.compat.v2compatv2rK   tf_keras.srcr   r   tf_keras.src.applicationsr   tf_keras.src.layersr   tf_keras.src.utilsr   r   tensorflow.python.platformr	   rU    tensorflow.python.util.tf_exportr
   rj   rh   rW   BASE_DOCSTRINGr   r   r   rf   rY   r   rZ   r^   r   r   r   r   r   r   r   <module>r      s  " ( ! !    4 2 ) * = 9 Q ))+6 
	gZ 
#up 34
#= 5=@ 34
#; 5;| *006H0I  )006H0I  33,@F @A B* BC= D= ,>>FF  r   