Browse Source

fix TF_OperationOutputNumConsumers

tags/v0.8.0
Oceania2018 6 years ago
parent
commit
27fbfb02c0
7 changed files with 20 additions and 11 deletions
  1. +4
    -4
      src/TensorFlowNET.Core/Gradients/gradients_impl.py.cs
  2. +1
    -1
      src/TensorFlowNET.Core/Operations/Operation.cs
  3. +0
    -3
      src/TensorFlowNET.Core/Operations/c_api.ops.cs
  4. +1
    -1
      src/TensorFlowNET.Core/Sessions/c_api.tf_session_helper.cs
  5. +1
    -1
      src/TensorFlowNET.Core/Tensors/Tensor.cs
  6. +8
    -0
      test/TensorFlowNET.Examples/LinearRegression.cs
  7. +5
    -1
      test/TensorFlowNET.Examples/Program.cs

+ 4
- 4
src/TensorFlowNET.Core/Gradients/gradients_impl.py.cs View File

@@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

namespace Tensorflow
{
@@ -49,10 +50,9 @@ namespace Tensorflow
all.AddRange(stop_gradients1);
all.AddRange(grad_ys1);

string grad_scope = "";
using (var namescope = new ops.name_scope(name, "gradients", values: all))
Python.with<ops.name_scope>(new ops.name_scope(name, "gradients", values: all), scope =>
{
grad_scope = namescope;
string grad_scope = scope;
// Get a uid for this call to gradients that can be used to help
// cluster ops for compilation.
var gradient_uid = ops.get_default_graph().unique_name("uid");
@@ -63,7 +63,7 @@ namespace Tensorflow
var from_ops = xs1.Select(x => x.op).ToList();
var stop_gradient_ops = stop_gradients1.Select(x => x.op).ToList();
_PendingCount(to_ops, from_ops, colocate_gradients_with_ops, new List<object>(), xs1);
}
});
}

/// <summary>


+ 1
- 1
src/TensorFlowNET.Core/Operations/Operation.cs View File

@@ -38,7 +38,7 @@ namespace Tensorflow
return;

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


+ 0
- 3
src/TensorFlowNET.Core/Operations/c_api.ops.cs View File

@@ -169,9 +169,6 @@ namespace Tensorflow
[DllImport(TensorFlowLibName)]
public static extern unsafe int TF_OperationOutputConsumers(TF_Output oper_out, IntPtr consumers, int max_consumers);

[DllImport(TensorFlowLibName)]
public static extern int TF_OperationOutputConsumers(TF_Output oper_out);

[DllImport(TensorFlowLibName)]
public static extern TF_DataType TF_OperationOutputType(TF_Output oper_out);



+ 1
- 1
src/TensorFlowNET.Core/Sessions/c_api.tf_session_helper.cs View File

@@ -9,7 +9,7 @@ namespace Tensorflow
{
public static string[] TF_OperationOutputConsumers_wrapper(TF_Output oper_out)
{
int num_consumers = TF_OperationOutputConsumers(oper_out);
int num_consumers = TF_OperationOutputNumConsumers(oper_out);
int size = Marshal.SizeOf<TF_Input>();
var handle = Marshal.AllocHGlobal(size * num_consumers);
int num = TF_OperationOutputConsumers(oper_out, handle, num_consumers);


+ 1
- 1
src/TensorFlowNET.Core/Tensors/Tensor.cs View File

@@ -19,7 +19,7 @@ namespace Tensorflow
private int _id;
public int Id => _id;

public Graph Graph => op.Graph;
public Graph Graph => op?.Graph;
public Operation op { get; }

/// <summary>


+ 8
- 0
test/TensorFlowNET.Examples/LinearRegression.cs View File

@@ -51,7 +51,15 @@ namespace TensorFlowNET.Examples
var optimizer = tf.train.GradientDescentOptimizer(learning_rate);
optimizer.minimize(cost);

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

// Start training
Python.with<Session>(tf.Session(), sess =>
{
// Run the initializer
sess.run(init);
});
}
}
}

+ 5
- 1
test/TensorFlowNET.Examples/Program.cs View File

@@ -13,7 +13,9 @@ namespace TensorFlowNET.Examples
{
if (args.Length > 0 && !args.Contains(type.Name))
continue;

Console.WriteLine($"{DateTime.UtcNow} Starting {type.Name}");

var example = (IExample)Activator.CreateInstance(type);

try
@@ -24,6 +26,8 @@ namespace TensorFlowNET.Examples
{
Console.WriteLine(ex);
}

Console.WriteLine($"{DateTime.UtcNow} Completed {type.Name}");
}

Console.ReadLine();


Loading…
Cancel
Save