Browse Source

Add console logger.

tags/v0.30
Oceania2018 4 years ago
parent
commit
db94e67d0d
8 changed files with 47 additions and 3 deletions
  1. +2
    -1
      src/TensorFlowNET.Core/Eager/EagerRunner.RecordGradient.cs
  2. +15
    -0
      src/TensorFlowNET.Core/Eager/EagerRunner.TapeSetPossibleGradientTypes.cs
  3. +2
    -0
      src/TensorFlowNET.Core/Eager/IEagerRunner.cs
  4. +3
    -0
      src/TensorFlowNET.Core/Gradients/Tape.RecordOperation.cs
  5. +9
    -1
      src/TensorFlowNET.Core/Gradients/Tape.cs
  6. +3
    -0
      src/TensorFlowNET.Core/Tensorflow.Binding.csproj
  7. +11
    -0
      src/TensorFlowNET.Core/tensorflow.cs
  8. +2
    -1
      src/TensorFlowNET.Keras/Engine/Functional.cs

+ 2
- 1
src/TensorFlowNET.Core/Eager/EagerRunner.RecordGradient.cs View File

@@ -1,5 +1,6 @@
using System;
using System.Linq;
using Microsoft.Extensions.Logging;
using Tensorflow.Gradients;
using static Tensorflow.Binding;
using static Tensorflow.tensorflow;
@@ -38,7 +39,7 @@ namespace Tensorflow.Eager
}*/
}

// Console.WriteLine($"RecordGradient: should_record={should_record}, op_name={op_name}");
tf.Logger.LogDebug($"RecordGradient: should_record={should_record}, op_name={op_name}");
if (!should_record) return should_record;

Tensor[] op_outputs;


+ 15
- 0
src/TensorFlowNET.Core/Eager/EagerRunner.TapeSetPossibleGradientTypes.cs View File

@@ -0,0 +1,15 @@
using System;
using Tensorflow.Gradients;
using static Tensorflow.Binding;
using static Tensorflow.tensorflow;

namespace Tensorflow.Eager
{
public partial class EagerRunner
{
public int TapeSetPossibleGradientTypes(params Tensor[] args)
{
return 1;
}
}
}

+ 2
- 0
src/TensorFlowNET.Core/Eager/IEagerRunner.cs View File

@@ -40,5 +40,7 @@ namespace Tensorflow.Eager
Tensor[] results);

bool MustRecordGradient();

int TapeSetPossibleGradientTypes(params Tensor[] args);
}
}

+ 3
- 0
src/TensorFlowNET.Core/Gradients/Tape.RecordOperation.cs View File

@@ -1,7 +1,9 @@
using System;
using System.Collections.Generic;
using Microsoft.Extensions.Logging;
using Tensorflow.Util;
using static Tensorflow.tensorflow;
using static Tensorflow.Binding;

namespace Tensorflow.Gradients
{
@@ -34,6 +36,7 @@ namespace Tensorflow.Gradients
foreach (var o in output_tensors)
{
tensor_tape_[o.GetID()] = op_id;
tf.Logger.LogDebug($"RecordOperation: tensor_tape_[{o.GetID()}] = {op_id}");
tensor_usage_[o.GetID()] = 1;
tensors.Add(o);
}


+ 9
- 1
src/TensorFlowNET.Core/Gradients/Tape.cs View File

@@ -1,5 +1,7 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using Tensorflow.Util;
using Microsoft.Extensions.Logging;
using static Tensorflow.Binding;
using static Tensorflow.tensorflow;

@@ -42,6 +44,7 @@ namespace Tensorflow.Gradients
if (!CouldBackprop())
return;

tf.Logger.LogDebug($"Watch tensor_id={tensor_id}");
tensor_tape_.emplace(tensor_id, -1);
}

@@ -50,8 +53,13 @@ namespace Tensorflow.Gradients
for (int i = 0; i < tensor_ids.Length; ++i)
{
if (tensor_tape_.find(tensor_ids[i]))
{
if (IsDtypeTrainable(dtypes[i]))
{
tf.Logger.LogDebug($"tape.h->ShouldRecord: should_record = true, tensor_tape_.size()={tensor_tape_.Count}, tensor_ids[{i}]={tensor_ids[i]}");
return true;
}
}
}
return false;
}


+ 3
- 0
src/TensorFlowNET.Core/Tensorflow.Binding.csproj View File

@@ -84,6 +84,9 @@ TensorFlow .NET v0.30 is focused on making more Keras API work including:
<ItemGroup>
<PackageReference Include="Google.Protobuf" Version="3.11.4" />
<PackageReference Include="MethodBoundaryAspect.Fody" Version="2.0.138" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="3.1.10" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="3.1.10" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="3.1.10" />
<PackageReference Include="NumSharp.Lite" Version="0.1.9" />
<PackageReference Include="Protobuf.Text" Version="0.4.0" />
</ItemGroup>


+ 11
- 0
src/TensorFlowNET.Core/tensorflow.cs View File

@@ -14,6 +14,8 @@
limitations under the License.
******************************************************************************/

using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using System.Collections.Generic;
using Tensorflow.Contexts;
using Tensorflow.Eager;
@@ -41,9 +43,18 @@ namespace Tensorflow
public OpDefLibrary OpDefLib;
public Context Context;
public IEagerRunner Runner;
public ILogger Logger;
ServiceProvider serviceProvider;

public tensorflow()
{
serviceProvider = new ServiceCollection()
.AddLogging(cfg => cfg.AddConsole())
.Configure<LoggerFilterOptions>(cfg => cfg.MinLevel = LogLevel.Warning)
.BuildServiceProvider();

Logger = serviceProvider.GetService<ILogger<tensorflow>>();

Status = new Status();
Context = new Context(new ContextOptions(), Status);
OpDefLib = new OpDefLibrary();


+ 2
- 1
src/TensorFlowNET.Keras/Engine/Functional.cs View File

@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using Tensorflow.Keras.ArgsDefinition;
using Tensorflow.Keras.Utils;
using Microsoft.Extensions.Logging;
using static Tensorflow.Binding;

namespace Tensorflow.Keras.Engine
@@ -335,7 +336,7 @@ namespace Tensorflow.Keras.Engine

var layer_inputs = node.MapArguments(tensor_dict);

// Console.WriteLine($"{node.Layer}: {node.Layer.Name}");
tf.Logger.LogDebug($"{node.Layer}: {node.Layer.Name}");
var outputs = node.Layer.Apply(layer_inputs, is_training: training);

// Update tensor_dict for next input


Loading…
Cancel
Save