From a942564fc9af53f07b1e75e26ef9d0d09f748c49 Mon Sep 17 00:00:00 2001 From: Oceania2018 Date: Sat, 20 Feb 2021 14:37:43 -0600 Subject: [PATCH] fix tf.batch_matmul #755 --- README.md | 9 +++++---- src/TensorFlowNET.Console/Tensorflow.Console.csproj | 1 + src/TensorFlowNET.Core/APIs/tf.linalg.cs | 4 ++-- src/TensorFlowNET.Core/Operations/math_ops.cs | 11 +++-------- src/TensorFlowNET.Keras/Tensorflow.Keras.csproj | 9 +++++---- .../Tensorflow.Benchmark.csproj | 1 + 6 files changed, 17 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 77688745..d157e09d 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ [![Badge](https://img.shields.io/badge/link-996.icu-red.svg)](https://996.icu/#/en_US) [![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/javiercp/BinderTF.NET/master?urlpath=lab) -*master branch is based on tensorflow 2.3 now, v0.15-tensorflow1.15 is from tensorflow1.15.* +*master branch is based on tensorflow v2.4, v0.3x branch is based on tensorflow v2.3, v0.15-tensorflow1.15 is from tensorflow1.15.* ![tensors_flowing](docs/assets/tensors_flowing.gif) @@ -30,7 +30,8 @@ Go through the online docs [TensorFlow for .NET](https://scisharp.github.io/tens | TensorFlow | tf native1.14, cuda 10.0 | tf native 1.15, cuda 10.0 | tf native 2.3, cuda 10.1 | tf native 2.4, cuda 11 | | -------------------------- | ------------- | -------------- | ------------- | ------------- | -| tf.net 0.3x, tf.keras 0.2 | | | x | not compatible | +| tf.net 0.4x, tf.keras 0.5 | | | | x | +| tf.net 0.3x, tf.keras 0.4 | | | x | | | tf.net 0.2x | | x | x | | | tf.net 0.15 | x | x | | | | tf.net 0.14 | x | | | | @@ -50,10 +51,10 @@ PM> Install-Package TensorFlow.Keras ### Install tensorflow binary ### For CPU version -PM> Install-Package SciSharp.TensorFlow.Redist -Version 2.3.1 +PM> Install-Package SciSharp.TensorFlow.Redist ### For GPU version (CUDA and cuDNN are required) -PM> Install-Package SciSharp.TensorFlow.Redist-Windows-GPU -Version 2.3.1 +PM> Install-Package SciSharp.TensorFlow.Redist-Windows-GPU ``` Import TF.NET and Keras API in your project. diff --git a/src/TensorFlowNET.Console/Tensorflow.Console.csproj b/src/TensorFlowNET.Console/Tensorflow.Console.csproj index bc2c90d5..d6a76889 100644 --- a/src/TensorFlowNET.Console/Tensorflow.Console.csproj +++ b/src/TensorFlowNET.Console/Tensorflow.Console.csproj @@ -11,6 +11,7 @@ TRACE;DEBUG + x64 diff --git a/src/TensorFlowNET.Core/APIs/tf.linalg.cs b/src/TensorFlowNET.Core/APIs/tf.linalg.cs index e6968c8c..beb3122c 100644 --- a/src/TensorFlowNET.Core/APIs/tf.linalg.cs +++ b/src/TensorFlowNET.Core/APIs/tf.linalg.cs @@ -39,7 +39,7 @@ namespace Tensorflow => math_ops.matmul(a, b); public Tensor batch_matmul(Tensor x, Tensor y, bool adj_x = false, bool adj_y = false, string name = null) - => tf.Context.ExecuteOp("BatchMatMul", name, new ExecuteOpArgs(x, y).SetAttributes(new { adj_x, adj_y })); + => math_ops.batch_matmul(x, y, adj_x: adj_x, adj_y: adj_y, name: name); } public Tensor diag(Tensor diagonal, string name = null) @@ -74,6 +74,6 @@ namespace Tensorflow /// /// public Tensor batch_matmul(Tensor x, Tensor y, bool adj_x = false, bool adj_y = false, string name = null) - => tf.Context.ExecuteOp("BatchMatMul", name, new ExecuteOpArgs(x, y).SetAttributes(new { adj_x, adj_y })); + => math_ops.batch_matmul(x, y, adj_x: adj_x, adj_y: adj_y, name: name); } } diff --git a/src/TensorFlowNET.Core/Operations/math_ops.cs b/src/TensorFlowNET.Core/Operations/math_ops.cs index 1ffa6cc4..dfff531e 100644 --- a/src/TensorFlowNET.Core/Operations/math_ops.cs +++ b/src/TensorFlowNET.Core/Operations/math_ops.cs @@ -796,22 +796,17 @@ namespace Tensorflow public static Tensor batch_matmul(Tensor x, Tensor y, bool adj_x = false, bool adj_y = false, string name = null) - { - Tensor result = null; - - tf_with(ops.name_scope(name, "MatMul", new Tensor[] { x, y }), scope => + => tf_with(ops.name_scope(name, "MatMul", new Tensor[] { x, y }), scope => { name = scope; x = ops.convert_to_tensor(x, name: "a"); y = ops.convert_to_tensor(y, name: "b"); - result = math_ops.batch_matmul(x, y, adj_x, adj_y, name); + return tf.Context.ExecuteOp("BatchMatMul", name, new ExecuteOpArgs(x, y) + .SetAttributes(new { adj_x, adj_y })); }); - return result; - } - /// /// Returns the complex conjugate of a complex number. /// diff --git a/src/TensorFlowNET.Keras/Tensorflow.Keras.csproj b/src/TensorFlowNET.Keras/Tensorflow.Keras.csproj index 9eeb4634..f8ee6b79 100644 --- a/src/TensorFlowNET.Keras/Tensorflow.Keras.csproj +++ b/src/TensorFlowNET.Keras/Tensorflow.Keras.csproj @@ -6,7 +6,7 @@ 8.0 Tensorflow.Keras AnyCPU;x64 - 0.4.1 + 0.5.0 Haiping Chen Keras for .NET Apache 2.0, Haiping Chen 2020 @@ -23,7 +23,8 @@ * Implemented backward_function. * Support model.load_weights. * Add Subtract layer -* Support YOLOv3 model. +* Support YOLOv3 model. +* Text preprocessing Keras for .NET Keras is an API designed for human beings, not machines. Keras follows best practices for reducing cognitive load: it offers consistent & simple APIs, it minimizes the number of user actions required for common use cases, and it provides clear & actionable error messages. @@ -34,8 +35,8 @@ Keras is an API designed for human beings, not machines. Keras follows best prac Git true Open.snk - 0.4.1.0 - 0.4.1.0 + 0.5.0.0 + 0.5.0.0 LICENSE diff --git a/src/TensorFlowNet.Benchmarks/Tensorflow.Benchmark.csproj b/src/TensorFlowNet.Benchmarks/Tensorflow.Benchmark.csproj index 60955e68..6567a1ae 100644 --- a/src/TensorFlowNet.Benchmarks/Tensorflow.Benchmark.csproj +++ b/src/TensorFlowNet.Benchmarks/Tensorflow.Benchmark.csproj @@ -9,6 +9,7 @@ true DEBUG;TRACE + x64