33using System . IO ;
44using System . Linq ;
55using System . Text ;
6+ using static Tensorflow . CollectionDef ;
67using static Tensorflow . MetaGraphDef . Types ;
78
89namespace Tensorflow
@@ -16,7 +17,7 @@ public static MetaGraphDef read_meta_graph_file(string filename)
1617 return meta_graph_def ;
1718 }
1819
19- public static void import_scoped_meta_graph_with_return_elements ( MetaGraphDef meta_graph_or_file ,
20+ public static ( RefVariable [ ] , string [ ] ) import_scoped_meta_graph_with_return_elements ( MetaGraphDef meta_graph_or_file ,
2021 bool clear_devices = false ,
2122 string import_scope = "" ,
2223 Dictionary < string , Tensor > input_map = null ,
@@ -51,15 +52,49 @@ public static void import_scoped_meta_graph_with_return_elements(MetaGraphDef me
5152 node . Device = "" ;
5253
5354 var scope_to_prepend_to_names = graph . unique_name ( "" , mark_as_used : false ) ;
54- importer . import_graph_def ( input_graph_def ,
55+ var imported_return_elements = importer . import_graph_def ( input_graph_def ,
5556 name : scope_to_prepend_to_names ,
5657 input_map : input_map ,
5758 producer_op_list : producer_op_list ,
5859 return_elements : return_elements ) ;
5960
6061 // Restores all the other collections.
6162 var variable_objects = new Dictionary < string , RefVariable > ( ) ;
63+ foreach ( var col in meta_graph_def . CollectionDef . OrderBy ( x => x . Key ) )
64+ {
65+ // Don't add unbound_inputs to the new graph.
66+ if ( col . Key == unbound_inputs_col_name )
67+ continue ;
68+
69+ switch ( col . Value . KindCase )
70+ {
71+ case KindOneofCase . NodeList :
72+ foreach ( var value in col . Value . NodeList . Value )
73+ {
74+ var col_op = graph . as_graph_element ( ops . prepend_name_scope ( value , scope_to_prepend_to_names ) ) ;
75+ graph . add_to_collection ( col . Key , col_op ) ;
76+ }
77+ break ;
78+ case KindOneofCase . BytesList :
79+ //var proto_type = ops.get_collection_proto_type(key)
80+ if ( ops . GraphKeys . _VARIABLE_COLLECTIONS . Contains ( col . Key ) )
81+ {
82+ foreach ( var value in col . Value . BytesList . Value )
83+ {
84+ var proto = VariableDef . Parser . ParseFrom ( value ) ;
85+ throw new NotImplementedException ( "import_scoped_meta_graph_with_return_elements" ) ;
86+ }
87+ }
88+ else
89+ {
90+ throw new NotImplementedException ( "import_scoped_meta_graph_with_return_elements" ) ;
91+ }
92+
93+ break ;
94+ }
95+ }
6296
97+ return ( null , null ) ;
6398 }
6499
65100 /// <summary>
0 commit comments