Skip to content

Commit 9a71f75

Browse files
committed
fix create_slot_with_initializer, upgrade to v1.14.0.
1 parent 0e29971 commit 9a71f75

9 files changed

Lines changed: 36 additions & 16 deletions

File tree

src/TensorFlowNET.Core/APIs/tf.variable.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ public static RefVariable get_variable(string name,
2323
TF_DataType dtype = TF_DataType.DtInvalid,
2424
object initializer = null, // IInitializer or Tensor
2525
bool? trainable = null,
26+
bool? use_resource = null,
27+
bool validate_shape = true,
2628
VariableSynchronization synchronization = VariableSynchronization.Auto,
2729
VariableAggregation aggregation = VariableAggregation.None)
2830
{
@@ -32,6 +34,8 @@ public static RefVariable get_variable(string name,
3234
name,
3335
shape: shape,
3436
dtype: dtype,
37+
use_resource: use_resource,
38+
validate_shape: validate_shape,
3539
initializer: initializer,
3640
trainable: trainable);
3741
}

src/TensorFlowNET.Core/Train/AdamOptimizer.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ protected override void _create_slots(RefVariable[] var_list)
7373
// Create slots for the first and second moments.
7474
foreach(var v in var_list)
7575
{
76-
_zero_slot(v, "m", Name);
76+
_zeros_slot(v, "m", Name);
77+
_zeros_slot(v, "v", Name);
7778
}
7879
}
7980

src/TensorFlowNET.Core/Train/Optimizer.cs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ public abstract class Optimizer : Trackable
2121
public static int GATE_OP = 1;
2222
public static int GATE_GRAPH = 2;
2323

24-
public string Name { get; set; }
24+
string _name;
25+
public string Name => _name;
2526
public float LearningRate { get; set; }
2627
public Tensor LearningRateTensor { get; set; }
2728
public bool _use_locking;
@@ -35,7 +36,7 @@ public Optimizer(float learning_rate, bool use_locking, string name = null)
3536
if (String.IsNullOrEmpty(name))
3637
throw new NotImplementedException("Must specify the optimizer name");
3738

38-
Name = name;
39+
_name = name;
3940
_use_locking = use_locking;
4041
LearningRate = learning_rate;
4142
// Dictionary of slots.
@@ -391,22 +392,34 @@ protected T _call_if_callable<T>(T param)
391392
/// <param name="slot_name"></param>
392393
/// <param name="op_name"></param>
393394
/// <returns></returns>
394-
protected RefVariable _zero_slot(RefVariable var, string slot_name, string op_name)
395+
protected RefVariable _zeros_slot(RefVariable var, string slot_name, string op_name)
395396
{
396397
var named_slots = _slot_dict(slot_name);
397398
if (!named_slots.ContainsKey(_var_key(var)))
398399
{
399400
var new_slot_variable = slot_creator.create_zeros_slot(var, op_name);
401+
_restore_slot_variable(slot_name: slot_name, variable: var, slot_variable: new_slot_variable);
402+
named_slots[_var_key(var)] = new_slot_variable;
400403
}
401404
return named_slots[_var_key(var)];
402405
}
403406

407+
/// <summary>
408+
/// Restore a newly created slot variable's value.
409+
/// </summary>
410+
protected void _restore_slot_variable(string slot_name, RefVariable variable, RefVariable slot_variable)
411+
{
412+
var variable_key = _var_key(variable);
413+
// TODO
414+
}
415+
404416
protected Dictionary<string, RefVariable> _slot_dict(string slot_name)
405417
{
406418
var named_slots = _slots.ContainsKey(slot_name) ? _slots[slot_name] : null;
407419
if(named_slots == null)
408420
{
409-
_slots[slot_name] = new Dictionary<string, RefVariable>();
421+
named_slots = new Dictionary<string, RefVariable>();
422+
_slots[slot_name] = named_slots;
410423
}
411424

412425
return named_slots;

src/TensorFlowNET.Core/Train/SlotCreator.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public RefVariable create_slot_with_initializer(RefVariable primary, IInitialize
4343
{
4444
var validate_shape = shape.is_fully_defined();
4545
var prefix = primary.op.name;
46-
return with(new variable_scope(prefix + "/" + name), delegate
46+
return with(new variable_scope(string.Empty, prefix + "/" + name), delegate
4747
{
4848
return _create_slot_var(primary, initializer, "", validate_shape, shape, dtype);
4949
});
@@ -62,11 +62,11 @@ public RefVariable create_slot_with_initializer(RefVariable primary, IInitialize
6262
private RefVariable _create_slot_var(VariableV1 primary, IInitializer val, string scope, bool validate_shape,
6363
TensorShape shape, TF_DataType dtype)
6464
{
65-
bool use_resource = primary is RefVariable;
65+
bool use_resource = primary is ResourceVariable;
6666
if (resource_variable_ops.is_resource_variable(primary))
6767
use_resource = true;
6868

69-
var slot = variable_scope.get_variable(
69+
var slot = tf.get_variable(
7070
scope,
7171
initializer: val,
7272
trainable: false,

src/TensorFlowNET.Core/Variables/VariableScope.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ public RefVariable get_variable(_VariableStore var_store,
3737
TF_DataType dtype = TF_DataType.DtInvalid,
3838
object initializer = null, // IInitializer or Tensor
3939
bool? trainable = null,
40+
bool? use_resource = null,
41+
bool validate_shape = true,
4042
VariableSynchronization synchronization = VariableSynchronization.Auto,
4143
VariableAggregation aggregation= VariableAggregation.None)
4244
{

src/TensorFlowNET.Core/Variables/variable_scope.py.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ private VariableScope _enter_scope_uncached()
104104
current_name_scope = ops.name_scope(name_scope);
105105
}
106106

107-
if (_name != null || _scope != null)
107+
if (!string.IsNullOrEmpty(_name) || _scope != null)
108108
{
109109
var name_scope = _scope.name.Split('/').Last();
110110
if (current_name_scope == null)

tensorflowlib/README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ TensorFlow.NET pack all required libraries in architecture-specific assemblies f
33
Here are some pre-built TensorFlow binaries you can use for each platform:
44

55
- Linux
6-
- CPU-only: https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-cpu-linux-x86_64-1.13.1.tar.gz
7-
- GPU-enabled: https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-gpu-linux-x86_64-1.13.1.tar.gz
8-
- Mac: https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-cpu-darwin-x86_64-1.13.1.tar.gz
6+
- CPU-only: https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-cpu-linux-x86_64-1.14.0.tar.gz
7+
- GPU-enabled: https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-gpu-linux-x86_64-1.14.0.tar.gz
8+
- Mac: https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-cpu-darwin-x86_64-1.14.0.tar.gz
99
- Windows
10-
- CPU-only: https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-cpu-windows-x86_64-1.13.1.zip
11-
- GPU-enabled: https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-gpu-windows-x86_64-1.13.1.zip
10+
- CPU-only: https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-cpu-windows-x86_64-1.14.0.zip
11+
- GPU-enabled: https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-gpu-windows-x86_64-1.14.0.zip
1212

1313
### Run in Linux
1414

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

4242
4. Install from local wheel file.
4343

44-
`pip install C:/tmp/tensorflow_pkg/tensorflow-1.13.0-cp36-cp36m-win_amd64.whl`
44+
`pip install C:/tmp/tensorflow_pkg/tensorflow-1.14.0-cp36-cp36m-win_amd64.whl`
4545

4646
### Export more APIs
4747

0 Bytes
Binary file not shown.

test/TensorFlowNET.Examples/TensorFlowNET.Examples.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
1818
<PackageReference Include="SharpZipLib" Version="1.1.0" />
1919
<PackageReference Include="System.Drawing.Common" Version="4.5.1" />
20-
<PackageReference Include="TensorFlow.NET" Version="0.8.0" />
20+
<PackageReference Include="TensorFlow.NET" Version="0.8.2" />
2121
</ItemGroup>
2222

2323
<ItemGroup>

0 commit comments

Comments
 (0)