@@ -6,22 +6,48 @@ namespace Tensorflow
66{
77 public class saver
88 {
9- public static Saver _import_meta_graph_with_return_elements ( string meta_graph_or_file ,
9+ public static ( Saver , object ) _import_meta_graph_with_return_elements ( string meta_graph_or_file ,
1010 bool clear_devices = false ,
1111 string import_scope = "" ,
1212 string [ ] return_elements = null )
1313 {
1414 var meta_graph_def = meta_graph . read_meta_graph_file ( meta_graph_or_file ) ;
1515
16- meta_graph . import_scoped_meta_graph_with_return_elements (
16+ var imported_vars = meta_graph . import_scoped_meta_graph_with_return_elements (
1717 meta_graph_def ,
1818 clear_devices : clear_devices ,
1919 import_scope : import_scope ,
2020 return_elements : return_elements ) ;
2121
22- return null ;
23- /*var (imported_vars, imported_return_elements) = (
24- , false);*/
22+ var saver = _create_saver_from_imported_meta_graph (
23+ meta_graph_def , import_scope , imported_vars ) ;
24+
25+ return ( saver , null ) ;
26+ }
27+
28+ public static Saver _create_saver_from_imported_meta_graph ( MetaGraphDef meta_graph_def ,
29+ string import_scope ,
30+ ( Dictionary < string , RefVariable > , ITensorOrOperation [ ] ) imported_vars )
31+ {
32+ if ( meta_graph_def . SaverDef != null )
33+ {
34+ throw new NotImplementedException ( "_create_saver_from_imported_meta_graph" ) ;
35+ }
36+ else
37+ {
38+ if ( variables . _all_saveable_objects ( scope : import_scope ) . Length > 0 )
39+ {
40+ // Return the default saver instance for all graph variables.
41+ return new Saver ( ) ;
42+ }
43+ else
44+ {
45+ // If no graph variables exist, then a Saver cannot be constructed.
46+ Console . WriteLine ( "Saver not created because there are no variables in the" +
47+ " graph to restore" ) ;
48+ return null ;
49+ }
50+ }
2551 }
2652 }
2753}
0 commit comments