Restore a training checkpoint. Restores this `Checkpoint` and any objects it depends on. Either assigns values immediately if variables to restore have been created already, or defers restoration until the variables are created. Dependencies added after this call will be matched if
(self, save_path)
| 1895 | return file_path |
| 1896 | |
| 1897 | def restore(self, save_path): |
| 1898 | """Restore a training checkpoint. |
| 1899 | |
| 1900 | Restores this `Checkpoint` and any objects it depends on. |
| 1901 | |
| 1902 | Either assigns values immediately if variables to restore have been created |
| 1903 | already, or defers restoration until the variables are created. Dependencies |
| 1904 | added after this call will be matched if they have a corresponding object in |
| 1905 | the checkpoint (the restore request will queue in any trackable object |
| 1906 | waiting for the expected dependency to be added). |
| 1907 | |
| 1908 | To ensure that loading is complete and no more assignments will take place, |
| 1909 | use the `assert_consumed()` method of the status object returned by |
| 1910 | `restore`: |
| 1911 | |
| 1912 | ```python |
| 1913 | checkpoint = tf.train.Checkpoint( ... ) |
| 1914 | checkpoint.restore(path).assert_consumed() |
| 1915 | ``` |
| 1916 | |
| 1917 | An exception will be raised if any Python objects in the dependency graph |
| 1918 | were not found in the checkpoint, or if any checkpointed values do not have |
| 1919 | a matching Python object. |
| 1920 | |
| 1921 | Name-based `tf.compat.v1.train.Saver` checkpoints from TensorFlow 1.x can be |
| 1922 | loaded |
| 1923 | using this method. Names are used to match variables. Re-encode name-based |
| 1924 | checkpoints using `tf.train.Checkpoint.save` as soon as possible. |
| 1925 | |
| 1926 | Args: |
| 1927 | save_path: The path to the checkpoint, as returned by `save` or |
| 1928 | `tf.train.latest_checkpoint`. If None (as when there is no latest |
| 1929 | checkpoint for `tf.train.latest_checkpoint` to return), returns an |
| 1930 | object which may run initializers for objects in the dependency graph. |
| 1931 | If the checkpoint was written by the name-based |
| 1932 | `tf.compat.v1.train.Saver`, names are used to match variables. |
| 1933 | |
| 1934 | Returns: |
| 1935 | A load status object, which can be used to make assertions about the |
| 1936 | status of a checkpoint restoration. |
| 1937 | |
| 1938 | The returned status object has the following methods: |
| 1939 | |
| 1940 | * `assert_consumed()`: |
| 1941 | Raises an exception if any variables/objects are unmatched: either |
| 1942 | checkpointed values which don't have a matching Python object or |
| 1943 | Python objects in the dependency graph with no values in the |
| 1944 | checkpoint. This method returns the status object, and so may be |
| 1945 | chained with other assertions. |
| 1946 | |
| 1947 | * `assert_existing_objects_matched()`: |
| 1948 | Raises an exception if any existing Python objects in the dependency |
| 1949 | graph are unmatched. Unlike `assert_consumed`, this assertion will |
| 1950 | pass if values in the checkpoint have no corresponding Python |
| 1951 | objects. For example a `tf.keras.Layer` object which has not yet been |
| 1952 | built, and so has not created any variables, will pass this assertion |
| 1953 | but fail `assert_consumed`. Useful when loading part of a larger |
| 1954 | checkpoint into a new Python program, e.g. a training checkpoint with |