Browse Source

change parameter to BindingArray.

tags/v0.20
Oceania2018 5 years ago
parent
commit
3aa1cf9928
28 changed files with 377 additions and 253 deletions
  1. +70
    -0
      TensorFlow.NET.sln
  2. +28
    -0
      src/TensorFlowNET.Console/MemoryLeakTesting.cs
  3. +20
    -0
      src/TensorFlowNET.Console/Program.cs
  4. +14
    -0
      src/TensorFlowNET.Console/TensorFlowNET.Console.csproj
  5. +48
    -0
      src/TensorFlowNET.Core/Eager/EagerTensor.Creation.cs
  6. +0
    -3
      src/TensorFlowNET.Core/Eager/EagerTensor.Implicit.cs
  7. +1
    -30
      src/TensorFlowNET.Core/Eager/EagerTensor.cs
  8. +0
    -26
      src/TensorFlowNET.Core/Eager/EagerTensorHandle.cs
  9. +9
    -17
      src/TensorFlowNET.Core/Eager/Execute.cs
  10. +0
    -23
      src/TensorFlowNET.Core/Eager/TFE_TensorHandle.cs
  11. +29
    -10
      src/TensorFlowNET.Core/Eager/c_api.eager.cs
  12. +13
    -6
      src/TensorFlowNET.Core/Gradients/GradientTape.cs
  13. +5
    -6
      src/TensorFlowNET.Core/Gradients/Tape.cs
  14. +5
    -1
      src/TensorFlowNET.Core/Gradients/math_grad.cs
  15. +4
    -4
      src/TensorFlowNET.Core/Operations/NnOps/gen_nn_ops.cs
  16. +20
    -20
      src/TensorFlowNET.Core/Operations/gen_array_ops.cs
  17. +59
    -59
      src/TensorFlowNET.Core/Operations/gen_math_ops.cs
  18. +2
    -2
      src/TensorFlowNET.Core/Operations/gen_random_ops.cs
  19. +13
    -13
      src/TensorFlowNET.Core/Operations/gen_resource_variable_ops.cs
  20. +1
    -1
      src/TensorFlowNET.Core/Tensors/TF_Tensor.cs
  21. +1
    -1
      src/TensorFlowNET.Core/Tensors/Tensor.Value.cs
  22. +2
    -2
      src/TensorFlowNET.Core/Tensors/constant_op.cs
  23. +2
    -2
      src/TensorFlowNET.Core/Training/gen_training_ops.py.cs
  24. +12
    -1
      src/TensorFlowNET.Core/Util/BindingArray.cs
  25. +1
    -0
      src/TensorFlowNET.Core/Variables/BaseResourceVariable.cs
  26. +6
    -0
      src/TensorFlowNET.Core/Variables/ResourceVariable.cs
  27. +3
    -0
      src/TensorFlowNET.Core/Variables/c_api.variable.cs
  28. +9
    -26
      src/TensorFlowNET.Core/tensorflow.cs

+ 70
- 0
TensorFlow.NET.sln View File

@@ -13,98 +13,168 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tensorflow.Keras", "src\Ten
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tensorflow.Keras.UnitTest", "test\Tensorflow.Keras.UnitTest\Tensorflow.Keras.UnitTest.csproj", "{EB92DD90-6346-41FB-B967-2B33A860AD98}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TensorFlowNET.Console", "src\TensorFlowNET.Console\TensorFlowNET.Console.csproj", "{03F06299-3F4B-4449-A709-3A647657BC0C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Debug-Minimal|Any CPU = Debug-Minimal|Any CPU
Debug-Minimal|x64 = Debug-Minimal|x64
Debug-Minimal|x86 = Debug-Minimal|x86
Publish|Any CPU = Publish|Any CPU
Publish|x64 = Publish|x64
Publish|x86 = Publish|x86
Release|Any CPU = Release|Any CPU
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{FD682AC0-7B2D-45D3-8B0D-C6D678B04144}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FD682AC0-7B2D-45D3-8B0D-C6D678B04144}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FD682AC0-7B2D-45D3-8B0D-C6D678B04144}.Debug|x64.ActiveCfg = Debug|x64
{FD682AC0-7B2D-45D3-8B0D-C6D678B04144}.Debug|x64.Build.0 = Debug|x64
{FD682AC0-7B2D-45D3-8B0D-C6D678B04144}.Debug|x86.ActiveCfg = Debug|Any CPU
{FD682AC0-7B2D-45D3-8B0D-C6D678B04144}.Debug|x86.Build.0 = Debug|Any CPU
{FD682AC0-7B2D-45D3-8B0D-C6D678B04144}.Debug-Minimal|Any CPU.ActiveCfg = Debug|Any CPU
{FD682AC0-7B2D-45D3-8B0D-C6D678B04144}.Debug-Minimal|Any CPU.Build.0 = Debug|Any CPU
{FD682AC0-7B2D-45D3-8B0D-C6D678B04144}.Debug-Minimal|x64.ActiveCfg = Debug|x64
{FD682AC0-7B2D-45D3-8B0D-C6D678B04144}.Debug-Minimal|x64.Build.0 = Debug|x64
{FD682AC0-7B2D-45D3-8B0D-C6D678B04144}.Debug-Minimal|x86.ActiveCfg = Debug|Any CPU
{FD682AC0-7B2D-45D3-8B0D-C6D678B04144}.Debug-Minimal|x86.Build.0 = Debug|Any CPU
{FD682AC0-7B2D-45D3-8B0D-C6D678B04144}.Publish|Any CPU.ActiveCfg = Release|Any CPU
{FD682AC0-7B2D-45D3-8B0D-C6D678B04144}.Publish|Any CPU.Build.0 = Release|Any CPU
{FD682AC0-7B2D-45D3-8B0D-C6D678B04144}.Publish|x64.ActiveCfg = Release|x64
{FD682AC0-7B2D-45D3-8B0D-C6D678B04144}.Publish|x64.Build.0 = Release|x64
{FD682AC0-7B2D-45D3-8B0D-C6D678B04144}.Publish|x86.ActiveCfg = Release|Any CPU
{FD682AC0-7B2D-45D3-8B0D-C6D678B04144}.Publish|x86.Build.0 = Release|Any CPU
{FD682AC0-7B2D-45D3-8B0D-C6D678B04144}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FD682AC0-7B2D-45D3-8B0D-C6D678B04144}.Release|Any CPU.Build.0 = Release|Any CPU
{FD682AC0-7B2D-45D3-8B0D-C6D678B04144}.Release|x64.ActiveCfg = Release|x64
{FD682AC0-7B2D-45D3-8B0D-C6D678B04144}.Release|x64.Build.0 = Release|x64
{FD682AC0-7B2D-45D3-8B0D-C6D678B04144}.Release|x86.ActiveCfg = Release|Any CPU
{FD682AC0-7B2D-45D3-8B0D-C6D678B04144}.Release|x86.Build.0 = Release|Any CPU
{3A6EB896-604F-4E25-B677-B8103BCF3D2E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3A6EB896-604F-4E25-B677-B8103BCF3D2E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3A6EB896-604F-4E25-B677-B8103BCF3D2E}.Debug|x64.ActiveCfg = Debug|x64
{3A6EB896-604F-4E25-B677-B8103BCF3D2E}.Debug|x64.Build.0 = Debug|x64
{3A6EB896-604F-4E25-B677-B8103BCF3D2E}.Debug|x86.ActiveCfg = Debug|Any CPU
{3A6EB896-604F-4E25-B677-B8103BCF3D2E}.Debug|x86.Build.0 = Debug|Any CPU
{3A6EB896-604F-4E25-B677-B8103BCF3D2E}.Debug-Minimal|Any CPU.ActiveCfg = Debug|Any CPU
{3A6EB896-604F-4E25-B677-B8103BCF3D2E}.Debug-Minimal|Any CPU.Build.0 = Debug|Any CPU
{3A6EB896-604F-4E25-B677-B8103BCF3D2E}.Debug-Minimal|x64.ActiveCfg = Debug|x64
{3A6EB896-604F-4E25-B677-B8103BCF3D2E}.Debug-Minimal|x64.Build.0 = Debug|x64
{3A6EB896-604F-4E25-B677-B8103BCF3D2E}.Debug-Minimal|x86.ActiveCfg = Debug|Any CPU
{3A6EB896-604F-4E25-B677-B8103BCF3D2E}.Debug-Minimal|x86.Build.0 = Debug|Any CPU
{3A6EB896-604F-4E25-B677-B8103BCF3D2E}.Publish|Any CPU.ActiveCfg = Release|Any CPU
{3A6EB896-604F-4E25-B677-B8103BCF3D2E}.Publish|Any CPU.Build.0 = Release|Any CPU
{3A6EB896-604F-4E25-B677-B8103BCF3D2E}.Publish|x64.ActiveCfg = Release|x64
{3A6EB896-604F-4E25-B677-B8103BCF3D2E}.Publish|x64.Build.0 = Release|x64
{3A6EB896-604F-4E25-B677-B8103BCF3D2E}.Publish|x86.ActiveCfg = Release|Any CPU
{3A6EB896-604F-4E25-B677-B8103BCF3D2E}.Publish|x86.Build.0 = Release|Any CPU
{3A6EB896-604F-4E25-B677-B8103BCF3D2E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3A6EB896-604F-4E25-B677-B8103BCF3D2E}.Release|Any CPU.Build.0 = Release|Any CPU
{3A6EB896-604F-4E25-B677-B8103BCF3D2E}.Release|x64.ActiveCfg = Release|x64
{3A6EB896-604F-4E25-B677-B8103BCF3D2E}.Release|x64.Build.0 = Release|x64
{3A6EB896-604F-4E25-B677-B8103BCF3D2E}.Release|x86.ActiveCfg = Release|Any CPU
{3A6EB896-604F-4E25-B677-B8103BCF3D2E}.Release|x86.Build.0 = Release|Any CPU
{23C28035-2FCE-41F3-9A12-E73CE8A5AE32}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{23C28035-2FCE-41F3-9A12-E73CE8A5AE32}.Debug|Any CPU.Build.0 = Debug|Any CPU
{23C28035-2FCE-41F3-9A12-E73CE8A5AE32}.Debug|x64.ActiveCfg = Debug|x64
{23C28035-2FCE-41F3-9A12-E73CE8A5AE32}.Debug|x64.Build.0 = Debug|x64
{23C28035-2FCE-41F3-9A12-E73CE8A5AE32}.Debug|x86.ActiveCfg = Debug|Any CPU
{23C28035-2FCE-41F3-9A12-E73CE8A5AE32}.Debug|x86.Build.0 = Debug|Any CPU
{23C28035-2FCE-41F3-9A12-E73CE8A5AE32}.Debug-Minimal|Any CPU.ActiveCfg = Debug|Any CPU
{23C28035-2FCE-41F3-9A12-E73CE8A5AE32}.Debug-Minimal|Any CPU.Build.0 = Debug|Any CPU
{23C28035-2FCE-41F3-9A12-E73CE8A5AE32}.Debug-Minimal|x64.ActiveCfg = Debug|x64
{23C28035-2FCE-41F3-9A12-E73CE8A5AE32}.Debug-Minimal|x64.Build.0 = Debug|x64
{23C28035-2FCE-41F3-9A12-E73CE8A5AE32}.Debug-Minimal|x86.ActiveCfg = Debug|Any CPU
{23C28035-2FCE-41F3-9A12-E73CE8A5AE32}.Debug-Minimal|x86.Build.0 = Debug|Any CPU
{23C28035-2FCE-41F3-9A12-E73CE8A5AE32}.Publish|Any CPU.ActiveCfg = Release|Any CPU
{23C28035-2FCE-41F3-9A12-E73CE8A5AE32}.Publish|Any CPU.Build.0 = Release|Any CPU
{23C28035-2FCE-41F3-9A12-E73CE8A5AE32}.Publish|x64.ActiveCfg = Release|x64
{23C28035-2FCE-41F3-9A12-E73CE8A5AE32}.Publish|x64.Build.0 = Release|x64
{23C28035-2FCE-41F3-9A12-E73CE8A5AE32}.Publish|x86.ActiveCfg = Release|Any CPU
{23C28035-2FCE-41F3-9A12-E73CE8A5AE32}.Publish|x86.Build.0 = Release|Any CPU
{23C28035-2FCE-41F3-9A12-E73CE8A5AE32}.Release|Any CPU.ActiveCfg = Release|Any CPU
{23C28035-2FCE-41F3-9A12-E73CE8A5AE32}.Release|Any CPU.Build.0 = Release|Any CPU
{23C28035-2FCE-41F3-9A12-E73CE8A5AE32}.Release|x64.ActiveCfg = Release|x64
{23C28035-2FCE-41F3-9A12-E73CE8A5AE32}.Release|x64.Build.0 = Release|x64
{23C28035-2FCE-41F3-9A12-E73CE8A5AE32}.Release|x86.ActiveCfg = Release|Any CPU
{23C28035-2FCE-41F3-9A12-E73CE8A5AE32}.Release|x86.Build.0 = Release|Any CPU
{6268B461-486A-460B-9B3C-86493CBBAAF7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6268B461-486A-460B-9B3C-86493CBBAAF7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6268B461-486A-460B-9B3C-86493CBBAAF7}.Debug|x64.ActiveCfg = Debug|x64
{6268B461-486A-460B-9B3C-86493CBBAAF7}.Debug|x64.Build.0 = Debug|x64
{6268B461-486A-460B-9B3C-86493CBBAAF7}.Debug|x86.ActiveCfg = Debug|Any CPU
{6268B461-486A-460B-9B3C-86493CBBAAF7}.Debug|x86.Build.0 = Debug|Any CPU
{6268B461-486A-460B-9B3C-86493CBBAAF7}.Debug-Minimal|Any CPU.ActiveCfg = Debug|Any CPU
{6268B461-486A-460B-9B3C-86493CBBAAF7}.Debug-Minimal|Any CPU.Build.0 = Debug|Any CPU
{6268B461-486A-460B-9B3C-86493CBBAAF7}.Debug-Minimal|x64.ActiveCfg = Debug|x64
{6268B461-486A-460B-9B3C-86493CBBAAF7}.Debug-Minimal|x64.Build.0 = Debug|x64
{6268B461-486A-460B-9B3C-86493CBBAAF7}.Debug-Minimal|x86.ActiveCfg = Debug|Any CPU
{6268B461-486A-460B-9B3C-86493CBBAAF7}.Debug-Minimal|x86.Build.0 = Debug|Any CPU
{6268B461-486A-460B-9B3C-86493CBBAAF7}.Publish|Any CPU.ActiveCfg = Release|Any CPU
{6268B461-486A-460B-9B3C-86493CBBAAF7}.Publish|Any CPU.Build.0 = Release|Any CPU
{6268B461-486A-460B-9B3C-86493CBBAAF7}.Publish|x64.ActiveCfg = Release|x64
{6268B461-486A-460B-9B3C-86493CBBAAF7}.Publish|x64.Build.0 = Release|x64
{6268B461-486A-460B-9B3C-86493CBBAAF7}.Publish|x86.ActiveCfg = Release|Any CPU
{6268B461-486A-460B-9B3C-86493CBBAAF7}.Publish|x86.Build.0 = Release|Any CPU
{6268B461-486A-460B-9B3C-86493CBBAAF7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6268B461-486A-460B-9B3C-86493CBBAAF7}.Release|Any CPU.Build.0 = Release|Any CPU
{6268B461-486A-460B-9B3C-86493CBBAAF7}.Release|x64.ActiveCfg = Release|x64
{6268B461-486A-460B-9B3C-86493CBBAAF7}.Release|x64.Build.0 = Release|x64
{6268B461-486A-460B-9B3C-86493CBBAAF7}.Release|x86.ActiveCfg = Release|Any CPU
{6268B461-486A-460B-9B3C-86493CBBAAF7}.Release|x86.Build.0 = Release|Any CPU
{EB92DD90-6346-41FB-B967-2B33A860AD98}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EB92DD90-6346-41FB-B967-2B33A860AD98}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EB92DD90-6346-41FB-B967-2B33A860AD98}.Debug|x64.ActiveCfg = Debug|x64
{EB92DD90-6346-41FB-B967-2B33A860AD98}.Debug|x64.Build.0 = Debug|x64
{EB92DD90-6346-41FB-B967-2B33A860AD98}.Debug|x86.ActiveCfg = Debug|Any CPU
{EB92DD90-6346-41FB-B967-2B33A860AD98}.Debug|x86.Build.0 = Debug|Any CPU
{EB92DD90-6346-41FB-B967-2B33A860AD98}.Debug-Minimal|Any CPU.ActiveCfg = Debug|Any CPU
{EB92DD90-6346-41FB-B967-2B33A860AD98}.Debug-Minimal|Any CPU.Build.0 = Debug|Any CPU
{EB92DD90-6346-41FB-B967-2B33A860AD98}.Debug-Minimal|x64.ActiveCfg = Debug|x64
{EB92DD90-6346-41FB-B967-2B33A860AD98}.Debug-Minimal|x64.Build.0 = Debug|x64
{EB92DD90-6346-41FB-B967-2B33A860AD98}.Debug-Minimal|x86.ActiveCfg = Debug|Any CPU
{EB92DD90-6346-41FB-B967-2B33A860AD98}.Debug-Minimal|x86.Build.0 = Debug|Any CPU
{EB92DD90-6346-41FB-B967-2B33A860AD98}.Publish|Any CPU.ActiveCfg = Release|Any CPU
{EB92DD90-6346-41FB-B967-2B33A860AD98}.Publish|Any CPU.Build.0 = Release|Any CPU
{EB92DD90-6346-41FB-B967-2B33A860AD98}.Publish|x64.ActiveCfg = Release|x64
{EB92DD90-6346-41FB-B967-2B33A860AD98}.Publish|x64.Build.0 = Release|x64
{EB92DD90-6346-41FB-B967-2B33A860AD98}.Publish|x86.ActiveCfg = Release|Any CPU
{EB92DD90-6346-41FB-B967-2B33A860AD98}.Publish|x86.Build.0 = Release|Any CPU
{EB92DD90-6346-41FB-B967-2B33A860AD98}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EB92DD90-6346-41FB-B967-2B33A860AD98}.Release|Any CPU.Build.0 = Release|Any CPU
{EB92DD90-6346-41FB-B967-2B33A860AD98}.Release|x64.ActiveCfg = Release|x64
{EB92DD90-6346-41FB-B967-2B33A860AD98}.Release|x64.Build.0 = Release|x64
{EB92DD90-6346-41FB-B967-2B33A860AD98}.Release|x86.ActiveCfg = Release|Any CPU
{EB92DD90-6346-41FB-B967-2B33A860AD98}.Release|x86.Build.0 = Release|Any CPU
{03F06299-3F4B-4449-A709-3A647657BC0C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{03F06299-3F4B-4449-A709-3A647657BC0C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{03F06299-3F4B-4449-A709-3A647657BC0C}.Debug|x64.ActiveCfg = Debug|Any CPU
{03F06299-3F4B-4449-A709-3A647657BC0C}.Debug|x64.Build.0 = Debug|Any CPU
{03F06299-3F4B-4449-A709-3A647657BC0C}.Debug|x86.ActiveCfg = Debug|Any CPU
{03F06299-3F4B-4449-A709-3A647657BC0C}.Debug|x86.Build.0 = Debug|Any CPU
{03F06299-3F4B-4449-A709-3A647657BC0C}.Debug-Minimal|Any CPU.ActiveCfg = Debug|Any CPU
{03F06299-3F4B-4449-A709-3A647657BC0C}.Debug-Minimal|Any CPU.Build.0 = Debug|Any CPU
{03F06299-3F4B-4449-A709-3A647657BC0C}.Debug-Minimal|x64.ActiveCfg = Debug|Any CPU
{03F06299-3F4B-4449-A709-3A647657BC0C}.Debug-Minimal|x64.Build.0 = Debug|Any CPU
{03F06299-3F4B-4449-A709-3A647657BC0C}.Debug-Minimal|x86.ActiveCfg = Debug|Any CPU
{03F06299-3F4B-4449-A709-3A647657BC0C}.Debug-Minimal|x86.Build.0 = Debug|Any CPU
{03F06299-3F4B-4449-A709-3A647657BC0C}.Publish|Any CPU.ActiveCfg = Debug|Any CPU
{03F06299-3F4B-4449-A709-3A647657BC0C}.Publish|Any CPU.Build.0 = Debug|Any CPU
{03F06299-3F4B-4449-A709-3A647657BC0C}.Publish|x64.ActiveCfg = Debug|Any CPU
{03F06299-3F4B-4449-A709-3A647657BC0C}.Publish|x64.Build.0 = Debug|Any CPU
{03F06299-3F4B-4449-A709-3A647657BC0C}.Publish|x86.ActiveCfg = Debug|Any CPU
{03F06299-3F4B-4449-A709-3A647657BC0C}.Publish|x86.Build.0 = Debug|Any CPU
{03F06299-3F4B-4449-A709-3A647657BC0C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{03F06299-3F4B-4449-A709-3A647657BC0C}.Release|Any CPU.Build.0 = Release|Any CPU
{03F06299-3F4B-4449-A709-3A647657BC0C}.Release|x64.ActiveCfg = Release|Any CPU
{03F06299-3F4B-4449-A709-3A647657BC0C}.Release|x64.Build.0 = Release|Any CPU
{03F06299-3F4B-4449-A709-3A647657BC0C}.Release|x86.ActiveCfg = Release|Any CPU
{03F06299-3F4B-4449-A709-3A647657BC0C}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE


+ 28
- 0
src/TensorFlowNET.Console/MemoryLeakTesting.cs View File

@@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Text;
using static Tensorflow.Binding;

namespace Tensorflow
{
class MemoryLeakTesting
{
public void WarmUp()
{
print(tf.VERSION);
}

/// <summary>
///
/// </summary>
public void TensorCreation()
{
int total = 10 * 1000 * 1000;
for(int i = 0; i < total; i++)
{
var const1 = tf.constant(3112.0f);
// const1.Dispose();
}
}
}
}

+ 20
- 0
src/TensorFlowNET.Console/Program.cs View File

@@ -0,0 +1,20 @@
using System;

namespace Tensorflow
{
class Program
{
static void Main(string[] args)
{
// boot .net core 10.5M.
var memoryTest = new MemoryLeakTesting();
// warm up tensorflow.net 28.5M.
memoryTest.WarmUp();
// 1 million float tensor 34.5M.
memoryTest.TensorCreation();

Console.WriteLine("Finished.");
Console.ReadLine();
}
}
}

+ 14
- 0
src/TensorFlowNET.Console/TensorFlowNET.Console.csproj View File

@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RootNamespace>Tensorflow</RootNamespace>
<AssemblyName>Tensorflow</AssemblyName>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\TensorFlowNET.Core\Tensorflow.Binding.csproj" />
</ItemGroup>

</Project>

+ 48
- 0
src/TensorFlowNET.Core/Eager/EagerTensor.Creation.cs View File

@@ -0,0 +1,48 @@
using NumSharp;
using System;
using System.Collections.Generic;
using System.Text;
using static Tensorflow.Binding;

namespace Tensorflow.Eager
{
public partial class EagerTensor : Tensor
{
public EagerTensor(IntPtr handle) : base(handle)
{
EagerTensorHandle = handle;
tfe_tensor_handle = c_api.EagerTensor_Handle(handle);
_handle = c_api.TFE_TensorHandleResolve(tfe_tensor_handle, status);
}

public EagerTensor(int value, string device_name) : base(value)
{
tfe_tensor_handle = c_api.TFE_NewTensorHandle(_handle, status);
EagerTensorHandle = c_api.TFE_EagerTensorFromHandle(tf.context, tfe_tensor_handle);
}

public EagerTensor(long value, string device_name) : base(value)
{
tfe_tensor_handle = c_api.TFE_NewTensorHandle(_handle, status);
EagerTensorHandle = c_api.TFE_EagerTensorFromHandle(tf.context, tfe_tensor_handle);
}

public EagerTensor(float value, string device_name) : base(value)
{
tfe_tensor_handle = c_api.TFE_NewTensorHandle(_handle, status);
EagerTensorHandle = c_api.TFE_EagerTensorFromHandle(tf.context, tfe_tensor_handle);
}

public EagerTensor(string value, string device_name) : base(value)
{
tfe_tensor_handle = c_api.TFE_NewTensorHandle(_handle, status);
EagerTensorHandle = c_api.TFE_EagerTensorFromHandle(tf.context, tfe_tensor_handle);
}

public EagerTensor(NDArray value, string device_name) : base(value)
{
tfe_tensor_handle = c_api.TFE_NewTensorHandle(_handle, status);
EagerTensorHandle = c_api.TFE_EagerTensorFromHandle(tf.context, tfe_tensor_handle);
}
}
}

+ 0
- 3
src/TensorFlowNET.Core/Eager/EagerTensor.Implicit.cs View File

@@ -8,9 +8,6 @@ namespace Tensorflow.Eager
{
public partial class EagerTensor
{
public static explicit operator TFE_TensorHandle(EagerTensor tensor)
=> tensor.tfe_tensor_handle;

public static implicit operator IntPtr(EagerTensor tensor)
=> tensor.EagerTensorHandle;
}


+ 1
- 30
src/TensorFlowNET.Core/Eager/EagerTensor.cs View File

@@ -9,39 +9,10 @@ namespace Tensorflow.Eager
public partial class EagerTensor : Tensor
{
Status status = new Status();
TFE_TensorHandle tfe_tensor_handle;
IntPtr tfe_tensor_handle;
public IntPtr EagerTensorHandle { get; set; }
public override string Device => c_api.StringPiece(c_api.TFE_TensorHandleDeviceName(tfe_tensor_handle, status));

public EagerTensor(IntPtr handle) : base(handle)
{
EagerTensorHandle = handle;
tfe_tensor_handle = c_api.EagerTensor_Handle(handle);
_handle = c_api.TFE_TensorHandleResolve(tfe_tensor_handle, status);
}

public EagerTensor(TFE_TensorHandle handle) : base(handle)
{
tfe_tensor_handle = handle;
_handle = c_api.TFE_TensorHandleResolve(tfe_tensor_handle, status);
EagerTensorHandle = c_api.TFE_EagerTensorFromHandle(tf.context, tfe_tensor_handle);
}

public EagerTensor(string value, string device_name) : base(value)
{
tfe_tensor_handle = c_api.TFE_NewTensorHandle(_handle, status);
EagerTensorHandle = c_api.TFE_EagerTensorFromHandle(tf.context, tfe_tensor_handle);
}

public EagerTensor(NDArray value, string device_name) : base(value)
{
tfe_tensor_handle = c_api.TFE_NewTensorHandle(_handle, status);
EagerTensorHandle = c_api.TFE_EagerTensorFromHandle(tf.context, tfe_tensor_handle);
}

public IntPtr GetTfeTensorHandle()
=> tfe_tensor_handle;

public override string ToString()
{
switch (rank)


+ 0
- 26
src/TensorFlowNET.Core/Eager/EagerTensorHandle.cs View File

@@ -1,26 +0,0 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace Tensorflow.Eager
{
public struct EagerTensorHandle
{
IntPtr _handle;

public EagerTensorHandle(IntPtr handle)
=> _handle = handle;

public static implicit operator EagerTensorHandle(IntPtr handle)
=> new EagerTensorHandle(handle);

public static implicit operator IntPtr(EagerTensorHandle tensor)
=> tensor._handle;

public static implicit operator Tensor(EagerTensorHandle tensor)
=> new EagerTensor(tensor._handle);

public override string ToString()
=> $"EagerTensorHandle 0x{_handle.ToString("x16")}";
}
}

+ 9
- 17
src/TensorFlowNET.Core/Eager/Execute.cs View File

@@ -27,35 +27,27 @@ namespace Tensorflow.Eager
/// <param name="ctx">The value of context.context().</param>
/// <param name="name">Customized name for the operation.</param>
/// <returns>List of output Tensor objects. The list is empty if there are no outputs</returns>
public Tensor execute(Context ctx, string op_name, int num_outputs,
Tensor[] inputs, object[] attrs,
public EagerTensor[] execute(Context ctx, string op_name, int num_outputs,
EagerTensor[] inputs, object[] attrs,
string name = null)
{
ctx.ensure_initialized();

// TFE_TensorHandle
using var status = new Status();
/*var retVals = wrap_tfe_src.TFE_Execute(ctx, ctx.device_name, op_name, inputs, attrs, num_outputs, status);

return new EagerTensor((TFE_TensorHandle)retVals[0]);*/

IntPtr[] outputs = new IntPtr[num_outputs];
c_api.TFE_QuickExecute(ctx,
ctx.device_name,
BindingArray results = c_api.TFE_QuickExecute(ctx,
ctx.device_name,
op_name,
inputs.Select(x => (x as EagerTensor).GetTfeTensorHandle()).ToArray(),
inputs.Select(x => x.EagerTensorHandle).ToArray(),
inputs.Length,
op => wrap_tfe_src.SetOpAttrs(op, attrs),
outputs,
num_outputs,
status);
status.Check(true);

TFE_TensorHandle tfe_tensor_handle = outputs[0];
return new EagerTensor(tfe_tensor_handle);
return results.Data().Select(x => new EagerTensor(x)).ToArray();
}

public (TF_DataType, Tensor[]) args_to_matching_eager(Context ctx, TF_DataType default_dtype = TF_DataType.DtInvalid, object[] args = null)
public (TF_DataType, EagerTensor[]) args_to_matching_eager(Context ctx, TF_DataType default_dtype = TF_DataType.DtInvalid, object[] args = null)
{
if (args.Length == 0 && default_dtype != TF_DataType.DtInvalid)
return (default_dtype, null);
@@ -72,10 +64,10 @@ namespace Tensorflow.Eager

if (dtype == TF_DataType.DtInvalid)
{
var ret = new List<Tensor>();
var ret = new List<EagerTensor>();
foreach (var t in args)
{
ret.Add(ops.convert_to_tensor(t, dtype, preferred_dtype: default_dtype, ctx: ctx));
ret.Add(ops.convert_to_tensor(t, dtype, preferred_dtype: default_dtype, ctx: ctx) as EagerTensor);
if (dtype == TF_DataType.DtInvalid)
dtype = ret.Last().dtype;
}


+ 0
- 23
src/TensorFlowNET.Core/Eager/TFE_TensorHandle.cs View File

@@ -1,23 +0,0 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace Tensorflow.Eager
{
public struct TFE_TensorHandle
{
IntPtr _handle;

public TFE_TensorHandle(IntPtr handle)
=> _handle = handle;

public static implicit operator TFE_TensorHandle(IntPtr handle)
=> new TFE_TensorHandle(handle);

public static implicit operator IntPtr(TFE_TensorHandle tensor)
=> tensor._handle;

public override string ToString()
=> $"TFE_TensorHandle 0x{_handle.ToString("x16")}";
}
}

+ 29
- 10
src/TensorFlowNET.Core/Eager/c_api.eager.cs View File

@@ -8,16 +8,22 @@ namespace Tensorflow
public partial class c_api
{
[DllImport(TensorFlowLibName)]
public static extern void TFE_RegisterGradientFunction(_gradient_function_callback callbackPointer);
public static extern void TFE_RegisterGradientFunction(gradient_function_callback gradientFunctionCallback,
delete_backward_function_callback deleteBackwardFunctionCallback);

[UnmanagedFunctionPointer(CallingConvention.StdCall)]
public delegate IntPtr _gradient_function_callback(string op_name,
IntPtr op_inputs,
public delegate IntPtr gradient_function_callback(string op_name,
BindingArray op_inputs,
BindingArray op_outputs,
int num_attrs,
BindingArray output_grads,
BindingArray skip_input_indices);

[UnmanagedFunctionPointer(CallingConvention.StdCall)]
public delegate void delete_backward_function_callback(string op_name,
BindingArray op_inputs,
BindingArray op_outputs);

[DllImport(TensorFlowLibName)]
public static extern IntPtr TFE_WrapGradientResult(IntPtr[] gradients, int num_gradients);

@@ -26,7 +32,7 @@ namespace Tensorflow
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
public delegate IntPtr VSpace_callback_Ones(long[] shape, int dims, TF_DataType dtype);
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
public delegate IntPtr VSpace_callback_AggregateGrads(IntPtr gradients, int num_grads);
public delegate IntPtr VSpace_callback_AggregateGrads(BindingArray gradients);

[DllImport(TensorFlowLibName)]
public static extern void TFE_RegisterVSpace(IntPtr vspace);
@@ -208,13 +214,13 @@ namespace Tensorflow
/// <param name="t">const tensorflow::Tensor&</param>
/// <returns>TFE_TensorHandle*</returns>
[DllImport(TensorFlowLibName)]
public static extern TFE_TensorHandle TFE_NewTensorHandle(IntPtr t, IntPtr status);
public static extern IntPtr TFE_NewTensorHandle(IntPtr t, IntPtr status);

[DllImport(TensorFlowLibName)]
public static extern TFE_TensorHandle EagerTensor_Handle(IntPtr t);
public static extern IntPtr EagerTensor_Handle(IntPtr t);

[DllImport(TensorFlowLibName)]
public static extern TFE_TensorHandle TFE_EagerTensorFromHandle(IntPtr ctx, IntPtr h);
public static extern IntPtr TFE_EagerTensorFromHandle(IntPtr ctx, IntPtr h);

/// <summary>
/// Sets the default execution mode (sync/async). Note that this can be
@@ -242,7 +248,7 @@ namespace Tensorflow
/// <param name="status">TF_Status*</param>
/// <returns></returns>
[DllImport(TensorFlowLibName)]
public static extern TF_Tensor TFE_TensorHandleResolve(IntPtr h, IntPtr status);
public static extern IntPtr TFE_TensorHandleResolve(IntPtr h, IntPtr status);


/// <summary>
@@ -292,6 +298,13 @@ namespace Tensorflow
[DllImport(TensorFlowLibName)]
public static extern void TFE_DeleteTensorHandle(IntPtr h);

/// <summary>
///
/// </summary>
/// <param name="h">TFE_TensorHandle*</param>
[DllImport(TensorFlowLibName)]
public static extern void TFE_DeleteEagerTensor(IntPtr h);
/// <summary>
/// Creates a new eager Executor. Nodes in one executor are guaranteed to be
/// executed in sequence. Assigning nodes to different executors allows executing
@@ -370,9 +383,15 @@ namespace Tensorflow
public static extern IntPtr TFE_QuickExecute(IntPtr ctx,
string device_name,
string op_name,
IntPtr[] inputs, int input_size,
IntPtr[] inputs,
int input_size,
TFE_FastPathExecute_SetOpAttrs set_op_attrs,
IntPtr[] outputs, int output_size,
IntPtr status);

[DllImport(TensorFlowLibName)]
public static extern IntPtr TFE_QuickExecute1(
string op_name,
int input_size,
IntPtr status);

[DllImport(TensorFlowLibName)]


+ 13
- 6
src/TensorFlowNET.Core/Gradients/GradientTape.cs View File

@@ -94,15 +94,22 @@ namespace Tensorflow.Gradients
}

using var status = new Status();
IntPtr et = c_api.TFE_TapeGradient(_tape,
new IntPtr[] { target as EagerTensor }, 1,
new IntPtr[] { sources.Item1.Handle as EagerTensor, sources.Item2.Handle as EagerTensor }, 2,
BindingArray result_handle = c_api.TFE_TapeGradient(_tape,
new IntPtr[]
{
target as EagerTensor
}, 1,
new IntPtr[]
{
(sources.Item1.Handle as EagerTensor).EagerTensorHandle,
(sources.Item2.Handle as EagerTensor).EagerTensorHandle
}, 2,
status);
status.Check(true);

var results = new Tensor[2];
for (int i = 0; i < 2; i++)
results[i] = new EagerTensor(*((IntPtr*)et + i));
var results = result_handle.Data().Select(x => new EagerTensor(x)).ToArray();
if (!_persistent)
{
// Keep track of watched variables before setting tape to None


+ 5
- 6
src/TensorFlowNET.Core/Gradients/Tape.cs View File

@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using Tensorflow.Eager;
@@ -33,13 +34,11 @@ namespace Tensorflow.Gradients
public unsafe ResourceVariable[] watched_variables()
{
BindingArray result = c_api.TFE_TapeWatchedVariables(_handle);
var variables = new ResourceVariable[result.length];
for (int i = 0; i < result.length; i++)
var variables = result.Data().Select(x =>
{
var handle = *((IntPtr*)result.array + i);
var tensor = c_api.ResourceVariable_Handle(handle);
variables[i] = new ResourceVariable(handle, tensor);
}
var tensor = c_api.ResourceVariable_Handle(x);
return new ResourceVariable(x, tensor);
}).ToArray();

return variables;
}


+ 5
- 1
src/TensorFlowNET.Core/Gradients/math_grad.cs View File

@@ -513,7 +513,11 @@ namespace Tensorflow.Gradients
input_shape = array_ops.shape(op.inputs[0]);
return new Tensor[] { gen_array_ops.tile(grad, input_shape), null };
}
}
else
{

}
}
}

input_shape = array_ops.shape(op.inputs[0]);


+ 4
- 4
src/TensorFlowNET.Core/Operations/NnOps/gen_nn_ops.cs View File

@@ -468,13 +468,13 @@ namespace Tensorflow.Operations
if (tf.context.executing_eagerly())
{
using var status = new Status();
EagerTensorHandle tensor = c_api.TFE_FastPathExecute(tf.context, tf.context.device_name,
BindingArray results = c_api.TFE_FastPathExecute(tf.context, tf.context.device_name,
"Relu", name, new IntPtr[]
{
features as EagerTensor,
}, 1, null, status);
status.Check(true);
return tensor;
return new EagerTensor(results[0]);
}

var _op = _op_def_lib._apply_op_helper("Relu", name: name, args: new { features });
@@ -486,13 +486,13 @@ namespace Tensorflow.Operations
if (tf.context.executing_eagerly())
{
using var status = new Status();
var tensor = c_api.TFE_FastPathExecute(tf.context, tf.context.device_name,
BindingArray results = c_api.TFE_FastPathExecute(tf.context, tf.context.device_name,
"Tanh", name, new IntPtr[]
{
x as EagerTensor,
}, 1, null, status);
status.Check(true);
return new EagerTensor(tensor);
return new EagerTensor(results[0]);
}

var _op = _op_def_lib._apply_op_helper("Tanh", name: name, args: new { x });


+ 20
- 20
src/TensorFlowNET.Core/Operations/gen_array_ops.cs View File

@@ -55,14 +55,14 @@ namespace Tensorflow
if (tf.context.executing_eagerly())
{
using var status = new Status();
EagerTensorHandle tensor = c_api.TFE_FastPathExecute(tf.context, tf.context.device_name,
BindingArray results = c_api.TFE_FastPathExecute(tf.context, tf.context.device_name,
"ConcatV2", name, new IntPtr[]
{
values as EagerTensor,
axis as EagerTensor
}, 2, null, status);
status.Check(true);
return tensor;
return new EagerTensor(results[0]);
}

var _op = _op_def_lib._apply_op_helper("ConcatV2", name: name, args: new { values, axis });
@@ -88,7 +88,7 @@ namespace Tensorflow
var _inputs_flat = input.concat(axis1);
var _attrs = new object[] { "N", _attr_N, "T", _attr_T, "Tidx", _attr_Tidx };

return _execute.execute(ctx, "ConcatV2", 1, _inputs_flat, _attrs, name: name);
return _execute.execute(ctx, "ConcatV2", 1, _inputs_flat, _attrs, name: name)[0];
}

public static Tensor[] concat_offset(Tensor concat_dim, Tensor[] shape, string name = null)
@@ -162,13 +162,13 @@ namespace Tensorflow
if(tf.context.executing_eagerly())
{
using var status = new Status();
var tensor = c_api.TFE_FastPathExecute(tf.context, tf.context.device_name,
BindingArray results = c_api.TFE_FastPathExecute(tf.context, tf.context.device_name,
"Pack", name,
values.Select(x => (x as EagerTensor).EagerTensorHandle).ToArray(), values.Length,
op => wrap_tfe_src.SetOpAttrs(op, "axis", axis),
status);
status.Check(true);
return new EagerTensor(tensor);
return new EagerTensor(results[0]);
}

var _op = _op_def_lib._apply_op_helper("Pack", name: name, args: new { values, axis });
@@ -230,13 +230,13 @@ namespace Tensorflow
if (tf.context.executing_eagerly())
{
using var status = new Status();
EagerTensorHandle tensor = c_api.TFE_FastPathExecute(tf.context, tf.context.device_name,
BindingArray results = c_api.TFE_FastPathExecute(tf.context, tf.context.device_name,
"Identity", name, new IntPtr[]
{
input as EagerTensor
}, 1, null, status);
status.Check(true);
return tensor;
return new EagerTensor(results[0]);
}

var _op = _op_def_lib._apply_op_helper("Identity", name, new { input });
@@ -277,14 +277,14 @@ namespace Tensorflow
if (tf.context.executing_eagerly())
{
using var status = new Status();
EagerTensorHandle tensor = c_api.TFE_FastPathExecute(tf.context, tf.context.device_name,
BindingArray results = c_api.TFE_FastPathExecute(tf.context, tf.context.device_name,
"Fill", name, new IntPtr[]
{
dims as EagerTensor,
value as EagerTensor
}, 2, null, status);
status.Check(true);
return tensor;
return new EagerTensor(results[0]);
}

var _op = _op_def_lib._apply_op_helper("Fill", name, new { dims, value });
@@ -298,19 +298,19 @@ namespace Tensorflow
/// <param name="s1">A `Tensor`. Must have the same type as `s0`.</param>
/// <param name="name">A name for the operation (optional).</param>
/// <returns>A tuple of `Tensor` objects (r0, r1).</returns>
public unsafe static (Tensor, Tensor) broadcast_gradient_args(Tensor s0, Tensor s1, string name = "")
public static (Tensor, Tensor) broadcast_gradient_args(Tensor s0, Tensor s1, string name = "")
{
if (tf.context.executing_eagerly())
{
using var status = new Status();
var _result = c_api.TFE_FastPathExecute(tf.context, tf.context.device_name,
BindingArray results = c_api.TFE_FastPathExecute(tf.context, tf.context.device_name,
"BroadcastGradientArgs", name, new IntPtr[]
{
s0 as EagerTensor,
s1 as EagerTensor
}, 2, null, status);
status.Check(true);
return (new EagerTensor(*(IntPtr*)_result), new EagerTensor(*((IntPtr*)_result + 1)));
return (new EagerTensor(results[0]), new EagerTensor(results[1]));
}

var _op = _op_def_lib._apply_op_helper("BroadcastGradientArgs", name, new { s0, s1 });
@@ -329,14 +329,14 @@ namespace Tensorflow
if (tf.context.executing_eagerly())
{
using var status = new Status();
EagerTensorHandle _result = c_api.TFE_FastPathExecute(tf.context, tf.context.device_name,
BindingArray results = c_api.TFE_FastPathExecute(tf.context, tf.context.device_name,
"Reshape", name, new IntPtr[]
{
tensor as EagerTensor,
shape as EagerTensor
}, 2, null, status);
status.Check(true);
return _result;
return new EagerTensor(results[0]);
}

var _op = _op_def_lib._apply_op_helper("Reshape", name, new { tensor, shape });
@@ -417,7 +417,7 @@ namespace Tensorflow
if (tf.context.executing_eagerly())
{
using var status = new Status();
EagerTensorHandle tensor = c_api.TFE_FastPathExecute(tf.context, tf.context.device_name,
BindingArray results = c_api.TFE_FastPathExecute(tf.context, tf.context.device_name,
"Shape", name, new IntPtr[]
{
input as EagerTensor,
@@ -425,7 +425,7 @@ namespace Tensorflow
op => wrap_tfe_src.SetOpAttrs(op, "out_type", out_type),
status);
status.Check(true);
return tensor;
return new EagerTensor(results[0]);
}

var _op = _op_def_lib._apply_op_helper("Shape", name, new { input, out_type });
@@ -476,14 +476,14 @@ namespace Tensorflow
if (tf.context.executing_eagerly())
{
using var status = new Status();
EagerTensorHandle tensor = c_api.TFE_FastPathExecute(tf.context, tf.context.device_name,
BindingArray results = c_api.TFE_FastPathExecute(tf.context, tf.context.device_name,
"Tile", name, new IntPtr[]
{
input as EagerTensor,
multiples as EagerTensor
}, 2, null, status);
status.Check(true);
return tensor;
return new EagerTensor(results[0]);
}

var _op = _op_def_lib._apply_op_helper("Tile", name, new { input, multiples });
@@ -520,7 +520,7 @@ namespace Tensorflow
if (tf.context.executing_eagerly())
{
using var status = new Status();
EagerTensorHandle tensor = c_api.TFE_FastPathExecute(tf.context, tf.context.device_name,
BindingArray results = c_api.TFE_FastPathExecute(tf.context, tf.context.device_name,
"StridedSlice", name, new IntPtr[]
{
input as EagerTensor,
@@ -536,7 +536,7 @@ namespace Tensorflow
"shrink_axis_mask", shrink_axis_mask),
status);
status.Check(true);
return tensor;
return new EagerTensor(results[0]);
}

var _op = _op_def_lib._apply_op_helper("StridedSlice", name, new


+ 59
- 59
src/TensorFlowNET.Core/Operations/gen_math_ops.cs View File

@@ -44,13 +44,13 @@ namespace Tensorflow
if (tf.context.executing_eagerly())
{
using var status = new Status();
EagerTensorHandle _result = c_api.TFE_FastPathExecute(tf.context, tf.context.device_name,
BindingArray results = c_api.TFE_FastPathExecute(tf.context, tf.context.device_name,
"AddN", name,
inputs.Select(x => (x as EagerTensor).EagerTensorHandle).ToArray(), inputs.Length,
null,
status);
status.Check(true);
return _result;
return new EagerTensor(results[0]);
}

var _op = _op_def_lib._apply_op_helper("AddN", name, args: new { inputs });
@@ -132,7 +132,7 @@ namespace Tensorflow
if (tf.context.executing_eagerly())
{
using var status = new Status();
EagerTensorHandle tensor = c_api.TFE_FastPathExecute(tf.context, tf.context.device_name,
BindingArray results = c_api.TFE_FastPathExecute(tf.context, tf.context.device_name,
"Mean", name,
new IntPtr[]
{
@@ -142,7 +142,7 @@ namespace Tensorflow
op => wrap_tfe_src.SetOpAttrs(op, "keep_dims", keep_dims),
status);
status.Check(true);
return tensor;
return new EagerTensor(results[0]);
}

var _op = _op_def_lib._apply_op_helper("Mean", name, args: new { input, reduction_indices = axis, keep_dims = keep_dims });
@@ -169,7 +169,7 @@ namespace Tensorflow
var _inputs_flat = input.concat(axis1);
var _attrs = new object[] { "keep_dims", keep_dims, "T", _attr_T, "Tidx", _attr_Tidx };

return _execute.execute(ctx, "Mean", 1, _inputs_flat, _attrs, name: name);
return _execute.execute(ctx, "Mean", 1, _inputs_flat, _attrs, name: name)[0];
}

public static Tensor prod<T1, T2>(T1 input, T2 axis, bool keep_dims = false, string name = null)
@@ -179,7 +179,7 @@ namespace Tensorflow
try
{
using var status = new Status();
EagerTensorHandle tensor = c_api.TFE_FastPathExecute(tf.context, tf.context.device_name,
BindingArray results = c_api.TFE_FastPathExecute(tf.context, tf.context.device_name,
"Prod", name, new IntPtr[]
{
input as EagerTensor,
@@ -188,7 +188,7 @@ namespace Tensorflow
op => wrap_tfe_src.SetOpAttrs(op, "keep_dims", keep_dims),
status);
status.Check(true);
return tensor;
return new EagerTensor(results[0]);
}
catch (Exception)
{
@@ -207,7 +207,7 @@ namespace Tensorflow
var _inputs_flat = input.concat(axis1);
var _attrs = new object[] { "keep_dims", keep_dims, "T", _attr_T, "Tidx", _attr_Tidx };

return _execute.execute(ctx, "Prod", 1, _inputs_flat, _attrs, name: name);
return _execute.execute(ctx, "Prod", 1, _inputs_flat, _attrs, name: name)[0];
}

public static Tensor acos(Tensor x, string name = null)
@@ -229,14 +229,14 @@ namespace Tensorflow
if (tf.context.executing_eagerly())
{
using var status = new Status();
EagerTensorHandle _result = c_api.TFE_FastPathExecute(tf.context, tf.context.device_name,
BindingArray results = c_api.TFE_FastPathExecute(tf.context, tf.context.device_name,
"Add", name, new IntPtr[]
{
x as EagerTensor,
y as EagerTensor
}, 2, null, status);
status.Check(true);
return _result;
return new EagerTensor(results[0]);
}

var _op = _op_def_lib._apply_op_helper("Add", name, args: new { x, y });
@@ -249,14 +249,14 @@ namespace Tensorflow
if (tf.context.executing_eagerly())
{
using var status = new Status();
EagerTensorHandle tensor = c_api.TFE_FastPathExecute(tf.context, tf.context.device_name,
BindingArray results = c_api.TFE_FastPathExecute(tf.context, tf.context.device_name,
"Add", name, new IntPtr[]
{
x as EagerTensor,
y as EagerTensor
}, 2, null, status);
status.Check(true);
return tensor;
return new EagerTensor(results[0]);
}

var _op = _op_def_lib._apply_op_helper("Add", name, args: new { x, y });
@@ -270,14 +270,14 @@ namespace Tensorflow
if (tf.context.executing_eagerly())
{
using var status = new Status();
EagerTensorHandle tensor = c_api.TFE_FastPathExecute(tf.context, tf.context.device_name,
BindingArray results = c_api.TFE_FastPathExecute(tf.context, tf.context.device_name,
"AddV2", name, new IntPtr[]
{
x as EagerTensor,
y as EagerTensor
}, 2, null, status);
status.Check(true);
return tensor;
return new EagerTensor(results[0]);
}

var _op = _op_def_lib._apply_op_helper("AddV2", name, args: new { x, y });
@@ -304,13 +304,13 @@ namespace Tensorflow
if (tf.context.executing_eagerly())
{
using var status = new Status();
EagerTensorHandle tensor = c_api.TFE_FastPathExecute(tf.context, tf.context.device_name,
BindingArray results = c_api.TFE_FastPathExecute(tf.context, tf.context.device_name,
"Sin", name, new IntPtr[]
{
x as EagerTensor,
}, 1, null, status);
status.Check(true);
return tensor;
return new EagerTensor(results[0]);
}

var _op = _op_def_lib._apply_op_helper("Sin", name, args: new { x });
@@ -337,13 +337,13 @@ namespace Tensorflow
if (tf.context.executing_eagerly())
{
using var status = new Status();
EagerTensorHandle tensor = c_api.TFE_FastPathExecute(tf.context, tf.context.device_name,
BindingArray results = c_api.TFE_FastPathExecute(tf.context, tf.context.device_name,
"Sigmoid", name, new IntPtr[]
{
x as EagerTensor,
}, 1, null, status);
status.Check(true);
return tensor;
return new EagerTensor(results[0]);
}

var op = _op_def_lib._apply_op_helper("Sigmoid", name: name, new { x });
@@ -429,13 +429,13 @@ namespace Tensorflow
if (tf.context.executing_eagerly())
{
using var status = new Status();
EagerTensorHandle tensor = c_api.TFE_FastPathExecute(tf.context, tf.context.device_name,
BindingArray results = c_api.TFE_FastPathExecute(tf.context, tf.context.device_name,
"Tan", name, new IntPtr[]
{
x as EagerTensor,
}, 1, null, status);
status.Check(true);
return tensor;
return new EagerTensor(results[0]);
}

var _op = _op_def_lib._apply_op_helper("Tan", name, args: new { x });
@@ -511,14 +511,14 @@ namespace Tensorflow
if (tf.context.executing_eagerly())
{
using var status = new Status();
EagerTensorHandle tensor = c_api.TFE_FastPathExecute(tf.context, tf.context.device_name,
BindingArray results = c_api.TFE_FastPathExecute(tf.context, tf.context.device_name,
"Less", name, new IntPtr[]
{
x as EagerTensor,
y as EagerTensor
}, 2, null, status);
status.Check(true);
return tensor;
return new EagerTensor(results[0]);
}

var _op = _op_def_lib._apply_op_helper("Less", name: name, args: new { x, y });
@@ -587,13 +587,13 @@ namespace Tensorflow
if (tf.context.executing_eagerly())
{
using var status = new Status();
EagerTensorHandle tensor = c_api.TFE_FastPathExecute(tf.context, tf.context.device_name,
BindingArray results = c_api.TFE_FastPathExecute(tf.context, tf.context.device_name,
"Square", name, new IntPtr[]
{
x as EagerTensor,
}, 1, null, status);
status.Check(true);
return tensor;
return new EagerTensor(results[0]);
}

var _op = _op_def_lib._apply_op_helper("Square", name, args: new { x });
@@ -652,13 +652,13 @@ namespace Tensorflow
if (tf.context.executing_eagerly())
{
using var status = new Status();
var tensor = c_api.TFE_FastPathExecute(tf.context, tf.context.device_name,
BindingArray results = c_api.TFE_FastPathExecute(tf.context, tf.context.device_name,
"Cast", name,
new IntPtr[] { x as EagerTensor }, 1,
op => wrap_tfe_src.SetOpAttrs(op, "DstT", DstT, "Truncate", Truncate),
status);
status.Check(true);
return new EagerTensor(tensor);
return new EagerTensor(results[0]);
}

var _op = _op_def_lib._apply_op_helper("Cast", name, args: new { x, DstT, Truncate });
@@ -671,13 +671,13 @@ namespace Tensorflow
if (tf.context.executing_eagerly())
{
using var status = new Status();
var tensor = c_api.TFE_FastPathExecute(tf.context, tf.context.device_name,
BindingArray results = c_api.TFE_FastPathExecute(tf.context, tf.context.device_name,
"Neg", name, new IntPtr[]
{
x as EagerTensor
}, 2, null, status);
status.Check(true);
return new EagerTensor(tensor);
return new EagerTensor(results[0]);
}

var _op = _op_def_lib._apply_op_helper("Neg", name, args: new { x });
@@ -690,13 +690,13 @@ namespace Tensorflow
if (tf.context.executing_eagerly())
{
using var status = new Status();
EagerTensorHandle tensor = c_api.TFE_FastPathExecute(tf.context, tf.context.device_name,
BindingArray results = c_api.TFE_FastPathExecute(tf.context, tf.context.device_name,
"Sqrt", name, new IntPtr[]
{
x as EagerTensor,
}, 1, null, status);
status.Check(true);
return tensor;
return new EagerTensor(results[0]);
}

var _op = _op_def_lib._apply_op_helper("Sqrt", name, args: new { x });
@@ -709,14 +709,14 @@ namespace Tensorflow
if (tf.context.executing_eagerly())
{
using var status = new Status();
var _result = c_api.TFE_FastPathExecute(tf.context, tf.context.device_name,
BindingArray results = c_api.TFE_FastPathExecute(tf.context, tf.context.device_name,
"Sub", name, new IntPtr[]
{
x as EagerTensor,
y as EagerTensor
}, 2, null, status);
status.Check(true);
return new EagerTensor(_result);
return new EagerTensor(results[0]);
}

var _op = _op_def_lib._apply_op_helper("Sub", name, args: new { x, y });
@@ -729,14 +729,14 @@ namespace Tensorflow
if (tf.context.executing_eagerly())
{
using var status = new Status();
EagerTensorHandle tensor = c_api.TFE_FastPathExecute(tf.context, tf.context.device_name,
BindingArray results = c_api.TFE_FastPathExecute(tf.context, tf.context.device_name,
"Sub", name, new IntPtr[]
{
x as EagerTensor,
y as EagerTensor
}, 2, null, status);
status.Check(true);
return tensor;
return new EagerTensor(results[0]);
}

var _op = _op_def_lib._apply_op_helper("Sub", name, args: new { x, y });
@@ -756,14 +756,14 @@ namespace Tensorflow
if (tf.context.executing_eagerly())
{
using var status = new Status();
EagerTensorHandle tensor = c_api.TFE_FastPathExecute(tf.context, tf.context.device_name,
BindingArray results = c_api.TFE_FastPathExecute(tf.context, tf.context.device_name,
"Equal", name, new IntPtr[]
{
x as EagerTensor,
y as EagerTensor
}, 2, null, status);
status.Check(true);
return tensor;
return new EagerTensor(results[0]);
}

var _op = _op_def_lib._apply_op_helper("Equal", name, args: new { x, y });
@@ -784,14 +784,14 @@ namespace Tensorflow
if (tf.context.executing_eagerly())
{
using var status = new Status();
EagerTensorHandle tensor = c_api.TFE_FastPathExecute(tf.context, tf.context.device_name,
BindingArray results = c_api.TFE_FastPathExecute(tf.context, tf.context.device_name,
"NotEqual", name, new IntPtr[]
{
x as EagerTensor,
y as EagerTensor
}, 2, null, status);
status.Check(true);
return tensor;
return new EagerTensor(results[0]);
}

var _op = _op_def_lib._apply_op_helper("NotEqual", name, args: new { x, y });
@@ -804,14 +804,14 @@ namespace Tensorflow
if (tf.context.executing_eagerly())
{
using var status = new Status();
EagerTensorHandle tensor = c_api.TFE_FastPathExecute(tf.context, tf.context.device_name,
BindingArray results = c_api.TFE_FastPathExecute(tf.context, tf.context.device_name,
"Atan2", name, new IntPtr[]
{
y as EagerTensor,
x as EagerTensor
}, 2, null, status);
status.Check(true);
return tensor;
return new EagerTensor(results[0]);
}

var _op = _op_def_lib._apply_op_helper("Atan2", name, args: new { y, x });
@@ -823,14 +823,14 @@ namespace Tensorflow
if (tf.context.executing_eagerly())
{
using var status = new Status();
EagerTensorHandle tensor = c_api.TFE_FastPathExecute(tf.context, tf.context.device_name,
BindingArray results = c_api.TFE_FastPathExecute(tf.context, tf.context.device_name,
"Mul", name, new IntPtr[]
{
x as EagerTensor,
y as EagerTensor
}, 2, null, status);
status.Check(true);
return tensor;
return new EagerTensor(results[0]);
}

var _op = _op_def_lib._apply_op_helper("Mul", name, args: new { x, y });
@@ -843,14 +843,14 @@ namespace Tensorflow
if (tf.context.executing_eagerly())
{
using var status = new Status();
EagerTensorHandle tensor = c_api.TFE_FastPathExecute(tf.context, tf.context.device_name,
BindingArray results = c_api.TFE_FastPathExecute(tf.context, tf.context.device_name,
"Mul", name, new IntPtr[]
{
x as EagerTensor,
y as EagerTensor,
}, 2, null, status);
status.Check(true);
return tensor;
return new EagerTensor(results[0]);
}

var _op = _op_def_lib._apply_op_helper("Mul", name, args: new { x, y });
@@ -870,14 +870,14 @@ namespace Tensorflow
if (tf.context.executing_eagerly())
{
using var status = new Status();
EagerTensorHandle tensor = c_api.TFE_FastPathExecute(tf.context, tf.context.device_name,
BindingArray results = c_api.TFE_FastPathExecute(tf.context, tf.context.device_name,
"RealDiv", name, new IntPtr[]
{
x as EagerTensor,
y as EagerTensor
}, 2, null, status);
status.Check(true);
return tensor;
return new EagerTensor(results[0]);
}

var _op = _op_def_lib._apply_op_helper("RealDiv", name, args: new { x, y });
@@ -897,14 +897,14 @@ namespace Tensorflow
if (tf.context.executing_eagerly())
{
using var status = new Status();
EagerTensorHandle tensor = c_api.TFE_FastPathExecute(tf.context, tf.context.device_name,
BindingArray results = c_api.TFE_FastPathExecute(tf.context, tf.context.device_name,
"FloorMod", name, new IntPtr[]
{
x as EagerTensor,
y as EagerTensor
}, 2, null, status);
status.Check(true);
return tensor;
return new EagerTensor(results[0]);
}

var _op = _op_def_lib._apply_op_helper("FloorMod", name, args: new { x, y });
@@ -917,14 +917,14 @@ namespace Tensorflow
if (tf.context.executing_eagerly())
{
using var status = new Status();
EagerTensorHandle tensor = c_api.TFE_FastPathExecute(tf.context, tf.context.device_name,
BindingArray results = c_api.TFE_FastPathExecute(tf.context, tf.context.device_name,
"FloorDiv", name, new IntPtr[]
{
x as EagerTensor,
y as EagerTensor
}, 2, null, status);
status.Check(true);
return tensor;
return new EagerTensor(results[0]);
}

var _op = _op_def_lib._apply_op_helper("FloorDiv", name, args: new { x, y });
@@ -946,7 +946,7 @@ namespace Tensorflow
if (tf.context.executing_eagerly())
{
using var status = new Status();
var tensor = c_api.TFE_FastPathExecute(tf.context, tf.context.device_name,
BindingArray results = c_api.TFE_FastPathExecute(tf.context, tf.context.device_name,
"MatMul", name,
new IntPtr[]
{
@@ -958,7 +958,7 @@ namespace Tensorflow
"transpose_b", transpose_b),
status);
status.Check(true);
return new EagerTensor(tensor);
return new EagerTensor(results[0]);
}

var _op = _op_def_lib._apply_op_helper("MatMul", name, args: new { a, b, transpose_a, transpose_b });
@@ -1055,14 +1055,14 @@ namespace Tensorflow
if (tf.context.executing_eagerly())
{
using var status = new Status();
EagerTensorHandle tensor = c_api.TFE_FastPathExecute(tf.context, tf.context.device_name,
BindingArray results = c_api.TFE_FastPathExecute(tf.context, tf.context.device_name,
"Pow", name, new IntPtr[]
{
x as EagerTensor,
y as EagerTensor
}, 2, null, status);
status.Check(true);
return tensor;
return new EagerTensor(results[0]);
}

var _op = _op_def_lib._apply_op_helper("Pow", name, args: new { x, y });
@@ -1075,7 +1075,7 @@ namespace Tensorflow
if (tf.context.executing_eagerly())
{
using var status = new Status();
var tensor = c_api.TFE_FastPathExecute(tf.context, tf.context.device_name,
BindingArray results = c_api.TFE_FastPathExecute(tf.context, tf.context.device_name,
"Sum", name,
new IntPtr[]
{
@@ -1085,7 +1085,7 @@ namespace Tensorflow
op => wrap_tfe_src.SetOpAttrs(op, "keep_dims", keep_dims),
status);
status.Check(true);
return new EagerTensor(tensor);
return new EagerTensor(results[0]);
}

var _op = _op_def_lib._apply_op_helper("Sum", name, args: new { input, reduction_indices = axis, keep_dims });
@@ -1113,7 +1113,7 @@ namespace Tensorflow
var _inputs_flat = input.concat(axis1);
var _attrs = new object[] { "keep_dims", keep_dims, "T", _attr_T, "Tidx", _attr_Tidx };

return _execute.execute(ctx, "Sum", 1, _inputs_flat, _attrs, name: name);
return _execute.execute(ctx, "Sum", 1, _inputs_flat, _attrs, name: name)[0];
}

/// <summary>
@@ -1129,7 +1129,7 @@ namespace Tensorflow
if (tf.context.executing_eagerly())
{
using var status = new Status();
var tensor = c_api.TFE_FastPathExecute(tf.context, tf.context.device_name,
BindingArray results = c_api.TFE_FastPathExecute(tf.context, tf.context.device_name,
"Range", name, new IntPtr[]
{
start as EagerTensor,
@@ -1137,7 +1137,7 @@ namespace Tensorflow
delta as EagerTensor
}, 3, null, status);
status.Check(true);
return new EagerTensor(tensor);
return new EagerTensor(results[0]);
}

var _op = _op_def_lib._apply_op_helper("Range", name, new { start, limit, delta });


+ 2
- 2
src/TensorFlowNET.Core/Operations/gen_random_ops.cs View File

@@ -42,7 +42,7 @@ namespace Tensorflow
if (tf.context.executing_eagerly())
{
using var status = new Status();
EagerTensorHandle tensor = c_api.TFE_FastPathExecute(tf.context, tf.context.device_name,
BindingArray results = c_api.TFE_FastPathExecute(tf.context, tf.context.device_name,
"RandomStandardNormal", name, new IntPtr[]
{
shape as EagerTensor,
@@ -53,7 +53,7 @@ namespace Tensorflow
"dtype", dtype),
status);
status.Check(true);
return tensor;
return new EagerTensor(results[0]);
}

var _op = _op_def_lib._apply_op_helper("RandomStandardNormal",


+ 13
- 13
src/TensorFlowNET.Core/Operations/gen_resource_variable_ops.cs View File

@@ -30,7 +30,7 @@ namespace Tensorflow
if (tf.context.executing_eagerly())
{
using var status = new Status();
var tensor = c_api.TFE_FastPathExecute(tf.context, tf.context.device_name,
BindingArray results = c_api.TFE_FastPathExecute(tf.context, tf.context.device_name,
"AssignSubVariableOp", name,
new IntPtr[]
{
@@ -38,7 +38,7 @@ namespace Tensorflow
value as EagerTensor
}, 2, null, status);
status.Check(true);
return tensor;
return results[0];
}

return null;
@@ -56,7 +56,7 @@ namespace Tensorflow
if (tf.context.executing_eagerly())
{
using var status = new Status();
var tensor = c_api.TFE_FastPathExecute(tf.context, tf.context.device_name,
BindingArray results = c_api.TFE_FastPathExecute(tf.context, tf.context.device_name,
"AssignAddVariableOp", name,
new IntPtr[]
{
@@ -64,7 +64,7 @@ namespace Tensorflow
value as EagerTensor
}, 2, null, status);
status.Check(true);
return tensor;
return results[0];
}

return null;
@@ -75,7 +75,7 @@ namespace Tensorflow
if (tf.context.executing_eagerly())
{
using var status = new Status();
var tensor = c_api.TFE_FastPathExecute(tf.context, tf.context.device_name,
var results = c_api.TFE_FastPathExecute(tf.context, tf.context.device_name,
"AssignVariableOp", name,
new IntPtr[]
{
@@ -83,7 +83,7 @@ namespace Tensorflow
value as EagerTensor
}, 2, null, status);
status.Check(true);
return tensor;
return null;
}

var _op = _op_def_lib._apply_op_helper("AssignVariableOp", name, new { resource, value });
@@ -96,12 +96,12 @@ namespace Tensorflow
if (tf.context.executing_eagerly())
{
using var status = new Status();
EagerTensorHandle tensor = c_api.TFE_FastPathExecute(tf.context, tf.context.device_name,
BindingArray results = c_api.TFE_FastPathExecute(tf.context, tf.context.device_name,
"VarIsInitializedOp", name,
new IntPtr[] { resource as EagerTensor },
1, null, status);
status.Check(true);
return tensor;
return new EagerTensor(results[0]);
}

var _op = _op_def_lib._apply_op_helper("VarIsInitializedOp", name, new { resource });
@@ -121,10 +121,10 @@ namespace Tensorflow
public static Tensor var_handle_op(TF_DataType dtype, TensorShape shape,
string container ="", string shared_name = "", string name = null)
{
if (tf.context.executing_eagerly())
if(tf.context.executing_eagerly())
{
using var status = new Status();
EagerTensorHandle tensor = c_api.TFE_FastPathExecute(tf.context, tf.context.device_name,
BindingArray results = c_api.TFE_FastPathExecute(tf.context, tf.context.device_name,
"VarHandleOp", name, null, 0,
op => wrap_tfe_src.SetOpAttrs(op,
"container", container,
@@ -133,7 +133,7 @@ namespace Tensorflow
"shape", shape.dims),
status);
status.Check(true);
return tensor;
return new EagerTensor(results[0]);
}

var _op = _op_def_lib._apply_op_helper("VarHandleOp", name, new {
@@ -158,13 +158,13 @@ namespace Tensorflow
if (tf.context.executing_eagerly())
{
using var status = new Status();
EagerTensorHandle tensor = c_api.TFE_FastPathExecute(tf.context, tf.context.device_name,
BindingArray results = c_api.TFE_FastPathExecute(tf.context, tf.context.device_name,
"ReadVariableOp", name,
new IntPtr[] { resource as EagerTensor }, 1,
op => wrap_tfe_src.SetOpAttrs(op, "dtype", dtype),
status);
status.Check(true);
return tensor;
return new EagerTensor(results[0]);
}

var _op = _op_def_lib._apply_op_helper("ReadVariableOp", name, new


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

@@ -17,6 +17,6 @@ namespace Tensorflow
=> tensor._handle;

public override string ToString()
=> $"TF_Tensor {_handle}";
=> $"TF_Tensor 0x{_handle.ToString("x16")}";
}
}

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

@@ -159,7 +159,7 @@ namespace Tensorflow
switch (dtype)
{
case TF_DataType.TF_STRING:
return StringData();
return (NDArray)StringData()[0];
case TF_DataType.TF_INT32:
storage = new UnmanagedStorage(NPTypeCode.Int32);
break;


+ 2
- 2
src/TensorFlowNET.Core/Tensors/constant_op.cs View File

@@ -101,14 +101,14 @@ namespace Tensorflow
return op.outputs[0];
}

private static Tensor _eager_fill(int[] dims, Tensor value, Context ctx)
private static Tensor _eager_fill(int[] dims, EagerTensor value, Context ctx)
{
var attr_t = value.dtype.as_datatype_enum();
var dims_t = convert_to_eager_tensor(dims, ctx, dtypes.int32);
var inputs_flat = new[] { dims_t, value };
var attrs = new object[] { "T", attr_t, "index_type", TF_DataType.TF_INT32 };
var result = _execute.execute(ctx, "Fill", 1, inputs_flat, attrs);
return result;
return result[0];
}

private static EagerTensor convert_to_eager_tensor(object value, Context ctx, TF_DataType dtype = TF_DataType.DtInvalid)


+ 2
- 2
src/TensorFlowNET.Core/Training/gen_training_ops.py.cs View File

@@ -65,7 +65,7 @@ namespace Tensorflow
if (tf.context.executing_eagerly())
{
using var status = new Status();
var tensor = c_api.TFE_FastPathExecute(tf.context, tf.context.device_name,
BindingArray results = c_api.TFE_FastPathExecute(tf.context, tf.context.device_name,
"ResourceApplyGradientDescent", name, new IntPtr[]
{
var,
@@ -75,7 +75,7 @@ namespace Tensorflow
op => wrap_tfe_src.SetOpAttrs(op, "use_locking", use_locking),
status);
status.Check(true);
return tensor;
return results[0];
}

var _op = _op_def_lib._apply_op_helper("ResourceApplyGradientDescent", name, new


+ 12
- 1
src/TensorFlowNET.Core/Util/BindingArray.cs View File

@@ -26,6 +26,17 @@ namespace Tensorflow
public int length;

public static implicit operator BindingArray(IntPtr handle)
=> Marshal.PtrToStructure<BindingArray>(handle);
=> handle == IntPtr.Zero ? default : Marshal.PtrToStructure<BindingArray>(handle);

public unsafe IntPtr this[int index]
=> array == IntPtr.Zero ? IntPtr.Zero : * ((IntPtr*)array + index);

public unsafe IntPtr[] Data()
{
var results = new IntPtr[length];
for (int i = 0; i < length; i++)
results[i] = array == IntPtr.Zero ? IntPtr.Zero : * ((IntPtr*)array + i);
return results;
}
}
}

+ 1
- 0
src/TensorFlowNET.Core/Variables/BaseResourceVariable.cs View File

@@ -129,6 +129,7 @@ namespace Tensorflow
protected override void DisposeUnmanagedResources(IntPtr handle)
{
// delete
// c_api.TFE_DeleteResourceVariable(handle);
}
}
}

+ 6
- 0
src/TensorFlowNET.Core/Variables/ResourceVariable.cs View File

@@ -239,5 +239,11 @@ namespace Tensorflow
{
return $"tf.Variable: '{Name}' shape={string.Join(",", shape)}, dtype={dtype.as_numpy_name()}, numpy={EagerTensor.GetFormattedString(dtype, numpy())}";
}

protected override void DisposeUnmanagedResources(IntPtr handle)
{
// delete
// c_api.TFE_DeleteResourceVariable(handle);
}
}
}

+ 3
- 0
src/TensorFlowNET.Core/Variables/c_api.variable.cs View File

@@ -10,6 +10,9 @@ namespace Tensorflow
[DllImport(TensorFlowLibName)]
public static extern IntPtr TFE_NewResourceVariable();

[DllImport(TensorFlowLibName)]
public static extern void TFE_DeleteResourceVariable(IntPtr variable);

[DllImport(TensorFlowLibName)]
public static extern void TFE_SetResourceVariableHandle(IntPtr variable, IntPtr tensor);



+ 9
- 26
src/TensorFlowNET.Core/tensorflow.cs View File

@@ -51,39 +51,19 @@ namespace Tensorflow
{
var ones = constant_op.constant(1.0f, dtype: dtype) as EagerTensor;
return ones.EagerTensorHandle;
}, (gradients, num_grads) =>
}, (gradients) =>
{
var input_grads = new EagerTensor[num_grads];
for (int i = 0; i < num_grads; i++)
input_grads[i] = new EagerTensor(*((IntPtr*)gradients + i));

var input_grads = gradients.Data().Select(x => new EagerTensor(x)).ToArray();
var add_n = gen_math_ops.add_n(input_grads) as EagerTensor;
return add_n.EagerTensorHandle;
});

ops.RegisterFromAssembly();
c_api.TFE_RegisterGradientFunction((op_name, op_inputs_handle, op_outputs, num_attrs, output_grads, skip_input_indices) =>
c_api.TFE_RegisterGradientFunction((op_name, op_inputs, op_outputs, num_attrs, output_grads, skip_input_indices) =>
{
var op_inputs = Marshal.PtrToStructure<BindingArray>(op_inputs_handle);
var input_tensors = new EagerTensor[op_inputs.length];
for (int i = 0; i < op_inputs.length; i++)
{
// Console.WriteLine($"debug 4: {op_name} op_inputs=" + (*(IntPtr*)op_inputs_handle).ToString("x16").ToUpper() + $" op_inputs[{i}]=" + (*((IntPtr*)op_inputs.array + i)).ToString("x16").ToUpper());
if((*((IntPtr*)op_inputs.array + i)).ToString("x16").ToUpper().StartsWith("FFFFF"))
{

}
input_tensors[i] = new EagerTensor(*((IntPtr*)op_inputs.array + i));
}

var output_tensors = new EagerTensor[op_outputs.length];
for (int i = 0; i < op_outputs.length; i++)
output_tensors[i] = new EagerTensor(*((IntPtr*)op_outputs.array + i));

var output_grad_tensors = new EagerTensor[output_grads.length];
for (int i = 0; i < output_grads.length; i++)
output_grad_tensors[i] = new EagerTensor(*((IntPtr*)output_grads.array + i));

var input_tensors = op_inputs.Data().Select(x => new EagerTensor(x)).ToArray();
var output_tensors = op_outputs.Data().Select(x => new EagerTensor(x)).ToArray();
var output_grad_tensors = output_grads.Data().Select(x => new EagerTensor(x)).ToArray();
var skip_input_indices_param = new int[skip_input_indices.length];
for (int i = 0; i < skip_input_indices.length; i++)
skip_input_indices_param[i] = *((int*)skip_input_indices.array + i);
@@ -101,6 +81,9 @@ namespace Tensorflow
var wrap_handle = c_api.TFE_WrapGradientResult(gradients_handles, gradients.Length);

return wrap_handle;
}, (op_name, op_inputs, op_outputs) =>
{

});
}



Loading…
Cancel
Save