Browse Source

fix create_slot_with_initializer, upgrade to v1.14.0.

tags/v0.9
Oceania2018 6 years ago
parent
commit
9a71f758dc
9 changed files with 36 additions and 16 deletions
  1. +4
    -0
      src/TensorFlowNET.Core/APIs/tf.variable.cs
  2. +2
    -1
      src/TensorFlowNET.Core/Train/AdamOptimizer.cs
  3. +17
    -4
      src/TensorFlowNET.Core/Train/Optimizer.cs
  4. +3
    -3
      src/TensorFlowNET.Core/Train/SlotCreator.cs
  5. +2
    -0
      src/TensorFlowNET.Core/Variables/VariableScope.cs
  6. +1
    -1
      src/TensorFlowNET.Core/Variables/variable_scope.py.cs
  7. +6
    -6
      tensorflowlib/README.md
  8. BIN
      tensorflowlib/runtimes/win-x64/native/tensorflow.dll
  9. +1
    -1
      test/TensorFlowNET.Examples/TensorFlowNET.Examples.csproj

+ 4
- 0
src/TensorFlowNET.Core/APIs/tf.variable.cs View File

@@ -23,6 +23,8 @@ namespace Tensorflow
TF_DataType dtype = TF_DataType.DtInvalid,
object initializer = null, // IInitializer or Tensor
bool? trainable = null,
bool? use_resource = null,
bool validate_shape = true,
VariableSynchronization synchronization = VariableSynchronization.Auto,
VariableAggregation aggregation = VariableAggregation.None)
{
@@ -32,6 +34,8 @@ namespace Tensorflow
name,
shape: shape,
dtype: dtype,
use_resource: use_resource,
validate_shape: validate_shape,
initializer: initializer,
trainable: trainable);
}


+ 2
- 1
src/TensorFlowNET.Core/Train/AdamOptimizer.cs View File

@@ -73,7 +73,8 @@ namespace Tensorflow.Train
// Create slots for the first and second moments.
foreach(var v in var_list)
{
_zero_slot(v, "m", Name);
_zeros_slot(v, "m", Name);
_zeros_slot(v, "v", Name);
}
}



+ 17
- 4
src/TensorFlowNET.Core/Train/Optimizer.cs View File

@@ -21,7 +21,8 @@ namespace Tensorflow
public static int GATE_OP = 1;
public static int GATE_GRAPH = 2;

public string Name { get; set; }
string _name;
public string Name => _name;
public float LearningRate { get; set; }
public Tensor LearningRateTensor { get; set; }
public bool _use_locking;
@@ -35,7 +36,7 @@ namespace Tensorflow
if (String.IsNullOrEmpty(name))
throw new NotImplementedException("Must specify the optimizer name");

Name = name;
_name = name;
_use_locking = use_locking;
LearningRate = learning_rate;
// Dictionary of slots.
@@ -391,22 +392,34 @@ namespace Tensorflow
/// <param name="slot_name"></param>
/// <param name="op_name"></param>
/// <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);
if (!named_slots.ContainsKey(_var_key(var)))
{
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)];
}

/// <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)
{
var named_slots = _slots.ContainsKey(slot_name) ? _slots[slot_name] : 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;


+ 3
- 3
src/TensorFlowNET.Core/Train/SlotCreator.cs View File

@@ -43,7 +43,7 @@ namespace Tensorflow.Train
{
var validate_shape = shape.is_fully_defined();
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);
});
@@ -62,11 +62,11 @@ namespace Tensorflow.Train
private RefVariable _create_slot_var(VariableV1 primary, IInitializer val, string scope, bool validate_shape,
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))
use_resource = true;

var slot = variable_scope.get_variable(
var slot = tf.get_variable(
scope,
initializer: val,
trainable: false,


+ 2
- 0
src/TensorFlowNET.Core/Variables/VariableScope.cs View File

@@ -37,6 +37,8 @@ namespace Tensorflow
TF_DataType dtype = TF_DataType.DtInvalid,
object initializer = null, // IInitializer or Tensor
bool? trainable = null,
bool? use_resource = null,
bool validate_shape = true,
VariableSynchronization synchronization = VariableSynchronization.Auto,
VariableAggregation aggregation= VariableAggregation.None)
{


+ 1
- 1
src/TensorFlowNET.Core/Variables/variable_scope.py.cs View File

@@ -104,7 +104,7 @@ namespace Tensorflow
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();
if (current_name_scope == null)


+ 6
- 6
tensorflowlib/README.md View File

@@ -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:

- 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
- 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

@@ -41,7 +41,7 @@ pacman -S git patch unzip

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



BIN
tensorflowlib/runtimes/win-x64/native/tensorflow.dll View File


+ 1
- 1
test/TensorFlowNET.Examples/TensorFlowNET.Examples.csproj View File

@@ -17,7 +17,7 @@
<PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
<PackageReference Include="SharpZipLib" Version="1.1.0" />
<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>


Loading…
Cancel
Save