ó
    6êbi`3  ã                   óò   • S r SSKrSSKrSSK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rSrS r\	" S	S
5      SS j5       r\	" SS5       SS j5       rSS jrSS jrS rg! \ a    Sr N@f = f)z#Public API surface for saving APIs.é    N)Úkeras_export)Ú
saving_lib)Úsave)Úio_utilsTc                 ó,  • Sn[        U 5      R                  S5      (       aq  US:w  ak  U nU(       d  U R                  SS5      n[        R                  R                  [        R                  " 5       [        R                  R                  U5      5      n X04$ )z8Supports GCS URIs through bigstore via a temporary file.Nzgs://Útfz
/bigstore/)	ÚstrÚ
startswithÚreplaceÚosÚpathÚjoinr   Úget_temp_dirÚbasename)ÚfilepathÚsave_formatÚis_ossÚgs_filepaths       ÚX/home/james-whalen/.local/lib/python3.13/site-packages/tf_keras/src/saving/saving_api.pyÚ_support_gcs_urir   $   sw   € à€KÜ
ˆ8ƒ}×Ñ ×(Ñ(¨[¸DÓ-@ØˆÞØ"×*Ñ*¨7°LÓAˆKÜ—7‘7—<‘<Ü×#Ò#Ó%¤r§w¡w×'7Ñ'7¸Ó'Dó
ˆð Ð Ð ó    zkeras.saving.save_modelzkeras.models.save_modelc                 óö  • [        X5      n[        X[        5      u  pQUS:X  a  [        R                  " SSS9  US:X  a   [
        R                  R                  U5      nU(       a%  U(       d  [        R                  " U5      nU(       d  gU(       a%  [        S[        UR                  5       5       35      e[        R                  " X5        g[         R                  " U U4UUS	.UD6$ ! [         a    Sn N˜f = f)
a
  Saves a model as a TensorFlow SavedModel or HDF5 file.

See the [Serialization and Saving guide](
    https://keras.io/guides/serialization_and_saving/) for details.

Args:
    model: TF-Keras model instance to be saved.
    filepath: `str` or `pathlib.Path` object. Path where to save the model.
    overwrite: Whether we should overwrite any existing model at the target
        location, or instead ask the user via an interactive prompt.
    save_format: Either `"keras"`, `"tf"`, `"h5"`,
        indicating whether to save the model
        in the native TF-Keras format (`.keras`),
        in the TensorFlow SavedModel format (referred to as "SavedModel"
        below), or in the legacy HDF5 format (`.h5`).
        Defaults to `"tf"` in TF 2.X, and `"h5"` in TF 1.X.

SavedModel format arguments:
    include_optimizer: Only applied to SavedModel and legacy HDF5 formats.
        If False, do not save the optimizer state. Defaults to True.
    signatures: Only applies to SavedModel format. Signatures to save
        with the SavedModel. See the `signatures` argument in
        `tf.saved_model.save` for details.
    options: Only applies to SavedModel format.
        `tf.saved_model.SaveOptions` object that specifies SavedModel
        saving options.
    save_traces: Only applies to SavedModel format. When enabled, the
        SavedModel will store the function traces for each layer. This
        can be disabled, so that only the configs of each layer are stored.
        Defaults to `True`. Disabling this will decrease serialization time
        and reduce file size, but it requires that all custom layers/models
        implement a `get_config()` method.

Example:

```python
model = tf.keras.Sequential([
    tf.keras.layers.Dense(5, input_shape=(3,)),
    tf.keras.layers.Softmax()])
model.save("model.keras")
loaded_model = tf.keras.saving.load_model("model.keras")
x = tf.random.uniform((10, 3))
assert np.allclose(model.predict(x), loaded_model.predict(x))
```

Note that `model.save()` is an alias for `tf.keras.saving.save_model()`.

The SavedModel or HDF5 file contains:

- The model's configuration (architecture)
- The model's weights
- The model's optimizer's state (if any)

Thus models can be reinstantiated in the exact same state, without any of
the code used for model definition or training.

Note that the model weights may have different scoped names after being
loaded. Scoped names include the model/layer names, such as
`"dense_1/kernel:0"`. It is recommended that you use the layer properties to
access specific variables, e.g. `model.get_layer("dense_1").kernel`.

__SavedModel serialization format__

With `save_format="tf"`, the model and all trackable objects attached
to the it (e.g. layers and variables) are saved as a TensorFlow SavedModel.
The model config, weights, and optimizer are included in the SavedModel.
Additionally, for every TF-Keras layer attached to the model, the SavedModel
stores:

* The config and metadata -- e.g. name, dtype, trainable status
* Traced call and loss functions, which are stored as TensorFlow
  subgraphs.

The traced functions allow the SavedModel format to save and load custom
layers without the original class definition.

You can choose to not save the traced functions by disabling the
`save_traces` option. This will decrease the time it takes to save the model
and the amount of disk space occupied by the output SavedModel. If you
enable this option, then you _must_ provide all custom class definitions
when loading the model. See the `custom_objects` argument in
`tf.keras.saving.load_model`.
Úh5zÀYou are saving your model as an HDF5 file via `model.save()`. This file format is considered legacy. We recommend using instead the native TF-Keras format, e.g. `model.save('my_model.keras')`.é   )Ú
stacklevelÚkerasFNúMThe following argument(s) are not supported with the native TF-Keras format: )Ú	overwriter   )Úget_save_formatr   r   ÚwarningsÚwarnr   r   ÚexistsÚ	TypeErrorr   Úask_to_proceed_with_overwriteÚ
ValueErrorÚlistÚkeysr   Ú
save_modelÚlegacy_sm_saving_lib)Úmodelr   r   r   Úkwargsr   r"   Úproceeds           r   r(   r(   1   s  € ôj " (Ó8€Kô -¨XÄFÓKÑ€Kð dÓÜŠð3ð ò	
ð gÓð	Ü—W‘W—^‘^ HÓ-ˆFö ž)Ü×<Ò<¸XÓFˆGÞØÞÜð4Ü48¸¿¹»Ó4GÐ3HðJóð ô 	×Ò˜eÕ.ô $×.Ò.ØØð
ð  Ø#ñ	
ð
 ñ
ð 	
øô ó 	ØŠFð	ús   Á C) Ã)C8Ã7C8zkeras.saving.load_modelzkeras.models.load_modelc                 ó’  • [        U SS9n[        X[        5      u  p`Ub(  [        R                  R
                  R                  X`SS9  [        U 5      R                  S5      =(       a    [        R                  " U 5      n[        R                  " U 5      (       aÌ  [        R                  R
                  R                  U 5      (       dž  U(       d—  [        R                  R!                  [        R"                  " 5       [        R                  R%                  U 5      5      n[        R                  R
                  R                  XSS9  [        R                  " U5      (       a  Un SnU(       aC  U(       a%  ['        S[)        UR+                  5       5       35      e[        R,                  " U UUUS9$ [.        R,                  " U 4XS.UD6$ )	a.  Loads a model saved via `model.save()`.

Args:
    filepath: `str` or `pathlib.Path` object, path to the saved model file.
    custom_objects: Optional dictionary mapping names
        (strings) to custom classes or functions to be
        considered during deserialization.
    compile: Boolean, whether to compile the model after loading.
    safe_mode: Boolean, whether to disallow unsafe `lambda` deserialization.
        When `safe_mode=False`, loading an object has the potential to
        trigger arbitrary code execution. This argument is only
        applicable to the TF-Keras v3 model format. Defaults to True.

SavedModel format arguments:
    options: Only applies to SavedModel format.
        Optional `tf.saved_model.LoadOptions` object that specifies
        SavedModel loading options.

Returns:
    A TF-Keras model instance. If the original model was compiled,
    and the argument `compile=True` is set, then the returned model
    will be compiled. Otherwise, the model will be left uncompiled.

Example:

```python
model = tf.keras.Sequential([
    tf.keras.layers.Dense(5, input_shape=(3,)),
    tf.keras.layers.Softmax()])
model.save("model.keras")
loaded_model = tf.keras.saving.load_model("model.keras")
x = tf.random.uniform((10, 3))
assert np.allclose(model.predict(x), loaded_model.predict(x))
```

Note that the model variables may have different name values
(`var.name` property, e.g. `"dense_1/kernel:0"`) after being reloaded.
It is recommended that you use layer attributes to
access specific variables, e.g. `model.get_layer("dense_1").kernel`.
N©r   T©r   ú.kerasr   )Úcustom_objectsÚcompileÚ	safe_mode)r1   r2   )r   r   r   r   ÚioÚgfileÚcopyr	   ÚendswithÚzipfileÚ
is_zipfiler   Úis_remote_pathÚisdirr   r   r   r   r   r%   r&   r'   Ú
load_modelr)   )	r   r1   r2   r3   r+   r   r   Úis_keras_zipÚ
local_paths	            r   r<   r<   °   sz  € ôZ " (¸Ñ=€KÜ,¨XÄFÓKÑ€KØÑÜ
‰‰×Ñ˜¸$ÐÑ?äx“=×)Ñ)¨(Ó3÷ ¼×8JÒ8JØó9€Lô 	×!Ò! (×+Ñ+Ü—‘—‘×!Ñ! (×+Ñ+Þä—W‘W—\‘\Ü×#Ò#Ó%¤r§w¡w×'7Ñ'7¸Ó'Aó
ˆ
ô
 	‰‰×Ñ˜¸ÐÑ>ô ×Ò˜j×)Ñ)Ø!ˆHØˆLæÞÜð4Ü48¸¿¹»Ó4GÐ3HðJóð ô ×$Ò$ØØ)ØØñ	
ð 	
ô  ×*Ò*ØðØ!/ñØDJñð r   c                 ó–  • [        US S9n[        X[        5      u  pQ[        U5      R	                  S5      (       ac   [
        R                  R                  U5      nU(       a%  U(       d  [        R                  " U5      nU(       d  g [        R                  " X5        g [        R                  " X4SU0UD6  g ! [         a    Sn Nkf = f)Nr.   ú.weights.h5Fr   )r   r   r   r	   r7   r   r   r"   r#   r   r$   r   Úsave_weights_onlyr)   Úsave_weights)r*   r   r   r+   r   r   r"   r,   s           r   rB   rB     s«   € ä! (¸Ñ=€KÜ,¨XÄFÓKÑ€Kä
ˆ8ƒ}×Ñ˜m×,Ñ,ð	Ü—W‘W—^‘^ HÓ-ˆFö ž)Ü×<Ò<¸XÓFˆGÞØÜ×$Ò$ UÕ5ä×)Ò)Øñ	
Ø'0ð	
Ø4:ó	
øô ó 	ØŠFð	ús   ½B9 Â9CÃCc                 óÌ  • [        US S9n[        X[        5      u  pQUb(  [        R                  R
                  R                  XQSS9  [        U5      R                  S5      (       a1  [        R                  " U5      (       a  [        R                  " XUS9  g [        U5      R                  S5      (       a  [        R                  " XUS9  g [        R                  " X4SU0UD6$ )Nr.   Tr/   r0   )Úskip_mismatchr@   rD   )r   r   r   r   r4   r5   r6   r	   r7   r8   r9   r   Úload_weights_onlyr)   Úload_weights)r*   r   rD   r+   r   r   s         r   rF   rF   !  sÈ   € ä! (¸Ñ=€KÜ,¨XÄFÓKÑ€KØÑÜ
‰‰×Ñ˜¸$ÐÑ?ä
ˆ8ƒ}×Ñ˜h×'Ñ'¬G×,>Ò,>¸x×,HÑ,HÜ×$Ò$Ø¨=ó	
ô 
ˆX‹×	Ñ	 ×	.Ñ	.Ü×$Ò$Ø¨=ó	
ô $×0Ò0Øñ
Ø+8ð
Ø<Bñ
ð 	
r   c                 óü  • U(       aE  US:X  a  gUS:X  a  [         R                  " 5       (       a  ggUS;   a  gUS;   a  g[        SU 35      e[        U 5      R	                  S5      (       a  [         R                  " 5       (       a  gg[        U 5      R	                  S	5      (       a  g[
        b   [        U [
        R                  5      (       a  g[        R                  R                  R                  5       (       a  gg)
NÚkeras_v3r   r   )r   Úhdf5)r   Ú
tensorflowr   z^Unknown `save_format` argument. Expected one of 'keras', 'tf', or 'h5'. Received: save_format=r0   )z.h5z.hdf5)r   Úsaving_v3_enabledr%   r	   r7   Úh5pyÚ
isinstanceÚFiler   Ú__internal__Útf2Úenabled)r   r   s     r   r   r   6  sß   € ÞØ˜*Ó$ØØ˜'Ó!Ü×+Ò+×-Ñ-ØàØ˜.Ó(ØØÐ.Ó.Øäð%à%0 Mð3ó
ð 	
ô ˆ8ƒ}×Ñ˜h×'Ñ'Ü×'Ò'×)Ñ)Øàä
ˆ8ƒ}×ÑÐ.×/Ñ/ØäÑœJ x´·±×;Ñ;Øô 
‡×Ñ×"Ñ"×$Ñ$Øàr   )TN)NTT)T)F)Ú__doc__r   r    r8   Útensorflow.compat.v2ÚcompatÚv2r   Ú tensorflow.python.util.tf_exportr   Útf_keras.src.savingr   Útf_keras.src.saving.legacyr   r)   Útf_keras.src.utilsr   rL   ÚImportErrorr   r   r(   r<   rB   rF   r   © r   r   Ú<module>r\      s¤   ðñ *ã 	Û Û ç !Ð !Ý 9å *Ý CÝ 'ðÛð 
€ò
!ñ Ð'Ð)BÓCó{
ó Dð{
ñ| Ð'Ð)BÓCà;?óWó DðWôt
ô,
ó*'øðq ó Ø‚Dðús   ±A+ Á+A6Á5A6