Skip to content

Commit 27fbfb0

Browse files
committed
fix TF_OperationOutputNumConsumers
1 parent f516966 commit 27fbfb0

7 files changed

Lines changed: 20 additions & 11 deletions

File tree

‎src/TensorFlowNET.Core/Gradients/gradients_impl.py.cs‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections.Generic;
33
using System.Linq;
44
using System.Text;
5+
using System.Threading;
56

67
namespace Tensorflow
78
{
@@ -49,10 +50,9 @@ public static void _GradientsHelper(object ys,
4950
all.AddRange(stop_gradients1);
5051
all.AddRange(grad_ys1);
5152

52-
string grad_scope = "";
53-
using (var namescope = new ops.name_scope(name, "gradients", values: all))
53+
Python.with<ops.name_scope>(new ops.name_scope(name, "gradients", values: all), scope =>
5454
{
55-
grad_scope = namescope;
55+
string grad_scope = scope;
5656
// Get a uid for this call to gradients that can be used to help
5757
// cluster ops for compilation.
5858
var gradient_uid = ops.get_default_graph().unique_name("uid");
@@ -63,7 +63,7 @@ public static void _GradientsHelper(object ys,
6363
var from_ops = xs1.Select(x => x.op).ToList();
6464
var stop_gradient_ops = stop_gradients1.Select(x => x.op).ToList();
6565
_PendingCount(to_ops, from_ops, colocate_gradients_with_ops, new List<object>(), xs1);
66-
}
66+
});
6767
}
6868

6969
/// <summary>

‎src/TensorFlowNET.Core/Operations/Operation.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public Operation(IntPtr handle)
3838
return;
3939

4040
_handle = handle;
41-
41+
this.Graph = ops.get_default_graph();
4242
_outputs = new Tensor[NumOutputs];
4343
for (int i = 0; i < NumOutputs; i++)
4444
_outputs[i] = new Tensor(this, i, OutputType(i));

‎src/TensorFlowNET.Core/Operations/c_api.ops.cs‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,6 @@ public partial class c_api
169169
[DllImport(TensorFlowLibName)]
170170
public static extern unsafe int TF_OperationOutputConsumers(TF_Output oper_out, IntPtr consumers, int max_consumers);
171171

172-
[DllImport(TensorFlowLibName)]
173-
public static extern int TF_OperationOutputConsumers(TF_Output oper_out);
174-
175172
[DllImport(TensorFlowLibName)]
176173
public static extern TF_DataType TF_OperationOutputType(TF_Output oper_out);
177174

‎src/TensorFlowNET.Core/Sessions/c_api.tf_session_helper.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public partial class c_api
99
{
1010
public static string[] TF_OperationOutputConsumers_wrapper(TF_Output oper_out)
1111
{
12-
int num_consumers = TF_OperationOutputConsumers(oper_out);
12+
int num_consumers = TF_OperationOutputNumConsumers(oper_out);
1313
int size = Marshal.SizeOf<TF_Input>();
1414
var handle = Marshal.AllocHGlobal(size * num_consumers);
1515
int num = TF_OperationOutputConsumers(oper_out, handle, num_consumers);

‎src/TensorFlowNET.Core/Tensors/Tensor.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public partial class Tensor : IDisposable
1919
private int _id;
2020
public int Id => _id;
2121

22-
public Graph Graph => op.Graph;
22+
public Graph Graph => op?.Graph;
2323
public Operation op { get; }
2424

2525
/// <summary>

‎test/TensorFlowNET.Examples/LinearRegression.cs‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,15 @@ public void Run()
5151
var optimizer = tf.train.GradientDescentOptimizer(learning_rate);
5252
optimizer.minimize(cost);
5353

54+
// Initialize the variables (i.e. assign their default value)
55+
var init = tf.global_variables_initializer();
5456

57+
// Start training
58+
Python.with<Session>(tf.Session(), sess =>
59+
{
60+
// Run the initializer
61+
sess.run(init);
62+
});
5563
}
5664
}
5765
}

‎test/TensorFlowNET.Examples/Program.cs‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ static void Main(string[] args)
1313
{
1414
if (args.Length > 0 && !args.Contains(type.Name))
1515
continue;
16-
16+
17+
Console.WriteLine($"{DateTime.UtcNow} Starting {type.Name}");
18+
1719
var example = (IExample)Activator.CreateInstance(type);
1820

1921
try
@@ -24,6 +26,8 @@ static void Main(string[] args)
2426
{
2527
Console.WriteLine(ex);
2628
}
29+
30+
Console.WriteLine($"{DateTime.UtcNow} Completed {type.Name}");
2731
}
2832

2933
Console.ReadLine();

0 commit comments

Comments
 (0)