
    6biC                        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-   r\S-   r\S-   r\S-   r\S-   r\S-   r\" 5       rS rS rS r       S&S jr\" SS5             S&S j5       r\" SS5             S&S j5       r\" SS5             S&S j5       r \" S5      S'S j5       r!\" S 5      S(S! j5       r"\RF                  RI                  S"\RJ                  \RL                  S#9\!l         \RD                  R                   \"l         S$r'\(" \S%\R                   \'-   5        \(" \S%\R                   \'-   5        \(" \ S%\ R                   \'-   5        g))zDenseNet models for TF-Keras.

Reference:
  - [Densely Connected Convolutional Networks](
      https://arxiv.org/abs/1608.06993) (CVPR 2017)
    N)backend)imagenet_utils)training)VersionAwareLayers)
data_utils)layer_utils)keras_exportzFhttps://storage.googleapis.com/tensorflow/keras-applications/densenet/1densenet121_weights_tf_dim_ordering_tf_kernels.h57densenet121_weights_tf_dim_ordering_tf_kernels_notop.h51densenet169_weights_tf_dim_ordering_tf_kernels.h57densenet169_weights_tf_dim_ordering_tf_kernels_notop.h51densenet201_weights_tf_dim_ordering_tf_kernels.h57densenet201_weights_tf_dim_ordering_tf_kernels_notop.h5c           
      d    [        U5       H   n[        U SUS-   [        US-   5      -   S9n M"     U $ )zA dense block.

Args:
  x: input tensor.
  blocks: integer, the number of building blocks.
  name: string, block label.

Returns:
  Output tensor for the block.
    _block   name)range
conv_blockstr)xblocksr   is       \/home/james-whalen/.local/lib/python3.13/site-packages/tf_keras/src/applications/densenet.pydense_blockr   ?   s6     6]q"4(?SQZ#?@ H    c                 v   [         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 [        R                  [        [         R                  " U 5      U   U-  5      SS
US-   S9" U 5      n [        R                  SSUS-   S9" U 5      n U $ )zA transition block.

Args:
  x: input tensor.
  reduction: float, compression rate at transition layers.
  name: string, block label.

Returns:
  output tensor for the block.
channels_last   r   >_bnaxisepsilonr   relu_relur   F_convuse_biasr      _poolstridesr   )	r   image_data_formatlayersBatchNormalization
ActivationConv2Dint	int_shapeAveragePooling2D)r   	reductionr   bn_axiss       r   transition_blockr:   O   s     ,,./AaqG!!hTE\ 	" 			A 	&tg~6q9AGa )I56	G^	 	 	
 		A 	14'>B1EAHr   c                    [         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[        R                  S
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[        R                  USSSUS-   S9" U5      n[        R                  X2S-   S9" X/5      n U $ )zA building block for a dense block.

Args:
  x: input tensor.
  growth_rate: float, growth rate at dense layers.
  name: string, block label.

Returns:
  Output tensor for the block.
r    r!   r   r"   _0_bnr$   r'   _0_relur      F_1_convr*   _1_bn_1_relusame_2_conv)paddingr+   r   _concat)r%   r   )r   r0   r1   r2   r3   r4   Concatenate)r   growth_rater   r9   x1s        r   r   r   i   s-    ,,./AaqG		"	"hTG^ 
# 

	B 
		6y(8		9"	=B		KU	1A 
 


B 
	"	"hTG^ 
# 


B 
		6y(8		9"	=B	QTI=M 
 


B 	Y.>?HAHr   c           	         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                  X4S
9nOUn[        R                  " 5       S:X  a  SOSn	[        R                  SS9" U5      n
[        R                  SSSSSS9" U
5      n
[        R                  U	SSS9" U
5      n
[        R                  SSS9" U
5      n
[        R                  SS9" U
5      n
[        R!                  SSSS9" U
5      n
[#        XS   S S9n
[%        U
S!S"S9n
[#        XS   S#S9n
[%        U
S!S$S9n
[#        XS   S%S9n
[%        U
S!S&S9n
[#        XS   S'S9n
[        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(                  " Xr5        [        R+                  XgS*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U / S/Q:X  a  [2        R4                  " XS0S9nOQU / S1Q:X  a  [2        R4                  " XS2S9nO3U / S3Q:X  a  [2        R4                  " XS4S9nO[2        R4                  " XS5S9nUS:X  a  U(       al  U / S/Q:X  a  [6        R8                  " S6[:        S7S8S99nOU / S1Q:X  a  [6        R8                  " S:[<        S7S;S99nOU / S3Q:X  a  [6        R8                  " S<[>        S7S=S99nOkU / S/Q:X  a  [6        R8                  " S>[@        S7S?S99nOGU / S1Q:X  a  [6        R8                  " S@[B        S7SAS99nO#U / S3Q:X  a  [6        R8                  " SB[D        S7SCS99nURG                  W5        U$ Ub  URG                  U5        U$ )Da
  Instantiates the DenseNet architecture.

Reference:
- [Densely Connected Convolutional Networks](
    https://arxiv.org/abs/1608.06993) (CVPR 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 DenseNet, call
`tf.keras.applications.densenet.preprocess_input` on your inputs before
passing them to the model. `densenet.preprocess_input` will scale pixels
between 0 and 1 and then will normalize each channel with respect to the
ImageNet dataset statistics.

Args:
  blocks: numbers of building blocks for the four dense layers.
  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 `keras.Model` instance.
>   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.rJ     zWIf using `weights` as `"imagenet"` with `include_top` as true, `classes` should be 1000   r   )default_sizemin_sizedata_formatrequire_flattenweights)shape)tensorrR   r    r!   r   )r!   r!   rT   )rD   @      r,   Fz
conv1/conv)r/   r+   r   r"   zconv1/bnr$   r'   z
conv1/relur   )r   r   rW   pool1r.   r   conv2g      ?pool2conv3pool3conv4pool4conv5bnavg_poolpredictions)
activationr   avgmaxmax_pool            densenet121rh   ri   r   r   densenet169rh   ri   0   r   densenet201densenetr
   models 9d60b8095a5708f2dcce2bca79d332c7)cache_subdir	file_hashr    d699b8f76981ab1b30698df4c175e90br    1ceb130c1ea1b78c3bf6114dbdfd8807r    30ee3e1110167f948a6b9946edeeb738r    b8c4d4c20dd625c148057b9ff1c1176br    c13680b51ded0fb44dff2d8f86ac8bb1)$tfiogfileexists
ValueErrorr   obtain_input_shaper   r0   r1   Inputis_keras_tensorZeroPadding2Dr4   r2   r3   MaxPooling2Dr   r:   GlobalAveragePooling2Dvalidate_activationDenseGlobalMaxPooling2Dr   get_source_inputsr   Modelr   get_fileDENSENET121_WEIGHT_PATHDENSENET169_WEIGHT_PATHDENSENET201_WEIGHT_PATHDENSENET121_WEIGHT_PATH_NO_TOPDENSENET169_WEIGHT_PATH_NO_TOPDENSENET201_WEIGHT_PATH_NO_TOPload_weights)r   include_toprQ   input_tensorinput_shapepoolingclassesclassifier_activation	img_inputr9   r   inputsmodelweights_paths                 r   DenseNetr      sN   T ))RUU[[-?-?-H-H<
 	
 *D1
 	
 !33--/#K LL{L3	&&|44LLI$I,,./AaqG%56yAAb!Q\J1MA!!hZ 	" 			A 	&|4Q7A%56q9AAqw7:AAayw/ACg.AAayw/ACg.AAayw/ACg.AAayw/A!!wt!LQOA&v.q1A))z):1=**+@JLLM  

 e--:->qAA))z):1=A ..|<  v}=	?	"v}=	?	"v}=vz: *()22G+!)@	  ?*)22G+!)@	  ?*)22G+!)@	  ()22M2!)@	  ?*)22M2!)@	  ?*)22M2!)@	  	<( L 
	7#Lr   z'keras.applications.densenet.DenseNet121zkeras.applications.DenseNet121c           
      *    [        / SQU UUUUUU5      $ )z*Instantiates the Densenet121 architecture.rg   r   r   rQ   r   r   r   r   r   s          r   DenseNet121r   Z  )     	 	r   z'keras.applications.densenet.DenseNet169zkeras.applications.DenseNet169c           
      *    [        / SQU UUUUUU5      $ )z*Instantiates the Densenet169 architecture.rm   r   r   s          r   DenseNet169r   s  r   r   z'keras.applications.densenet.DenseNet201zkeras.applications.DenseNet201c           
      *    [        / SQU UUUUUU5      $ )z*Instantiates the Densenet201 architecture.ro   r   r   s          r   DenseNet201r     r   r   z,keras.applications.densenet.preprocess_inputc                 ,    [         R                  " XSS9$ )Ntorch)rO   mode)r   preprocess_input)r   rO   s     r   r   r     s    **	 r   z.keras.applications.densenet.decode_predictionsc                 *    [         R                  " XS9$ )N)top)r   decode_predictions)predsr   s     r   r   r     s    ,,U<<r    )r   reterrora	  

  Reference:
  - [Densely Connected Convolutional Networks](
      https://arxiv.org/abs/1608.06993) (CVPR 2017)

  Optionally loads weights pre-trained on ImageNet.
  Note that the data format convention used by the model is
  the one specified in your TF-Keras config at `~/.keras/keras.json`.

  Note: each TF-Keras Application expects a specific kind of input
   preprocessing. For DenseNet, call
  `tf.keras.applications.densenet.preprocess_input` on your inputs before
  passing them to the model.

  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__)TrJ   NNNrK   softmax)N)   ))r   tensorflow.compat.v2compatv2r|   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	   BASE_WEIGHTS_PATHr   r   r   r   r   r   r1   r   r:   r   r   r   r   r   r   r   PREPROCESS_INPUT_DOCformatPREPROCESS_INPUT_RET_DOC_TORCHPREPROCESS_INPUT_ERROR_DOCDOCsetattr r   r   <module>r      sI    " !   4 ( 2 ) * : M  KK  ?@ 
 KK  ?@ 
 KK  ?@ 
 
	 4@ #Pf -/O #, -/O #, -/O #, <= > >?= @= *>>EE	55

3
3 F   
 ,>>FF  4l Y 3 3c 9 : Y 3 3c 9 : Y 3 3c 9 :r   