| @@ -2,6 +2,7 @@ | |||||
| using System.Collections.Generic; | using System.Collections.Generic; | ||||
| using System.Linq; | using System.Linq; | ||||
| using System.Text; | using System.Text; | ||||
| using System.Threading; | |||||
| namespace Tensorflow | namespace Tensorflow | ||||
| { | { | ||||
| @@ -49,10 +50,9 @@ namespace Tensorflow | |||||
| all.AddRange(stop_gradients1); | all.AddRange(stop_gradients1); | ||||
| all.AddRange(grad_ys1); | 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 | // Get a uid for this call to gradients that can be used to help | ||||
| // cluster ops for compilation. | // cluster ops for compilation. | ||||
| var gradient_uid = ops.get_default_graph().unique_name("uid"); | 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 from_ops = xs1.Select(x => x.op).ToList(); | ||||
| var stop_gradient_ops = stop_gradients1.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); | _PendingCount(to_ops, from_ops, colocate_gradients_with_ops, new List<object>(), xs1); | ||||
| } | |||||
| }); | |||||
| } | } | ||||
| /// <summary> | /// <summary> | ||||
| @@ -38,7 +38,7 @@ namespace Tensorflow | |||||
| return; | return; | ||||
| _handle = handle; | _handle = handle; | ||||
| this.Graph = ops.get_default_graph(); | |||||
| _outputs = new Tensor[NumOutputs]; | _outputs = new Tensor[NumOutputs]; | ||||
| for (int i = 0; i < NumOutputs; i++) | for (int i = 0; i < NumOutputs; i++) | ||||
| _outputs[i] = new Tensor(this, i, OutputType(i)); | _outputs[i] = new Tensor(this, i, OutputType(i)); | ||||
| @@ -169,9 +169,6 @@ namespace Tensorflow | |||||
| [DllImport(TensorFlowLibName)] | [DllImport(TensorFlowLibName)] | ||||
| public static extern unsafe int TF_OperationOutputConsumers(TF_Output oper_out, IntPtr consumers, int max_consumers); | 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)] | [DllImport(TensorFlowLibName)] | ||||
| public static extern TF_DataType TF_OperationOutputType(TF_Output oper_out); | public static extern TF_DataType TF_OperationOutputType(TF_Output oper_out); | ||||
| @@ -9,7 +9,7 @@ namespace Tensorflow | |||||
| { | { | ||||
| public static string[] TF_OperationOutputConsumers_wrapper(TF_Output oper_out) | 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>(); | int size = Marshal.SizeOf<TF_Input>(); | ||||
| var handle = Marshal.AllocHGlobal(size * num_consumers); | var handle = Marshal.AllocHGlobal(size * num_consumers); | ||||
| int num = TF_OperationOutputConsumers(oper_out, handle, num_consumers); | int num = TF_OperationOutputConsumers(oper_out, handle, num_consumers); | ||||
| @@ -19,7 +19,7 @@ namespace Tensorflow | |||||
| private int _id; | private int _id; | ||||
| public int Id => _id; | public int Id => _id; | ||||
| public Graph Graph => op.Graph; | |||||
| public Graph Graph => op?.Graph; | |||||
| public Operation op { get; } | public Operation op { get; } | ||||
| /// <summary> | /// <summary> | ||||
| @@ -51,7 +51,15 @@ namespace TensorFlowNET.Examples | |||||
| var optimizer = tf.train.GradientDescentOptimizer(learning_rate); | var optimizer = tf.train.GradientDescentOptimizer(learning_rate); | ||||
| optimizer.minimize(cost); | 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); | |||||
| }); | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| @@ -13,7 +13,9 @@ namespace TensorFlowNET.Examples | |||||
| { | { | ||||
| if (args.Length > 0 && !args.Contains(type.Name)) | if (args.Length > 0 && !args.Contains(type.Name)) | ||||
| continue; | continue; | ||||
| Console.WriteLine($"{DateTime.UtcNow} Starting {type.Name}"); | |||||
| var example = (IExample)Activator.CreateInstance(type); | var example = (IExample)Activator.CreateInstance(type); | ||||
| try | try | ||||
| @@ -24,6 +26,8 @@ namespace TensorFlowNET.Examples | |||||
| { | { | ||||
| Console.WriteLine(ex); | Console.WriteLine(ex); | ||||
| } | } | ||||
| Console.WriteLine($"{DateTime.UtcNow} Completed {type.Name}"); | |||||
| } | } | ||||
| Console.ReadLine(); | Console.ReadLine(); | ||||