@@ -23,18 +23,68 @@ public partial class RefVariable : VariableV1
2323
2424 public string name => _variable . name ;
2525
26- public RefVariable ( object initial_value ,
26+ public RefVariable ( object initial_value = null ,
2727 bool trainable = true ,
2828 List < string > collections = null ,
2929 bool validate_shape = true ,
3030 string caching_device = "" ,
3131 string name = "" ,
32- TF_DataType dtype = TF_DataType . DtInvalid ) :
33- base ( initial_value , trainable , collections , validate_shape , caching_device , name , dtype )
32+ VariableDef variable_def = null ,
33+ TF_DataType dtype = TF_DataType . DtInvalid ,
34+ string import_scope = "" ) : base ( initial_value ,
35+ trainable ,
36+ collections ,
37+ validate_shape ,
38+ caching_device ,
39+ name ,
40+ dtype )
3441 {
3542 _in_graph_mode = true ;
3643
37- _init_from_args ( initial_value , trainable , collections , validate_shape , caching_device , name , dtype ) ;
44+ if ( variable_def != null )
45+ {
46+ if ( initial_value != null )
47+ throw new ValueError ( "variable_def and initial_value are mutually exclusive." ) ;
48+ _init_from_proto ( variable_def , import_scope : import_scope ) ;
49+ }
50+ else
51+ {
52+ _init_from_args ( initial_value , trainable , collections , validate_shape , caching_device , name , dtype ) ;
53+ }
54+ }
55+
56+ private void _init_from_proto ( VariableDef variable_def , string import_scope = "" )
57+ {
58+ var g = ops . get_default_graph ( ) ;
59+
60+ _variable = g . as_graph_element (
61+ ops . prepend_name_scope ( variable_def . VariableName ,
62+ import_scope : import_scope ) ) as Tensor ;
63+
64+ _initializer_op = g . as_graph_element (
65+ ops . prepend_name_scope ( variable_def . InitializerName ,
66+ import_scope : import_scope ) ) as Operation ;
67+
68+ // Tests whether initial_value_name exists first for backwards compatibility.
69+ if ( ! string . IsNullOrEmpty ( variable_def . InitialValueName ) )
70+ _initial_value = g . as_graph_element (
71+ ops . prepend_name_scope ( variable_def . InitialValueName ,
72+ import_scope : import_scope ) ) as Tensor ;
73+ else
74+ _initial_value = null ;
75+
76+ _trainable = variable_def . Trainable ;
77+ _snapshot = g . as_graph_element (
78+ ops . prepend_name_scope ( variable_def . SnapshotName ,
79+ import_scope : import_scope ) ) as Tensor ;
80+
81+ if ( variable_def . SaveSliceInfoDef != null )
82+ throw new NotImplementedException ( "save_slice_info_def" ) ;
83+ else
84+ ; // _save_slice_info = null;
85+
86+ //_caching_device = null;
87+ //_constraint = null;
3888 }
3989
4090 private void _init_from_args ( object initial_value ,
0 commit comments