Creates a `Saver`. The constructor adds ops to save and restore variables. `var_list` specifies the variables that will be saved and restored. It can be passed as a `dict` or a list: * A `dict` of names to variables: The keys are the names that will be used to save or restor
(self,
var_list=None,
reshape=False,
sharded=False,
max_to_keep=5,
keep_checkpoint_every_n_hours=10000.0,
name=None,
restore_sequentially=False,
saver_def=None,
builder=None,
defer_build=False,
allow_empty=False,
write_version=saver_pb2.SaverDef.V2,
pad_step_number=False,
save_relative_paths=False,
filename=None,
incremental_save_restore=False,
incremental_include_normal_var=False)
| 887 | """ |
| 888 | |
| 889 | def __init__(self, |
| 890 | var_list=None, |
| 891 | reshape=False, |
| 892 | sharded=False, |
| 893 | max_to_keep=5, |
| 894 | keep_checkpoint_every_n_hours=10000.0, |
| 895 | name=None, |
| 896 | restore_sequentially=False, |
| 897 | saver_def=None, |
| 898 | builder=None, |
| 899 | defer_build=False, |
| 900 | allow_empty=False, |
| 901 | write_version=saver_pb2.SaverDef.V2, |
| 902 | pad_step_number=False, |
| 903 | save_relative_paths=False, |
| 904 | filename=None, |
| 905 | incremental_save_restore=False, |
| 906 | incremental_include_normal_var=False): |
| 907 | """Creates a `Saver`. |
| 908 | |
| 909 | The constructor adds ops to save and restore variables. |
| 910 | |
| 911 | `var_list` specifies the variables that will be saved and restored. It can |
| 912 | be passed as a `dict` or a list: |
| 913 | |
| 914 | * A `dict` of names to variables: The keys are the names that will be |
| 915 | used to save or restore the variables in the checkpoint files. |
| 916 | * A list of variables: The variables will be keyed with their op name in |
| 917 | the checkpoint files. |
| 918 | |
| 919 | For example: |
| 920 | |
| 921 | ```python |
| 922 | v1 = tf.Variable(..., name='v1') |
| 923 | v2 = tf.Variable(..., name='v2') |
| 924 | |
| 925 | # Pass the variables as a dict: |
| 926 | saver = tf.compat.v1.train.Saver({'v1': v1, 'v2': v2}) |
| 927 | |
| 928 | # Or pass them as a list. |
| 929 | saver = tf.compat.v1.train.Saver([v1, v2]) |
| 930 | # Passing a list is equivalent to passing a dict with the variable op names |
| 931 | # as keys: |
| 932 | saver = tf.compat.v1.train.Saver({v.op.name: v for v in [v1, v2]}) |
| 933 | ``` |
| 934 | |
| 935 | Note: the newer `AutoTrackable` API is not supported by `Saver`. In this |
| 936 | case, the `tf.train.Checkpoint` class should be used. |
| 937 | |
| 938 | The optional `reshape` argument, if `True`, allows restoring a variable from |
| 939 | a save file where the variable had a different shape, but the same number |
| 940 | of elements and type. This is useful if you have reshaped a variable and |
| 941 | want to reload it from an older checkpoint. |
| 942 | |
| 943 | The optional `sharded` argument, if `True`, instructs the saver to shard |
| 944 | checkpoints per device. |
| 945 | |
| 946 | Args: |
no test coverage detected