<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/models/blob/v2.20.0/official/core/savedmodel_checkpoint_manager.py#L32-L258) |

A CheckpointManager that also exports `SavedModel`s.

    tfm.core.savedmodel_checkpoint_manager.SavedModelCheckpointManager(
        checkpoint: tf.train.Checkpoint,
        directory: str,
        max_to_keep: int,
        modules_to_export: Optional[Mapping[str, tf.Module]] = None,
        keep_checkpoint_every_n_hours: Optional[int] = None,
        checkpoint_name: str = 'ckpt',
        step_counter: Optional[tf.Variable] = None,
        checkpoint_interval: Optional[int] = None,
        init_fn: Optional[Callable[[], None]] = None
    )

<br />

<br />

<br />

| ## Attributes ||
|---|---|
| `checkpoint` | Returns the [`tf.train.Checkpoint`](https://www.tensorflow.org/api_docs/python/tf/train/Checkpoint) object. |
| `checkpoint_interval` | <br /> <br /> |
| `checkpoints` | A list of managed checkpoints. <br /> Note that checkpoints saved due to `keep_checkpoint_every_n_hours` will not show up in this list (to avoid ever-growing filename lists). |
| `directory` | <br /> <br /> |
| `latest_checkpoint` | The prefix of the most recent checkpoint in `directory`. <br /> Equivalent to [`tf.train.latest_checkpoint(directory)`](https://www.tensorflow.org/api_docs/python/tf/train/latest_checkpoint) where `directory` is the constructor argument to `CheckpointManager`. Suitable for passing to [`tf.train.Checkpoint.restore`](https://www.tensorflow.org/api_docs/python/tf/train/Checkpoint#restore) to resume training. |
| `latest_savedmodel` | The path of the most recent SavedModel in `directory`. |
| `modules_to_export` | <br /> <br /> |
| `savedmodels` | A list of managed SavedModels. |

<br />

## Methods

### `get_existing_savedmodels`

[View source](https://github.com/tensorflow/models/blob/v2.20.0/official/core/savedmodel_checkpoint_manager.py#L106-L121)

    get_existing_savedmodels() -> List[str]

Gets a list of all existing SavedModel paths in `directory`.

<br />

<br />

<br />

| Returns ||
|---|---|
| A list of all existing SavedModel paths. ||

<br />

### `get_savedmodel_number_from_path`

[View source](https://github.com/tensorflow/models/blob/v2.20.0/official/core/savedmodel_checkpoint_manager.py#L147-L164)

    get_savedmodel_number_from_path(
        savedmodel_path: str
    ) -> Union[int, None]

Gets the savedmodel_number/checkpoint_number from savedmodel filepath.

The savedmodel_number is global step when using with orbit controller.

<br />

<br />

<br />

| Args ||
|---|---|
| `savedmodel_path` | savedmodel directory path. |

<br />

<br />

<br />

<br />

| Returns ||
|---|---|
| Savedmodel number or None if no matched pattern found in savedmodel path. ||

<br />

### `restore_or_initialize`

    restore_or_initialize()

Restore items in `checkpoint` from the latest checkpoint file.

This method will first try to restore from the most recent checkpoint in
`directory`. If no checkpoints exist in `directory`, and `init_fn` is
specified, this method will call `init_fn` to do customized
initialization. This can be used to support initialization from pretrained
models.

Note that unlike [`tf.train.Checkpoint.restore()`](https://www.tensorflow.org/api_docs/python/tf/train/Checkpoint#restore), this method doesn't return
a load status object that users can run assertions on
(e.g. assert_consumed()). Thus to run assertions, users should directly use
[`tf.train.Checkpoint.restore()`](https://www.tensorflow.org/api_docs/python/tf/train/Checkpoint#restore) method.

<br />

<br />

<br />

| Returns ||
|---|---|
| The restored checkpoint path if the latest checkpoint is found and restored. Otherwise None. ||

<br />

### `save`

[View source](https://github.com/tensorflow/models/blob/v2.20.0/official/core/savedmodel_checkpoint_manager.py#L58-L104)

    save(
        checkpoint_number: Optional[int] = None,
        check_interval: bool = True,
        options: Optional[tf.train.CheckpointOptions] = None
    )

See base class.

### `savedmodels_iterator`

[View source](https://github.com/tensorflow/models/blob/v2.20.0/official/core/savedmodel_checkpoint_manager.py#L166-L207)

    savedmodels_iterator(
        min_interval_secs: float = 0,
        timeout: Optional[float] = None,
        timeout_fn: Optional[Callable[[], bool]] = None
    )

Continuously yield new SavedModel files as they appear.

The iterator only checks for new savedmodels when control flow has been
reverted to it. The logic is same to the [`train.checkpoints_iterator`](https://www.tensorflow.org/api_docs/python/tf/train/checkpoints_iterator).

<br />

<br />

<br />

| Args ||
|---|---|
| `min_interval_secs` | The minimum number of seconds between yielding savedmodels. |
| `timeout` | The maximum number of seconds to wait between savedmodels. If left as `None`, then the process will wait indefinitely. |
| `timeout_fn` | Optional function to call after a timeout. If the function returns True, then it means that no new savedmodels will be generated and the iterator will exit. The function is called with no arguments. |

<br />

<br />

<br />

<br />

| Yields ||
|---|---|
| String paths to latest SavedModel files as they arrive. ||

<br />

### `sync`

    sync()

Wait for any outstanding save or restore operations.

### `wait_for_new_savedmodel`

[View source](https://github.com/tensorflow/models/blob/v2.20.0/official/core/savedmodel_checkpoint_manager.py#L209-L258)

    wait_for_new_savedmodel(
        last_savedmodel: Optional[str] = None,
        seconds_to_sleep: float = 1.0,
        timeout: Optional[float] = None
    ) -> Union[str, None]

Waits until a new savedmodel file is found.

<br />

<br />

<br />

| Args ||
|---|---|
| `last_savedmodel` | The last savedmodel path used or `None` if we're expecting a savedmodel for the first time. |
| `seconds_to_sleep` | The number of seconds to sleep for before looking for a new savedmodel. |
| `timeout` | The maximum number of seconds to wait. If left as `None`, then the process will wait indefinitely. |

<br />

<br />

<br />

<br />

| Returns ||
|---|---|
| A new savedmodel path, or None if the timeout was reached. ||

<br />