
    6biV?                        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S
KJr  SrSq	\" SS5             SS j5       r     SS jr\R2                  R5                  5        " S S\
R6                  5      5       rSS jr\" S5      SS j5       r\" S5      SS j5       r\R@                  RC                  S\RD                  \RF                  S9\l         \R>                  R                   \l         g)zInception-ResNet V2 model for TF-Keras.

Reference:
  - [Inception-v4, Inception-ResNet and the Impact of
     Residual Connections on Learning](https://arxiv.org/abs/1602.07261)
    (AAAI 2017)
    N)backend)layers)imagenet_utils)training)VersionAwareLayers)
data_utils)layer_utils)keras_exportzQhttps://storage.googleapis.com/tensorflow/keras-applications/inception_resnet_v2/z8keras.applications.inception_resnet_v2.InceptionResNetV2z$keras.applications.InceptionResNetV2c           	      	   SU;   a  UR                  S5      qO
[        5       qU(       a  [        SU 35      eUS;   d9  [        R
                  R                  R                  U5      (       d  [        S5      eUS:X  a  U (       a  US:w  a  [        S5      e[        R                  " USS	[        R                  " 5       U US
9nUc  [        R                  US9nO1[        R                  " U5      (       d  [        R                  X#S9nOUn[        USSSSS9n	[        U	SSSS9n	[        U	SS5      n	[        R                  SSS9" U	5      n	[        U	SSSS9n	[        U	SSSS9n	[        R                  SSS9" U	5      n	[        U	SS5      n
[        U	SS5      n[        USS5      n[        U	SS5      n[        USS5      n[        USS5      n[        R!                  SSSS9" U	5      n[        USS5      nXX/n[        R                  " 5       S:X  a  SOSn[        R#                  USS9" U5      n	[%        SS 5       H  n['        U	S!S"US#9n	M     [        U	S$SSSS9n
[        U	S%S5      n[        US%S5      n[        US$SSSS9n[        R                  SSSS9" U	5      nXU/n[        R#                  US&S9" U5      n	[%        SS'5       H  n['        U	S(S)US#9n	M     [        U	S%S5      n
[        U
S$SSSS9n
[        U	S%S5      n[        US*SSSS9n[        U	S%S5      n[        US*S5      n[        US+SSSS9n[        R                  SSSS9" U	5      nXX/n[        R#                  US,S9" U5      n	[%        SS-5       H  n['        U	S.S/US#9n	M     ['        U	S0SS/S-S19n	[        U	S2SS3S49n	U (       aJ  [        R)                  S5S49" U	5      n	[        R*                  " Xa5        [        R-                  XVS6S79" U	5      n	OAUS8:X  a  [        R)                  5       " U	5      n	O US9:X  a  [        R/                  5       " U	5      n	Ub  [0        R2                  " U5      nOUn[4        R6                  " UU	S:S49nUS:X  a[  U (       a!  S;n[8        R:                  " U[<        U-   S<S=S>9nO S?n[8        R:                  " U[<        U-   S<S@S>9nUR?                  U5        U$ Ub  UR?                  U5        U$ )Aa
  Instantiates the Inception-ResNet v2 architecture.

Reference:
- [Inception-v4, Inception-ResNet and the Impact of
   Residual Connections on Learning](https://arxiv.org/abs/1602.07261)
  (AAAI 2017)

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

Args:
  include_top: whether to include the fully-connected
    layer at the top of the network.
  weights: 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.
  input_shape: optional shape tuple, only to be specified
    if `include_top` is `False` (otherwise the input shape
    has to be `(299, 299, 3)` (with `'channels_last'` data format)
    or `(3, 299, 299)` (with `'channels_first'` data format).
    It should have exactly 3 inputs channels,
    and width and height should be no smaller than 75.
    E.g. `(150, 150, 3)` would be one valid value.
  pooling: 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: optional number of classes to classify images
    into, only to be specified if `include_top` is `True`, and
    if no `weights` argument is specified.
  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"`.
  **kwargs: For backwards compatibility only.

Returns:
  A `keras.Model` instance.
r   zUnknown argument(s): >   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.r     zWIf using `weights` as `"imagenet"` with `include_top` as true, `classes` should be 1000i+  K   )default_sizemin_sizedata_formatrequire_flattenweightsN)shape)tensorr             valid)stridespadding)r   @   )r   P         `   0      samechannels_firstmixed_5baxisname   g(\?block35)scale
block_type	block_idxi     mixed_6a   g?block17i   i@  mixed_7a
   g?block8g      ?)r+   
activationr,   r-   i   conv_7br(   avg_poolpredictions)r5   r(   avgmaxinception_resnet_v2z9inception_resnet_v2_weights_tf_dim_ordering_tf_kernels.h5models e693bd0210a403b3192acc6073ad2e96)cache_subdir	file_hashz?inception_resnet_v2_weights_tf_dim_ordering_tf_kernels_notop.h5 d19885ff4a710c122648d3b5c3b684e4) popr   r   
ValueErrortfiogfileexistsr   obtain_input_shaper   image_data_formatInputis_keras_tensor	conv2d_bnMaxPooling2DAveragePooling2DConcatenaterangeinception_resnet_blockGlobalAveragePooling2Dvalidate_activationDenseGlobalMaxPooling2Dr	   get_source_inputsr   Modelr   get_fileBASE_WEIGHT_URLload_weights)include_topr   input_tensorinput_shapepoolingclassesclassifier_activationkwargs	img_inputxbranch_0branch_1branch_2branch_poolbrancheschannel_axisr-   inputsmodelfnameweights_paths                        g/home/james-whalen/.local/lib/python3.13/site-packages/tf_keras/src/applications/inception_resnet_v2.pyInceptionResNetV2ro   -   sM   Z 6H%#%09::))RUU[[-?-?-H-H<
 	
 *D1
 	
 !33--/#K LL{L3	&&|44LLI$I 	)RAw?A!RG,A!RAAq)!,A!RG,A!S!W-AAq)!,A B"HB"H2q)HB"H2q)H2q)H))!Q)GJKKQ/KH:H1137GG1QL:>xHA 1b\	"Ti9
 " CAw?HC#H3*H31gFH%%aG%DQGKK0H:>xHA 1b\	"SY)
 " C#H31gFHC#H31gFHC#H3*H31gFH%%aG%DQGKH:H:>xHA 1b\	"SX
 " 		(b	A
 	!T19-A))z):1=**+@JLLM  

 e--/2A))+A.A ..|< NN61+@AE *OE%..%'%<	L6  &..%'%<	L 	<( L 
	7#L    c           	          [         R                  UUUUUUS9" U 5      n U(       dB  [        R                  " 5       S:X  a  SOSnUc  SOUS-   n	[         R	                  USU	S9" U 5      n Ub#  Uc  SOUS	-   n
[         R                  XZS
9" U 5      n U $ )a  Utility function to apply conv + BN.

Args:
  x: input tensor.
  filters: filters in `Conv2D`.
  kernel_size: kernel size as in `Conv2D`.
  strides: strides in `Conv2D`.
  padding: padding mode in `Conv2D`.
  activation: activation in `Conv2D`.
  use_bias: whether to use a bias in `Conv2D`.
  name: name of the ops; will become `name + '_ac'` for the activation
      and `name + '_bn'` for the batch norm layer.

Returns:
  Output tensor after applying `Conv2D` and `BatchNormalization`.
)r   r   use_biasr(   r$   r   r   N_bnF)r'   r+   r(   _acr7   )r   Conv2Dr   rI   BatchNormalization
Activation)rc   filterskernel_sizer   r   r5   rr   r(   bn_axisbn_nameac_names              rn   rL   rL     s    4 	 	 	 		A 0026FF!A,$D5L%%7%g%N
 ,$D5Lj7:Hrp   c                   :   ^  \ rS rSrU 4S jrU 4S jrS rSrU =r$ )CustomScaleLayeriD  c                 2   > [         TU ]  " S0 UD6  Xl        g )N )super__init__r+   )selfr+   ra   	__class__s      rn   r   CustomScaleLayer.__init__F  s    "6"
rp   c                 ^   > [         TU ]  5       nUR                  SU R                  05        U$ )Nr+   )r   
get_configupdater+   )r   configr   s     rn   r   CustomScaleLayer.get_configJ  s*    #%w

+,rp   c                 2    US   US   U R                   -  -   $ )Nr   r   r+   )r   rj   s     rn   callCustomScaleLayer.callO  s    ay6!9tzz111rp   r   )	__name__
__module____qualname____firstlineno__r   r   r   __static_attributes____classcell__)r   s   @rn   r~   r~   D  s    
2 2rp   r~   c           	      4   US:X  aS  [        U SS5      n[        U SS5      n[        USS5      n[        U SS5      n[        USS5      n[        USS5      nXVU/nOUS:X  a<  [        U SS5      n[        U S	S5      n[        US
SS/5      n[        USSS/5      nXV/nOYUS:X  a<  [        U SS5      n[        U SS5      n[        USSS/5      n[        USSS/5      nXV/nO[        S[        U5      -   5      eUS-   [        U5      -   n	[        R                  " 5       S:X  a  SOSn
[
        R                  XS-   S9" U5      n[        U[        R                  " U 5      U
   SSSU	S-   S9n[        U5      " X/5      n Ub  [
        R                  XIS-   S9" U 5      n U $ )a  Adds an Inception-ResNet block.

This function builds 3 types of Inception-ResNet blocks mentioned
in the paper, controlled by the `block_type` argument (which is the
block name used in the official TF-slim implementation):
- Inception-ResNet-A: `block_type='block35'`
- Inception-ResNet-B: `block_type='block17'`
- Inception-ResNet-C: `block_type='block8'`

Args:
  x: input tensor.
  scale: scaling factor to scale the residuals (i.e., the output of passing
    `x` through an inception module) before adding them to the shortcut
    branch. Let `r` be the output from the residual branch, the output of
    this block will be `x + scale * r`.
  block_type: `'block35'`, `'block17'` or `'block8'`, determines the network
    structure in the residual branch.
  block_idx: an `int` used for generating layer names. The Inception-ResNet
    blocks are repeated many times in this network. We use `block_idx` to
    identify each of the repetitions. For example, the first
    Inception-ResNet-A block will have `block_type='block35', block_idx=0`,
    and the layer names will have a common prefix `'block35_0'`.
  activation: activation function to use at the end of the block (see
    [activations](../activations.md)). When `activation=None`, no activation
    is applied
    (i.e., "linear" activation: `a(x) = x`).

Returns:
    Output tensor for the block.

Raises:
  ValueError: if `block_type` is not one of `'block35'`,
    `'block17'` or `'block8'`.
r*   r   r   r   r!   r   r1   r            r4      r.   zXUnknown Inception-ResNet block type. Expects "block35", "block17" or "block8", but got: _r$   _mixedr&   NT_conv)r5   rr   r(   rt   r7   )
rL   rC   strr   rI   r   rO   	int_shaper~   rw   )rc   r+   r,   r-   r5   rd   re   rf   rh   
block_nameri   mixedups                rn   rQ   rQ   S  s   F YQA&QA&Xr1-QA&Xr1-Xr1-1	y	 QQ'QQ'XsQF3XsQF3'	x	QQ'QQ'XsQF3XsQF3'j/*
 	
 c!C	N2J1137GG1QLLH7LME 
!\*	'!
B 	(AjE/AB1EHrp   z7keras.applications.inception_resnet_v2.preprocess_inputc                 ,    [         R                  " XSS9$ )NrD   )r   mode)r   preprocess_input)rc   r   s     rn   r   r     s    **	 rp   z9keras.applications.inception_resnet_v2.decode_predictionsc                 *    [         R                  " XS9$ )N)top)r   decode_predictions)predsr   s     rn   r   r     s    ,,U<<rp    )r   reterror)Tr   NNNr   softmax)r   r#   reluFN)r   )N)r"   )$__doc__tensorflow.compat.v2compatv2rD   tf_keras.srcsrckerasr   r   keras_layerstf_keras.src.applicationsr   tf_keras.src.enginer   tf_keras.src.layersr   tf_keras.src.utilsr   r	    tensorflow.python.util.tf_exportr
   rY   ro   rL   utilsregister_keras_serializableLayerr~   rQ   r   r   PREPROCESS_INPUT_DOCformatPREPROCESS_INPUT_RET_DOC_TFPREPROCESS_INPUT_ERROR_DOCr   rp   rn   <module>r      sI    " !    / 4 ( 2 ) * :.  
 >*
 #b	bR 	+\ ((*2|)) 2 +2Od GH I IJ= K= *>>EE	22

3
3 F   
 ,>>FF  rp   