
    &VfF                        d dl Z d dlmZ d dlmZ d dlmZ d dlmZ d dlm	Z	 d dl
mZ d dlmZ d	Z ed
dg          	 	 	 	 	 	 	 	 dd            Zd ZddZ ed          dd            Z ed          dd            Zej                            dej        ej                  e_        ej        j        e_        dS )    N)backend)layers)keras_export)imagenet_utils)
Functional)operation_utils)
file_utilszJhttps://storage.googleapis.com/tensorflow/keras-applications/mobilenet_v2/z+keras.applications.mobilenet_v2.MobileNetV2zkeras.applications.MobileNetV2      ?Timagenet  softmaxc           
         |dv s't          j        |          st          d| d          |dk    r|r|dk    rt          d| d          | |	 t          j        |          }ni# t          $ r\ 	 t          j        t          j        |                    }n1# t          $ r$ t          d| d	t          |           d          w xY wY nw xY w|r}t          j                    d
k    r3|j	        d         | d         k    rt          d|j	         d|  d          nF|j	        d         | d         k    rt          d|j	         d|  d          nt          d| d          | |	 t          j        |           n0# t          $ r# t          d| dt          |                     w xY w| t          j        |          sd}	n| ot          j        |          r[t          j                    d
k    r|j	        d         }
|j	        d         }n|j	        d         }
|j	        d         }|
|k    r|
dv r|
}	nOd}	nL| d}	nGt          j                    d
k    r| d         }
| d         }n| d         }
| d         }|
|k    r|
dv r|
}	nd}	t          j        | |	dt          j                    ||          } t          j                    dk    rd\  }}nd\  }}| |         }
| |         }|dk    r9|dvrt          d| d          |
|k    s|
dvrd}
t          j        dd           |t          j        |            }n-t          j        |          st          j        || !          }n|}t          j                    d
k    rdnd"}t!          d|z  d#          } t          j        |dd$d%d&d'(          |          } t          j        |d)d*d+,          |          } t          j        d-d./          |          }t)          |d0|ddd1          }t)          |d2|dd3d1          }t)          |d2|dd3d1          }t)          |d|dd3d1          }t)          |d|dd3d41          }t)          |d|dd3d51          }t)          |d6|dd3d31          }t)          |d6|dd3d71          }t)          |d6|dd3d#1          }t)          |d6|dd3d81          }t)          |d9|dd3d:1          }t)          |d9|dd3d;1          }t)          |d9|dd3d<1          }t)          |d=|dd3d>1          }t)          |d=|dd3d?1          }t)          |d=|dd3d@1          }t)          |dA|dd3d01          }|dBk    rt!          dC|z  d#          }ndC} t          j        |dd&dDE          |          } t          j        |d)d*dF,          |          } t          j        d-dG/          |          }|rR t          j                    |          }t          j        ||            t          j        ||dHI          |          }nE|dJk    r t          j                    |          }n"|dKk    r t          j                    |          }|t          j        |          }n|}t3          ||dL|dMdN|
 /          }|dk    r|rWdOt5          t7          |                    z   dNz   t5          |
          z   dPz   }t8          |z   }t          j        ||dQR          }nYdOt5          t7          |                    z   dNz   t5          |
          z   dSz   dPz   }t8          |z   }t          j        ||dQR          }|                    |           n||                    |           |S )Ta  Instantiates the MobileNetV2 architecture.

    MobileNetV2 is very similar to the original MobileNet,
    except that it uses inverted residual blocks with
    bottlenecking features. It has a drastically lower
    parameter count than the original MobileNet.
    MobileNets support any input size greater
    than 32 x 32, with larger image sizes
    offering better performance.

    Reference:
    - [MobileNetV2: Inverted Residuals and Linear Bottlenecks](
        https://arxiv.org/abs/1801.04381) (CVPR 2018)

    This function returns a Keras image classification model,
    optionally loaded with weights pre-trained on ImageNet.

    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 Keras Application expects a specific kind of input preprocessing.
    For MobileNetV2, call
    `keras.applications.mobilenet_v2.preprocess_input`
    on your inputs before passing them to the model.
    `mobilenet_v2.preprocess_input` will scale input pixels between -1 and 1.

    Args:
        input_shape: Optional shape tuple, only to be specified if `include_top`
            is `False` (otherwise the input shape has to be `(224, 224, 3)`
            (with `"channels_last"` data format) or `(3, 224, 224)`
            (with `"channels_first"` data format).
            It should have exactly 3 inputs channels, and width and
            height should be no smaller than 32. E.g. `(200, 200, 3)` would
            be one valid value. Defaults to `None`.
            `input_shape` will be ignored if the `input_tensor` is provided.
        alpha: Controls the width of the network. This is known as the width
            multiplier in the MobileNet paper.
            - 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. Defaults to `1.0`.
        include_top: Boolean, whether to include the fully-connected layer
            at the top of the network. Defaults to `True`.
        weights: One of `None` (random initialization), `"imagenet"`
            (pre-training on ImageNet), or the path to the weights file
            to be loaded. Defaults to `"imagenet"`.
        input_tensor: Optional Keras tensor (i.e. output of `layers.Input()`)
            to use as image input for the model. `input_tensor` is useful
            for sharing inputs between multiple different networks.
            Defaults to `None`.
        pooling: Optional pooling mode for feature extraction when `include_top`
            is `False`.
            - `None` (default) 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: Optional number of classes to classify images into,
            only to be specified if `include_top` is `True`, and if
            no `weights` argument is specified. Defaults to `1000`.
        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"`.

    Returns:
        A model instance.
    >   Nr   zThe `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   r   zfIf using `weights="imagenet"` with `include_top` as true, `classes` should be 1000. Received `classes=Nzinput_tensor: z7is not type input_tensor. Received `type(input_tensor)=channels_first   z|input_shape[1] must equal shape(input_tensor)[1] when `image_data_format` is `channels_first`; Received `input_tensor.shape=z`, `input_shape=   zNinput_tensor.shape[2] must equal input_shape[1]; Received `input_tensor.shape=z;input_tensor is not a Keras tensor; Received `input_tensor=z9input_tensor must be a valid Keras tensor type; Received z	 of type       )`            r   r       )default_sizemin_sizedata_formatrequire_flattenweightschannels_last)r   r   )r   r   )gffffff?g      ?g      ?r
   g?gffffff?zIf imagenet weights are being loaded, alpha must be one of `0.35`, `0.50`, `0.75`, `1.0`, `1.3` or `1.4` only; Received `alpha=z`input_shape` is undefined or non-square, or `rows` is not in [96, 128, 160, 192, 224]. Weights for input shape (224, 224) will be loaded as the default.)
stacklevel)shape)tensorr!      )r   r   sameFConv1)kernel_sizestridespaddinguse_biasnameMbP?+?bn_Conv1axisepsilonmomentumr+         @
Conv1_relur+      )filtersalphastride	expansionblock_id            @      	   r   
         r            i@  r
   i   Conv_1)r'   r*   r+   	Conv_1_bnout_relupredictions)
activationr+   avgmaxmobilenetv2_z0.2f_0mobilenet_v2_weights_tf_dim_ordering_tf_kernels_z.h5models)cache_subdir_no_top)r	   exists
ValueErrorr   is_keras_tensorr   get_source_inputstypeimage_data_formatr!   r   obtain_input_shapewarningswarnr   Input_make_divisibleConv2DBatchNormalizationReLU_inverted_res_blockGlobalAveragePooling2Dvalidate_activationDenseGlobalMaxPooling2Dr   strfloatBASE_WEIGHT_PATHget_fileload_weights)input_shaper8   include_topr   input_tensorpoolingclassesclassifier_activationis_input_t_tensorr   rowscolsrow_axiscol_axis	img_inputchannel_axisfirst_block_filtersxlast_block_filtersinputsmodel
model_nameweight_pathweights_paths                           `/var/www/html/software/conda/lib/python3.11/site-packages/keras/src/applications/mobilenet_v2.pyMobileNetV2r      s   | )))Z->w-G-G), ")	, , ,
 
 	
 *DODKO O O
 
 	
 <#;	 ' 7 E E 
	 
	 
		$+$;#5lCC% %!!     J\ J J484F4FJ J J   "!
	  	(**.>>>%a(KN::$9 (-9 9 +6	9 9 9   ;  %a(KN::$7'-7 7 )47 7 7   ; :*6: : :   |7	#L1111 	 	 	H(H H373E3EH H  	 w'>|'L'LLL W%<\%J%J (**.>>>#)!,#)!,#)!,#)!,t||(@ @ @#" 
	 $&&*:::q>Dq>DDq>Dq>D4<<D$<<<LLL 3!-//#  K  ""o55#((#(x Dx D*999- %*- - -   4<<4'???DM)     L{333		&|44 	%LLLLII$I1337GGG11RL)"u*a88		 	 	 	 	A	!4%j	 	 			 		A 	,Cl+++A..A	2U1A	 	 	A 		2U1A	 	 	A 		2U1A	 	 	A 		2U1A	 	 	A 		2U1A	 	 	A 		2U1A	 	 	A 		2U1A	 	 	A 		2U1A	 	 	A 		2U1A	 	 	A 		2U1A	 	 	A 		2U1B	 	 	A 		2U1B	 	 	A 		2U1B	 	 	A 		3eAR	 	 	A 		3eAR	 	 	A 		3eAR	 	 	A 		3eAR	 	 	A s{{,TE\1==!	E	 	 			 		A	!4%k	 	 			 		A 	*Cj)))!,,A /+F)++A..*+@'JJJ
FL 5M
 
 

 
 e/-//22AA+)++A..A  2<@@ vq'Ie'I'I'I4'I'IJJJE * 	BeEll##$ d)) 	  +Z7K%.Kh  LL
 CeEll##$ d)) 	
   +Z7K%.Kh  L 	<((((		7###Ls6   A) )
C4&BC.C		CC)E> >-F+c           
         t          j                    dk    rdnd}| j        |         }t          ||z            }t	          |d          }	| }
d| d}|rp t          j        ||z  dddd	|d
z             |
          }
 t          j        |dd|dz             |
          }
 t          j        d|dz             |
          }
nd}|dk    r5 t          j	        t          j        |
d          |dz             |
          }
 t          j        d|d	d|dk    rdnd|dz             |
          }
 t          j        |dd|dz             |
          }
 t          j        d|dz             |
          }
 t          j        |	dddd	|dz             |
          }
 t          j        |dd|dz             |
          }
||	k    r)|dk    r# t          j        |dz             | |
g          S |
S ) zInverted ResNet block.r   r   r#   r$   block_rQ   r%   FNexpand)r'   r)   r*   rM   r+   r,   r-   	expand_BNr/   r3   expand_relur5   expanded_conv_r   r   pad)r)   r+   valid	depthwise)r'   r(   rM   r*   r)   r+   depthwise_BNdepthwise_reluproject
project_BNadd)r   r[   r!   intr`   r   ra   rb   rc   ZeroPadding2Dr   correct_padDepthwiseConv2DAdd)r~   r:   r9   r8   r7   r;   rz   in_channelspointwise_conv_filterspointwise_filtersr|   prefixs               r   rd   rd     s   1337GGG11RL,|,K 511 ((>BBA!h!!!F "
FM#("
 
 
  
F%+%	
 
 

   :FK&="8999!<<! {{
F ".q!446E>
 
 

 	 A++7k!	 	 	 		 		A	!n$		 	 	
 		 		A 	9Cf'77888;;A	i	 	 	 		 		A	!l"		 	 	
 		 		A '''FaKK.vzv~...{;;;H    c                 |    ||}t          |t          | |dz  z             |z  |z            }|d| z  k     r||z  }|S )Nr   g?)rO   r   )vdivisor	min_valuenew_vs       r   r`   r`     sR    		3q7Q;//7:WDEEEsQwLr   z0keras.applications.mobilenet_v2.preprocess_inputc                 0    t          j        | |d          S )Ntf)r   mode)r   preprocess_input)r|   r   s     r   r   r     s#    *	{   r   z2keras.applications.mobilenet_v2.decode_predictionsr?   c                 .    t          j        | |          S )N)top)r   decode_predictions)predsr   s     r   r   r     s    ,U<<<<r    )r   reterror)Nr
   Tr   NNr   r   )N)r?   )r]   	keras.srcr   r   keras.src.api_exportr   keras.src.applicationsr   keras.src.modelsr   keras.src.opsr   keras.src.utilsr	   rk   r   rd   r`   r   r   PREPROCESS_INPUT_DOCformatPREPROCESS_INPUT_RET_DOC_TFPREPROCESS_INPUT_ERROR_DOC__doc__ r   r   <module>r      s                - - - - - - 1 1 1 1 1 1 ' ' ' ' ' ' ) ) ) ) ) ) & & & & & & Q 
 5(  
#u u u upH H HV    @AA   BA BCC= = = DC= *>EE	2

3 F    
 ,>F    r   