@@ -55,6 +55,7 @@ public Saver(RefVariable[] var_list = null,
5555 _keep_checkpoint_every_n_hours = keep_checkpoint_every_n_hours ;
5656 _name = name ;
5757 _restore_sequentially = restore_sequentially ;
58+ _saver_def = saver_def ;
5859 _builder = builder ;
5960 _is_built = false ;
6061 _allow_empty = allow_empty ;
@@ -122,7 +123,7 @@ private void _build(string checkpoint_path, bool build_save, bool build_restore)
122123 }
123124 else if ( _saver_def != null && ! string . IsNullOrEmpty ( _name ) )
124125 {
125- throw new NotImplementedException ( "" ) ;
126+ throw new NotImplementedException ( "Saver._build " ) ;
126127 }
127128
128129 _check_saver_def ( ) ;
@@ -200,6 +201,38 @@ public string save(Session sess,
200201 return saver . _import_meta_graph_with_return_elements ( meta_graph_or_file , clear_devices , import_scope ) ;
201202 }
202203
204+ /// <summary>
205+ /// Restores previously saved variables.
206+ ///
207+ /// This method runs the ops added by the constructor for restoring variables.
208+ /// It requires a session in which the graph was launched. The variables to
209+ /// restore do not have to have been initialized, as restoring is itself a way
210+ /// to initialize variables.
211+ /// </summary>
212+ /// <param name="sess">A `Session` to use to restore the parameters. None in eager mode.</param>
213+ /// <param name="save_path">Path where parameters were previously saved.</param>
214+ public void restore ( Session sess , string save_path )
215+ {
216+ if ( _is_empty )
217+ return ;
218+
219+ if ( string . IsNullOrEmpty ( save_path ) )
220+ throw new ValueError ( "Can't load save_path when it is None." ) ;
221+
222+ if ( ! checkpoint_management . checkpoint_exists ( save_path ) )
223+ throw new ValueError ( $ "The passed save_path is not a valid checkpoint: { save_path } ") ;
224+
225+ Console . WriteLine ( $ "Restoring parameters from { save_path } ") ;
226+
227+ if ( tf . context . executing_eagerly ( ) )
228+ ;
229+ else
230+ sess . run ( _saver_def . RestoreOpName , new FeedItem [ ]
231+ {
232+ new FeedItem ( _saver_def . FilenameTensorName , save_path )
233+ } ) ;
234+ }
235+
203236 /// <summary>
204237 /// Writes `MetaGraphDef` to save_path/filename.
205238 /// </summary>
0 commit comments