A string that identifies how to handle input
pipelines that depend on external state. Possible values are
'ignore': The external state is silently ignored.
'warn': The external state is ignored, logging a warning.
'fail': The operation fails upon encountering external state.
By default we set it to 'fail'.
Returns
A SaveableObject for saving/restoring iterator state using Saver.
Raises
ValueError
If iterator does not support checkpointing.
ValueError
If external_state_policy is not one of 'warn', 'ignore' or
'fail'.
For example:
withtf.Graph().as_default():ds=tf.data.Dataset.range(10)iterator=ds.make_initializable_iterator()# Build the iterator SaveableObject.saveable_obj=tf.data.experimental.make_saveable_from_iterator(iterator)# Add the SaveableObject to the SAVEABLE_OBJECTS collection so# it can be automatically saved using Saver.tf.compat.v1.add_to_collection(tf.GraphKeys.SAVEABLE_OBJECTS,saveable_obj)saver=tf.compat.v1.train.Saver()whilecontinue_training:...Performtraining...ifshould_save_checkpoint:saver.save()
[null,null,["Last updated 2024-04-26 UTC."],[],[],null,["# tf.data.experimental.make_saveable_from_iterator\n\n\u003cbr /\u003e\n\n|------------------------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.16.1/tensorflow/python/data/experimental/ops/iterator_ops.py#L38-L97) |\n\nReturns a SaveableObject for saving/restoring iterator state using Saver. (deprecated)\n\n#### View aliases\n\n\n**Compat aliases for migration**\n\nSee\n[Migration guide](https://www.tensorflow.org/guide/migrate) for\nmore details.\n\n[`tf.compat.v1.data.experimental.make_saveable_from_iterator`](https://www.tensorflow.org/api_docs/python/tf/data/experimental/make_saveable_from_iterator)\n\n\u003cbr /\u003e\n\n tf.data.experimental.make_saveable_from_iterator(\n iterator, external_state_policy=None\n )\n\n| **Deprecated:** THIS FUNCTION IS DEPRECATED. It will be removed in a future version. Instructions for updating: `make_saveable_from_iterator` is intended for use in TF1 with `tf.compat.v1.Saver`. In TF2, use [`tf.train.Checkpoint`](../../../tf/train/Checkpoint) instead.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|-------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `iterator` | Iterator. |\n| `external_state_policy` | A string that identifies how to handle input pipelines that depend on external state. Possible values are 'ignore': The external state is silently ignored. 'warn': The external state is ignored, logging a warning. 'fail': The operation fails upon encountering external state. By default we set it to 'fail'. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|---|---|\n| A SaveableObject for saving/restoring iterator state using Saver. ||\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Raises ------ ||\n|--------------|----------------------------------------------------------------------|\n| `ValueError` | If iterator does not support checkpointing. |\n| `ValueError` | If `external_state_policy` is not one of 'warn', 'ignore' or 'fail'. |\n\n\u003cbr /\u003e\n\n#### For example:\n\n with tf.Graph().as_default():\n ds = tf.data.Dataset.range(10)\n iterator = ds.make_initializable_iterator()\n # Build the iterator SaveableObject.\n saveable_obj = tf.data.experimental.make_saveable_from_iterator(iterator)\n # Add the SaveableObject to the SAVEABLE_OBJECTS collection so\n # it can be automatically saved using Saver.\n tf.compat.v1.add_to_collection(tf.GraphKeys.SAVEABLE_OBJECTS, saveable_obj)\n saver = tf.compat.v1.train.Saver()\n\n while continue_training:\n ... Perform training ...\n if should_save_checkpoint:\n saver.save()\n\n| **Note:** When restoring the iterator, the existing iterator state is completely discarded. This means that any changes you may have made to the Dataset graph will be discarded as well! This includes the new Dataset graph that you may have built during validation. So, while running validation, make sure to run the initializer for the validation input pipeline after restoring the checkpoint.\n| **Note:** Not all iterators support checkpointing yet. Attempting to save the state of an unsupported iterator will throw an error."]]