| @@ -23,6 +23,8 @@ namespace Tensorflow | |||||
| TF_DataType dtype = TF_DataType.DtInvalid, | TF_DataType dtype = TF_DataType.DtInvalid, | ||||
| object initializer = null, // IInitializer or Tensor | object initializer = null, // IInitializer or Tensor | ||||
| bool? trainable = null, | bool? trainable = null, | ||||
| bool? use_resource = null, | |||||
| bool validate_shape = true, | |||||
| VariableSynchronization synchronization = VariableSynchronization.Auto, | VariableSynchronization synchronization = VariableSynchronization.Auto, | ||||
| VariableAggregation aggregation = VariableAggregation.None) | VariableAggregation aggregation = VariableAggregation.None) | ||||
| { | { | ||||
| @@ -32,6 +34,8 @@ namespace Tensorflow | |||||
| name, | name, | ||||
| shape: shape, | shape: shape, | ||||
| dtype: dtype, | dtype: dtype, | ||||
| use_resource: use_resource, | |||||
| validate_shape: validate_shape, | |||||
| initializer: initializer, | initializer: initializer, | ||||
| trainable: trainable); | trainable: trainable); | ||||
| } | } | ||||
| @@ -73,7 +73,8 @@ namespace Tensorflow.Train | |||||
| // Create slots for the first and second moments. | // Create slots for the first and second moments. | ||||
| foreach(var v in var_list) | foreach(var v in var_list) | ||||
| { | { | ||||
| _zero_slot(v, "m", Name); | |||||
| _zeros_slot(v, "m", Name); | |||||
| _zeros_slot(v, "v", Name); | |||||
| } | } | ||||
| } | } | ||||
| @@ -21,7 +21,8 @@ namespace Tensorflow | |||||
| public static int GATE_OP = 1; | public static int GATE_OP = 1; | ||||
| public static int GATE_GRAPH = 2; | public static int GATE_GRAPH = 2; | ||||
| public string Name { get; set; } | |||||
| string _name; | |||||
| public string Name => _name; | |||||
| public float LearningRate { get; set; } | public float LearningRate { get; set; } | ||||
| public Tensor LearningRateTensor { get; set; } | public Tensor LearningRateTensor { get; set; } | ||||
| public bool _use_locking; | public bool _use_locking; | ||||
| @@ -35,7 +36,7 @@ namespace Tensorflow | |||||
| if (String.IsNullOrEmpty(name)) | if (String.IsNullOrEmpty(name)) | ||||
| throw new NotImplementedException("Must specify the optimizer name"); | throw new NotImplementedException("Must specify the optimizer name"); | ||||
| Name = name; | |||||
| _name = name; | |||||
| _use_locking = use_locking; | _use_locking = use_locking; | ||||
| LearningRate = learning_rate; | LearningRate = learning_rate; | ||||
| // Dictionary of slots. | // Dictionary of slots. | ||||
| @@ -391,22 +392,34 @@ namespace Tensorflow | |||||
| /// <param name="slot_name"></param> | /// <param name="slot_name"></param> | ||||
| /// <param name="op_name"></param> | /// <param name="op_name"></param> | ||||
| /// <returns></returns> | /// <returns></returns> | ||||
| protected RefVariable _zero_slot(RefVariable var, string slot_name, string op_name) | |||||
| protected RefVariable _zeros_slot(RefVariable var, string slot_name, string op_name) | |||||
| { | { | ||||
| var named_slots = _slot_dict(slot_name); | var named_slots = _slot_dict(slot_name); | ||||
| if (!named_slots.ContainsKey(_var_key(var))) | if (!named_slots.ContainsKey(_var_key(var))) | ||||
| { | { | ||||
| var new_slot_variable = slot_creator.create_zeros_slot(var, op_name); | var new_slot_variable = slot_creator.create_zeros_slot(var, op_name); | ||||
| _restore_slot_variable(slot_name: slot_name, variable: var, slot_variable: new_slot_variable); | |||||
| named_slots[_var_key(var)] = new_slot_variable; | |||||
| } | } | ||||
| return named_slots[_var_key(var)]; | return named_slots[_var_key(var)]; | ||||
| } | } | ||||
| /// <summary> | |||||
| /// Restore a newly created slot variable's value. | |||||
| /// </summary> | |||||
| protected void _restore_slot_variable(string slot_name, RefVariable variable, RefVariable slot_variable) | |||||
| { | |||||
| var variable_key = _var_key(variable); | |||||
| // TODO | |||||
| } | |||||
| protected Dictionary<string, RefVariable> _slot_dict(string slot_name) | protected Dictionary<string, RefVariable> _slot_dict(string slot_name) | ||||
| { | { | ||||
| var named_slots = _slots.ContainsKey(slot_name) ? _slots[slot_name] : null; | var named_slots = _slots.ContainsKey(slot_name) ? _slots[slot_name] : null; | ||||
| if(named_slots == null) | if(named_slots == null) | ||||
| { | { | ||||
| _slots[slot_name] = new Dictionary<string, RefVariable>(); | |||||
| named_slots = new Dictionary<string, RefVariable>(); | |||||
| _slots[slot_name] = named_slots; | |||||
| } | } | ||||
| return named_slots; | return named_slots; | ||||
| @@ -43,7 +43,7 @@ namespace Tensorflow.Train | |||||
| { | { | ||||
| var validate_shape = shape.is_fully_defined(); | var validate_shape = shape.is_fully_defined(); | ||||
| var prefix = primary.op.name; | var prefix = primary.op.name; | ||||
| return with(new variable_scope(prefix + "/" + name), delegate | |||||
| return with(new variable_scope(string.Empty, prefix + "/" + name), delegate | |||||
| { | { | ||||
| return _create_slot_var(primary, initializer, "", validate_shape, shape, dtype); | return _create_slot_var(primary, initializer, "", validate_shape, shape, dtype); | ||||
| }); | }); | ||||
| @@ -62,11 +62,11 @@ namespace Tensorflow.Train | |||||
| private RefVariable _create_slot_var(VariableV1 primary, IInitializer val, string scope, bool validate_shape, | private RefVariable _create_slot_var(VariableV1 primary, IInitializer val, string scope, bool validate_shape, | ||||
| TensorShape shape, TF_DataType dtype) | TensorShape shape, TF_DataType dtype) | ||||
| { | { | ||||
| bool use_resource = primary is RefVariable; | |||||
| bool use_resource = primary is ResourceVariable; | |||||
| if (resource_variable_ops.is_resource_variable(primary)) | if (resource_variable_ops.is_resource_variable(primary)) | ||||
| use_resource = true; | use_resource = true; | ||||
| var slot = variable_scope.get_variable( | |||||
| var slot = tf.get_variable( | |||||
| scope, | scope, | ||||
| initializer: val, | initializer: val, | ||||
| trainable: false, | trainable: false, | ||||
| @@ -37,6 +37,8 @@ namespace Tensorflow | |||||
| TF_DataType dtype = TF_DataType.DtInvalid, | TF_DataType dtype = TF_DataType.DtInvalid, | ||||
| object initializer = null, // IInitializer or Tensor | object initializer = null, // IInitializer or Tensor | ||||
| bool? trainable = null, | bool? trainable = null, | ||||
| bool? use_resource = null, | |||||
| bool validate_shape = true, | |||||
| VariableSynchronization synchronization = VariableSynchronization.Auto, | VariableSynchronization synchronization = VariableSynchronization.Auto, | ||||
| VariableAggregation aggregation= VariableAggregation.None) | VariableAggregation aggregation= VariableAggregation.None) | ||||
| { | { | ||||
| @@ -104,7 +104,7 @@ namespace Tensorflow | |||||
| current_name_scope = ops.name_scope(name_scope); | current_name_scope = ops.name_scope(name_scope); | ||||
| } | } | ||||
| if (_name != null || _scope != null) | |||||
| if (!string.IsNullOrEmpty(_name) || _scope != null) | |||||
| { | { | ||||
| var name_scope = _scope.name.Split('/').Last(); | var name_scope = _scope.name.Split('/').Last(); | ||||
| if (current_name_scope == null) | if (current_name_scope == null) | ||||
| @@ -3,12 +3,12 @@ TensorFlow.NET pack all required libraries in architecture-specific assemblies f | |||||
| Here are some pre-built TensorFlow binaries you can use for each platform: | Here are some pre-built TensorFlow binaries you can use for each platform: | ||||
| - Linux | - Linux | ||||
| - CPU-only: https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-cpu-linux-x86_64-1.13.1.tar.gz | |||||
| - GPU-enabled: https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-gpu-linux-x86_64-1.13.1.tar.gz | |||||
| - Mac: https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-cpu-darwin-x86_64-1.13.1.tar.gz | |||||
| - CPU-only: https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-cpu-linux-x86_64-1.14.0.tar.gz | |||||
| - GPU-enabled: https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-gpu-linux-x86_64-1.14.0.tar.gz | |||||
| - Mac: https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-cpu-darwin-x86_64-1.14.0.tar.gz | |||||
| - Windows | - Windows | ||||
| - CPU-only: https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-cpu-windows-x86_64-1.13.1.zip | |||||
| - GPU-enabled: https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-gpu-windows-x86_64-1.13.1.zip | |||||
| - CPU-only: https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-cpu-windows-x86_64-1.14.0.zip | |||||
| - GPU-enabled: https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-gpu-windows-x86_64-1.14.0.zip | |||||
| ### Run in Linux | ### Run in Linux | ||||
| @@ -41,7 +41,7 @@ pacman -S git patch unzip | |||||
| 4. Install from local wheel file. | 4. Install from local wheel file. | ||||
| `pip install C:/tmp/tensorflow_pkg/tensorflow-1.13.0-cp36-cp36m-win_amd64.whl` | |||||
| `pip install C:/tmp/tensorflow_pkg/tensorflow-1.14.0-cp36-cp36m-win_amd64.whl` | |||||
| ### Export more APIs | ### Export more APIs | ||||
| @@ -17,7 +17,7 @@ | |||||
| <PackageReference Include="Newtonsoft.Json" Version="12.0.2" /> | <PackageReference Include="Newtonsoft.Json" Version="12.0.2" /> | ||||
| <PackageReference Include="SharpZipLib" Version="1.1.0" /> | <PackageReference Include="SharpZipLib" Version="1.1.0" /> | ||||
| <PackageReference Include="System.Drawing.Common" Version="4.5.1" /> | <PackageReference Include="System.Drawing.Common" Version="4.5.1" /> | ||||
| <PackageReference Include="TensorFlow.NET" Version="0.8.0" /> | |||||
| <PackageReference Include="TensorFlow.NET" Version="0.8.2" /> | |||||
| </ItemGroup> | </ItemGroup> | ||||
| <ItemGroup> | <ItemGroup> | ||||