
    6bi$W              	          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
rSSSSSSSSS.rSq        S/S jrS0S jrS1S jrS2S jrS1S jr     S3S jrS4S jr\" SSS5            S5S j5       r\" SS 5            S5S! j5       r\" S"S#5            S5S$ j5       r\" S%S&5      S6S' j5       r\" S(S)5      S7S* j5       r \RB                  RE                  S+\RF                  \RH                  S,9\l         \R@                  R                   \ l         S-r%\&" \S.\R                   \%-   5        \&" \S.\R                   \%-   5        \&" \S.\R                   \%-   5        g)8zResNet models for TF-Keras.

Reference:
  - [Deep Residual Learning for Image Recognition](
      https://arxiv.org/abs/1512.03385) (CVPR 2015)
    N)backend)imagenet_utils)training)VersionAwareLayers)
data_utils)layer_utils)keras_exportzDhttps://storage.googleapis.com/tensorflow/keras-applications/resnet/) 2cb95161c43110f7111970584f804107 4d473c1dd8becc155b73f8504c6f6626) f1aeb4b969a6efcfb50fad2f0c20cfc5 88cf7a10940856eca736dc7b7e228a21) 100835be76be38e30d865e96f2aaae62 ee4c566cf9a93f14d82f913c2dc6dd0c) 3ef43a0b657b3be2300d5770ece849e0 fac2f116257151a9d068a22e544a4917) 6343647c601c52e1368623803854d971 c0ed64b8031c3730f411d2eb4eea35b5) a49b44d1979771252814e80f8ec446f9 ed17cf2e0169df9d443503ef94b23b33) 67a5b30d522ed92f75a1f16eef299d1a 62527c363bdd9ec598bed41947b379fc) 34fb605428fcc7aa4d62f44404c11509 0f678c91647380debd923963594981b3)resnet50	resnet101	resnet152
resnet50v2resnet101v2resnet152v2	resnext50
resnext101c           	         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                  XgS9nOUn[        R                  " 5       S:X  a  SOSn[        R                  SSS9" U5      n[        R                  SSSUSS9" U5      nU(       d5  [        R!                  USSS9" U5      n[        R#                  SSS9" U5      n[        R                  SSS9" U5      n[        R%                  SSS S!9" U5      nU " U5      nU(       a5  [        R!                  USS"S9" U5      n[        R#                  SS#S9" U5      nU(       aJ  [        R'                  S$S9" U5      n[        R(                  " X5        [        R+                  XS%S&9" U5      nO?US':X  a  [        R'                  S$S9" U5      nOUS(:X  a  [        R-                  S)S9" U5      nUb  [.        R0                  " U5      nOUn[2        R4                  " XUS9nUS:X  ae  U[6        ;   a[  U(       a  US*-   n[6        U   S+   nOUS,-   n[6        U   S   n[8        R:                  " U[<        U-   S-US.9nUR?                  U5        U$ Ub  UR?                  U5        U$ )/a"  Instantiates the ResNet, ResNetV2, and ResNeXt architecture.

Args:
  stack_fn: a function that returns output tensor for the
    stacked residual blocks.
  preact: whether to use pre-activation or not
    (True for ResNetV2, False for ResNet and ResNeXt).
  use_bias: whether to use biases for convolutional layers or not
    (True for ResNet and ResNetV2, False for ResNeXt).
  model_name: string, model name.
  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 `(224, 224, 3)` (with `channels_last` data format)
    or `(3, 224, 224)` (with `channels_first` data format).
    It should have exactly 3 inputs channels.
  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 layer.
    - `avg` means that global average pooling
        will be applied to the output of the
        last convolutional layer, 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.
layersz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 1000       )default_sizemin_sizedata_formatrequire_flattenweights)shape)tensorr-   channels_last      )r0   r0   r2   	conv1_padpaddingname@         
conv1_convstridesuse_biasr6   >conv1_bnaxisepsilonr6   relu
conv1_relur6   r1   r1   rG   	pool1_pad
pool1_poolr<   r6   post_bn	post_reluavg_poolpredictions)
activationr6   avgmaxmax_poolz&_weights_tf_dim_ordering_tf_kernels.h5r   z,_weights_tf_dim_ordering_tf_kernels_notop.h5models)cache_subdir	file_hash) popr#   r   
ValueErrortfiogfileexistsr   obtain_input_shaper   image_data_formatInputis_keras_tensorZeroPadding2DConv2DBatchNormalization
ActivationMaxPooling2DGlobalAveragePooling2Dvalidate_activationDenseGlobalMaxPooling2Dr   get_source_inputsr   ModelWEIGHTS_HASHESr   get_fileBASE_WEIGHTS_PATHload_weights)stack_fnpreactr=   
model_nameinclude_topr,   input_tensorinput_shapepoolingclassesclassifier_activationkwargs	img_inputbn_axisxinputsmodel	file_namerU   weights_paths                       Z/home/james-whalen/.local/lib/python3.13/site-packages/tf_keras/src/applications/resnet.pyResNetr   L   sr   | 6H%#%09::))RUU[[-?-?-H-H<
 	
 *D1
 	
 !33--/#K LL{L3	&&|44LLI$I,,./AaqG%5KH	A 	b!QMaPA%%( & 

 f<8;%5KHKAAq|<Q?AA%%( & 

 f;7:))z):1=**+@JLLM  

 e--:->qAA))z):1=A ..|< NN6:6E 	:J.$@"%MMI&z215I KK  'z215I!**	)!	
 	<( L 
	7#L    c                 (   [         R                  " 5       S:X  a  SOSnU(       a@  [        R                  SU-  SX5S-   S9" U 5      n[        R	                  USUS-   S	9" U5      nOU n[        R                  USX5S
-   S9" U 5      n [        R	                  USUS-   S	9" U 5      n [        R                  SUS-   S9" U 5      n [        R                  XSUS-   S9" U 5      n [        R	                  USUS-   S	9" U 5      n [        R                  SUS-   S9" U 5      n [        R                  SU-  SUS-   S9" U 5      n [        R	                  USUS-   S	9" U 5      n [        R                  US-   S9" Xp/5      n [        R                  SUS-   S9" U 5      n U $ )a  A residual block.

Args:
  x: input tensor.
  filters: integer, filters of the bottleneck layer.
  kernel_size: default 3, kernel size of the bottleneck layer.
  stride: default 1, stride of the first layer.
  conv_shortcut: default True, use convolution shortcut if True,
      otherwise identity shortcut.
  name: string, block label.

Returns:
  Output tensor for the residual block.
r/   r0   r1      _0_convrJ   r>   _0_bnr@   _1_conv_1_bnrC   _1_relurE   SAME_2_convr4   _2_bn_2_relu_3_conv_3_bn_add_out)r   r]   r#   ra   rb   rc   Add)r{   filterskernel_sizestrideconv_shortcutr6   rz   shortcuts           r   block1r      s    ,,./AaqG==KF	1A ! 

 ,,( - 

 gq&i7GHKA!!hTG^ 	" 			A 	&ti'78;Af4)3C 	 			A 	!!hTG^ 	" 			A 	&ti'78;Aa'k14)+;<Q?A!!hTG^ 	" 			A 	

v
&}5A&tf}5a8AHr   c           
          [        XX4S-   S9n [        SUS-   5       H  n[        XSUS-   [        U5      -   S9n M     U $ )a@  A set of stacked residual blocks.

Args:
  x: input tensor.
  filters: integer, filters of the bottleneck layer in a block.
  blocks: integer, blocks in the stacked blocks.
  stride1: default 2, stride of the first layer in the first block.
  name: string, stack label.

Returns:
  Output tensor for the stacked blocks.
_block1r   r6   r9   r1   F_blockr   r6   )r   rangestrr{   r   blocksstride1r6   is         r   stack1r   (  sO     	q'y0@AA1fqj!e$/CF2J
 " Hr   c                 n   [         R                  " 5       S:X  a  SOSn[        R                  USUS-   S9" U 5      n[        R	                  SUS-   S	9" U5      nU(       a"  [        R                  S
U-  SX5S-   S9" U5      nO"US:  a  [        R                  SUS9" U 5      OU n[        R                  USSSUS-   S9" U5      n [        R                  USUS-   S9" U 5      n [        R	                  SUS-   S	9" U 5      n [        R                  SUS-   S9" U 5      n [        R                  UUUSUS-   S9" U 5      n [        R                  USUS-   S9" U 5      n [        R	                  SUS-   S	9" U 5      n [        R                  S
U-  SUS-   S	9" U 5      n [        R                  US-   S	9" X/5      n U $ )a  A residual block.

Args:
    x: input tensor.
    filters: integer, filters of the bottleneck layer.
    kernel_size: default 3, kernel size of the bottleneck layer.
    stride: default 1, stride of the first layer.
    conv_shortcut: default False, use convolution shortcut if True,
      otherwise identity shortcut.
    name: string, block label.

Returns:
  Output tensor for the residual block.
r/   r0   r1   r>   
_preact_bnr@   rC   _preact_relurE   r   r   rJ   )r<   Fr   r;   r   r   rF   _2_padr4   r   r   r   r   r   )	r   r]   r#   rb   rc   ra   rd   r`   r   )	r{   r   r   r   r   r6   rz   rp   r   s	            r   block2r   =  s    ,,./AaqG&&hTL-@ ' 	F vD>,AB6JF==KF	1A ! 


 :@!F6215 	 	AD94D 	 		A 	!!hTG^ 	" 			A 	&ti'78;A%5D8OLQOAI 	 	 		A 	!!hTG^ 	" 			A 	&ti'78;Aa'k14)+;<Q?A

v
&}5AHr   c           	          [        XSUS-   S9n [        SU5       H  n[        XUS-   [        U5      -   S9n M     [        XX4S-   [        U5      -   S9n U $ )aL  A set of stacked residual blocks.

Args:
    x: input tensor.
    filters: integer, filters of the bottleneck layer in a block.
    blocks: integer, blocks in the stacked blocks.
    stride1: default 2, stride of the first layer in the first block.
    name: string, stack label.

Returns:
    Output tensor for the stacked blocks.
Tr   r   r9   r   rE   r   )r   r   r   r   s         r   stack2r   v  s_     	qD94DEA1f1D8Oc!f$<= q'x#f+0MNAHr   c           	        ^
 [         R                  " 5       S:X  a  SOSnU(       aE  [        R                  SU-  U-  SUSUS-   S9" U 5      n[        R	                  USUS	-   S
9" U5      nOU n[        R                  USSUS-   S9" U 5      n [        R	                  USUS-   S
9" U 5      n [        R                  SUS-   S9" U 5      n X-  m
[        R                  SUS-   S9" U 5      n [        R                  UUT
SUS-   S9" U 5      n [         R                  " U 5      SS n	[         R                  " U [         R                  " XT
T
4/5      5      n [        R                  U
4S jUS-   S9" U 5      n [         R                  " U [         R                  " X4/5      5      n [        R	                  USUS-   S
9" U 5      n [        R                  SUS-   S9" U 5      n [        R                  SU-  U-  SSUS-   S9" U 5      n [        R	                  USUS-   S
9" U 5      n [        R                  US-   S9" X/5      n [        R                  SUS-   S9" U 5      n U $ ) a  A residual block.

Args:
  x: input tensor.
  filters: integer, filters of the bottleneck layer.
  kernel_size: default 3, kernel size of the bottleneck layer.
  stride: default 1, stride of the first layer.
  groups: default 32, group size for grouped convolution.
  conv_shortcut: default True, use convolution shortcut if True,
      otherwise identity shortcut.
  name: string, block label.

Returns:
  Output tensor for the residual block.
r/   r0   r1   r7   Fr   r;   r>   r   r@   r   )r=   r6   r   rC   r   rE   rF   r   r4   r   )r<   depth_multiplierr=   r6   Nc                 B   >^  [        U 4S j[        T5       5       5      $ )Nc              3   H   >#    U  H  nTS S 2S S 2S S 2S S 2U4   v   M     g 7fN ).0r   r{   s     r   	<genexpr>+block3.<locals>.<lambda>.<locals>.<genexpr>  s      91a1aA&s   ")sumr   )r{   cs   `r   <lambda>block3.<locals>.<lambda>  s    #9a99r   	_2_reducer   r   r   r   r   r   )r   r]   r#   ra   rb   rc   r`   DepthwiseConv2Dr-   reshapeconcatenateLambdar   )r{   r   r   r   groupsr   r6   rz   r   x_shaper   s             @r   block3r     s   0 ,,./AaqG==6\W$	! ! 
  ,,( - 

 gq5ti7GHKA!!hTG^ 	" 			A 	&ti'78;AA%5D8OLQOAI 	 	 		A mmAs#G7..!Q/HIJA9K 	 	 		A 	7../DEFA!!hTG^ 	" 			A 	&ti'78;A	v !e$:J 	 			A 	!!hTG^ 	" 			A 	

v
&}5A&tf}5a8AHr   c                     [        XX4US-   S9n [        SUS-   5       H  n[        U UUSUS-   [        U5      -   S9n M!     U $ )az  A set of stacked residual blocks.

Args:
  x: input tensor.
  filters: integer, filters of the bottleneck layer in a block.
  blocks: integer, blocks in the stacked blocks.
  stride1: default 2, stride of the first layer in the first block.
  groups: default 32, group size for grouped convolution.
  name: string, stack label.

Returns:
  Output tensor for the stacked blocks.
r   )r   r   r6   r9   r1   Fr   )r   r   r6   )r   r   r   )r{   r   r   r   r   r6   r   s          r   stack3r     sY     	q'ti?OPA1fqj!3q6)
 " Hr   z$keras.applications.resnet50.ResNet50z"keras.applications.resnet.ResNet50zkeras.applications.ResNet50c                 2    S n[        USSSU UUUUU4
0 UD6$ )z'Instantiates the ResNet50 architecture.c                 d    [        U SSSSS9n [        U SSSS	9n [        U S
SSS	9n [        U SSSS	9$ )Nr7   r0   r1   conv2r   r6      r   conv3rE         conv4   conv5r   r{   s    r   ro   ResNet50.<locals>.stack_fn  sE    1b!QW51c17+1c17+aag..r   FTr   r   rr   r,   rs   rt   ru   rv   rx   ro   s           r   ResNet50r     s>     /   r   z#keras.applications.resnet.ResNet101zkeras.applications.ResNet101c                 2    S n[        USSSU UUUUU4
0 UD6$ )z(Instantiates the ResNet101 architecture.c                 d    [        U SSSSS9n [        U SSSS	9n [        U S
SSS	9n [        U SSSS	9$ )Nr7   r0   r1   r   r   r   r   r   rE   r      r   r   r   r   r   s    r   ro   ResNet101.<locals>.stack_fn&  E    1b!QW51c17+1c2G,aag..r   FTr   r   r   s           r   	ResNet101r     >    /   r   z#keras.applications.resnet.ResNet152zkeras.applications.ResNet152c                 2    S n[        USSSU UUUUU4
0 UD6$ )z(Instantiates the ResNet152 architecture.c                 d    [        U SSSSS9n [        U SSSS	9n [        U S
SSS	9n [        U SSSS	9$ )Nr7   r0   r1   r   r   r      r   rE   r   $   r   r   r   r   r   s    r   ro   ResNet152.<locals>.stack_fnI  r   r   FTr   r   r   s           r   	ResNet152r   ;  r   r   z,keras.applications.resnet50.preprocess_inputz*keras.applications.resnet.preprocess_inputc                 ,    [         R                  " XSS9$ )Ncaffe)r*   mode)r   preprocess_input)r{   r*   s     r   r   r   ^  s    
 **	 r   z.keras.applications.resnet50.decode_predictionsz,keras.applications.resnet.decode_predictionsc                 *    [         R                  " XS9$ )N)top)r   decode_predictions)predsr   s     r   r   r   h  s    
 ,,U<<r    )r   reterroraB
  

  Reference:
  - [Deep Residual Learning for Image Recognition](
      https://arxiv.org/abs/1512.03385) (CVPR 2015)

  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 ResNet, call
  `tf.keras.applications.resnet.preprocess_input` on your inputs before passing
  them to the model. `resnet.preprocess_input` will convert the input images
  from RGB to BGR, then will zero-center each color channel with respect to the
  ImageNet dataset, without scaling.

  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 `(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.
    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"`.

  Returns:
    A TF-Keras model instance.
__doc__)resnetTr$   NNNr%   softmax)r0   r1   TN)r9   N)r0   r1   FN)r0   r1   r'   TN)r9   r'   N)Tr$   NNNr%   r   )   )'r   tensorflow.compat.v2compatv2rX   tf_keras.srcr   tf_keras.src.applicationsr   tf_keras.src.enginer   tf_keras.src.layersr   tf_keras.src.utilsr   r    tensorflow.python.util.tf_exportr	   rm   rk   r#   r   r   r   r   r   r   r   r   r   r   r   r   PREPROCESS_INPUT_DOCformatPREPROCESS_INPUT_RET_DOC_CAFFEPREPROCESS_INPUT_ERROR_DOCDOCsetattrr   r   r   <module>r      s9    " !   4 ( 2 ) * : K ;!F 
 #fR0f*6r. 	L^4 *(! 
@ )+I @ )+I @ 20	 42=	= *>>EE	55

3
3 F   
 ,>>FF  :x )X--3 4 	9i//#5 6 	9i//#5 6r   