Browse Source

Merge branch 'master' into v0.20-tensorflow2.0

tags/v0.20
Oceania2018 6 years ago
parent
commit
a62fd47dfb
100 changed files with 480 additions and 314 deletions
  1. +3
    -0
      CODEOWNERS
  2. +1
    -0
      src/KerasNET.Core/Core.cs
  3. +1
    -0
      src/KerasNET.Core/Layers/Dense.cs
  4. +1
    -1
      src/KerasNET.Core/Model.cs
  5. +10
    -10
      src/TensorFlowNET.Core/APIs/tf.array.cs
  6. +3
    -3
      src/TensorFlowNET.Core/APIs/tf.control.cs
  7. +5
    -3
      src/TensorFlowNET.Core/APIs/tf.distributions.cs
  8. +2
    -2
      src/TensorFlowNET.Core/APIs/tf.exp.cs
  9. +4
    -4
      src/TensorFlowNET.Core/APIs/tf.gradients.cs
  10. +4
    -4
      src/TensorFlowNET.Core/APIs/tf.graph.cs
  11. +8
    -8
      src/TensorFlowNET.Core/APIs/tf.init.cs
  12. +5
    -5
      src/TensorFlowNET.Core/APIs/tf.io.cs
  13. +9
    -6
      src/TensorFlowNET.Core/APIs/tf.layers.cs
  14. +4
    -4
      src/TensorFlowNET.Core/APIs/tf.linalg.cs
  15. +2
    -2
      src/TensorFlowNET.Core/APIs/tf.loss.cs
  16. +58
    -58
      src/TensorFlowNET.Core/APIs/tf.math.cs
  17. +26
    -24
      src/TensorFlowNET.Core/APIs/tf.nn.cs
  18. +4
    -4
      src/TensorFlowNET.Core/APIs/tf.ops.cs
  19. +4
    -4
      src/TensorFlowNET.Core/APIs/tf.random.cs
  20. +2
    -2
      src/TensorFlowNET.Core/APIs/tf.reduce_logsumexp.cs
  21. +3
    -3
      src/TensorFlowNET.Core/APIs/tf.reshape.cs
  22. +3
    -3
      src/TensorFlowNET.Core/APIs/tf.summary.cs
  23. +4
    -4
      src/TensorFlowNET.Core/APIs/tf.tensor.cs
  24. +3
    -3
      src/TensorFlowNET.Core/APIs/tf.tile.cs
  25. +4
    -4
      src/TensorFlowNET.Core/APIs/tf.variable.cs
  26. +46
    -30
      src/TensorFlowNET.Core/Binding.Util.cs
  27. +11
    -0
      src/TensorFlowNET.Core/Binding.cs
  28. +1
    -0
      src/TensorFlowNET.Core/Clustering/KMeans.cs
  29. +1
    -1
      src/TensorFlowNET.Core/Clustering/_InitializeClustersOpFactory.cs
  30. +1
    -1
      src/TensorFlowNET.Core/Framework/graph_util_impl.cs
  31. +1
    -1
      src/TensorFlowNET.Core/Framework/importer.py.cs
  32. +1
    -0
      src/TensorFlowNET.Core/Framework/meta_graph.py.cs
  33. +7
    -1
      src/TensorFlowNET.Core/Gradients/array_grad.cs
  34. +1
    -1
      src/TensorFlowNET.Core/Gradients/gradients_util.cs
  35. +1
    -1
      src/TensorFlowNET.Core/Gradients/math_grad.cs
  36. +1
    -0
      src/TensorFlowNET.Core/Graphs/DefaultGraphStack.cs
  37. +1
    -0
      src/TensorFlowNET.Core/Graphs/Graph.Operation.cs
  38. +2
    -1
      src/TensorFlowNET.Core/Graphs/Graph.cs
  39. +12
    -2
      src/TensorFlowNET.Core/Graphs/_ControlDependenciesController.cs
  40. +7
    -5
      src/TensorFlowNET.Core/IObjectLife.cs
  41. +3
    -2
      src/TensorFlowNET.Core/Keras/BackendBase.cs
  42. +11
    -1
      src/TensorFlowNET.Core/Keras/Engine/Sequential.cs
  43. +3
    -2
      src/TensorFlowNET.Core/Keras/Layers/BatchNormalization.cs
  44. +2
    -2
      src/TensorFlowNET.Core/Keras/Layers/Dense.cs
  45. +2
    -0
      src/TensorFlowNET.Core/Keras/Layers/Embedding.cs
  46. +1
    -1
      src/TensorFlowNET.Core/Keras/Layers/Layer.cs
  47. +2
    -2
      src/TensorFlowNET.Core/Keras/Layers/MaxPooling2D.cs
  48. +1
    -0
      src/TensorFlowNET.Core/Keras/Utils/base_layer_utils.cs
  49. +2
    -2
      src/TensorFlowNET.Core/Keras/backend.cs
  50. +2
    -2
      src/TensorFlowNET.Core/Keras/tf.keras.cs
  51. +1
    -1
      src/TensorFlowNET.Core/Layers/Layer.cs
  52. +1
    -1
      src/TensorFlowNET.Core/Operations/ControlFlows/CondContext.cs
  53. +10
    -1
      src/TensorFlowNET.Core/Operations/ControlFlows/ControlFlowContext.cs
  54. +1
    -1
      src/TensorFlowNET.Core/Operations/ControlFlows/WhileContext.cs
  55. +1
    -1
      src/TensorFlowNET.Core/Operations/Distributions/distribution.py.cs
  56. +1
    -1
      src/TensorFlowNET.Core/Operations/Distributions/normal.py.cs
  57. +1
    -1
      src/TensorFlowNET.Core/Operations/Losses/losses_impl.py.cs
  58. +1
    -1
      src/TensorFlowNET.Core/Operations/NnOps/MaxPoolFunction.cs
  59. +1
    -2
      src/TensorFlowNET.Core/Operations/NnOps/rnn.cs
  60. +2
    -2
      src/TensorFlowNET.Core/Operations/OpDefLibrary.cs
  61. +1
    -1
      src/TensorFlowNET.Core/Operations/RNNCell.cs
  62. +1
    -1
      src/TensorFlowNET.Core/Operations/_GraphTensorArray.cs
  63. +1
    -1
      src/TensorFlowNET.Core/Operations/array_ops.py.cs
  64. +1
    -1
      src/TensorFlowNET.Core/Operations/check_ops.cs
  65. +1
    -1
      src/TensorFlowNET.Core/Operations/confusion_matrix.py.cs
  66. +1
    -1
      src/TensorFlowNET.Core/Operations/control_flow_ops.py.cs
  67. +1
    -1
      src/TensorFlowNET.Core/Operations/embedding_ops.cs
  68. +1
    -1
      src/TensorFlowNET.Core/Operations/gen_image_ops.py.cs
  69. +1
    -1
      src/TensorFlowNET.Core/Operations/math_ops.cs
  70. +1
    -1
      src/TensorFlowNET.Core/Operations/nn_impl.py.cs
  71. +2
    -2
      src/TensorFlowNET.Core/Operations/nn_ops.cs
  72. +1
    -1
      src/TensorFlowNET.Core/Operations/random_ops.py.cs
  73. +1
    -1
      src/TensorFlowNET.Core/Operations/weights_broadcast_ops.cs
  74. +12
    -2
      src/TensorFlowNET.Core/Sessions/Session.cs
  75. +1
    -1
      src/TensorFlowNET.Core/Summaries/Summary.cs
  76. +1
    -1
      src/TensorFlowNET.Core/Tensors/Tensor.Operators.cs
  77. +1
    -1
      src/TensorFlowNET.Core/Tensors/Tensor.cs
  78. +1
    -0
      src/TensorFlowNET.Core/Tensors/constant_op.cs
  79. +9
    -9
      src/TensorFlowNET.Core/Tensors/tf.constant.cs
  80. +1
    -1
      src/TensorFlowNET.Core/Train/AdamOptimizer.cs
  81. +2
    -2
      src/TensorFlowNET.Core/Train/Optimizer.cs
  82. +1
    -1
      src/TensorFlowNET.Core/Train/Saving/BaseSaverBuilder.cs
  83. +2
    -2
      src/TensorFlowNET.Core/Train/Saving/Saver.cs
  84. +1
    -1
      src/TensorFlowNET.Core/Train/Saving/saveable_object_util.py.cs
  85. +1
    -1
      src/TensorFlowNET.Core/Train/SlotCreator.cs
  86. +10
    -8
      src/TensorFlowNET.Core/Train/tf.optimizers.cs
  87. +2
    -2
      src/TensorFlowNET.Core/Util/nest.py.cs
  88. +11
    -1
      src/TensorFlowNET.Core/Variables/PureVariableScope.cs
  89. +1
    -1
      src/TensorFlowNET.Core/Variables/RefVariable.Operators.cs
  90. +1
    -1
      src/TensorFlowNET.Core/Variables/RefVariable.cs
  91. +1
    -1
      src/TensorFlowNET.Core/Variables/VariableScope.cs
  92. +1
    -0
      src/TensorFlowNET.Core/Variables/_VariableStore.cs
  93. +11
    -1
      src/TensorFlowNET.Core/Variables/variable_scope.py.cs
  94. +13
    -3
      src/TensorFlowNET.Core/ops._DefaultStack.cs
  95. +2
    -2
      src/TensorFlowNET.Core/ops.cs
  96. +11
    -1
      src/TensorFlowNET.Core/ops.name_scope.cs
  97. +49
    -24
      src/TensorFlowNET.Core/tensorflow.cs
  98. +1
    -0
      src/TensorFlowNet.Benchmarks/TensorBenchmark.cs
  99. +2
    -2
      test/TensorFlowNET.Examples.FSharp/FunctionApproximation.fs
  100. +1
    -0
      test/TensorFlowNET.Examples/BasicEagerApi.cs

+ 3
- 0
CODEOWNERS View File

@@ -0,0 +1,3 @@
# You can find more information about CODEOWNERS here: https://help.github.com/en/articles/about-code-owners
# These owners will be the default owners for everything in the repo.
* @Oceania2018

+ 1
- 0
src/KerasNET.Core/Core.cs View File

@@ -1,4 +1,5 @@
using Tensorflow;
using static Tensorflow.Binding;

namespace Keras
{


+ 1
- 0
src/KerasNET.Core/Layers/Dense.cs View File

@@ -19,6 +19,7 @@ using Tensorflow;
using static Keras.Keras;
using NumSharp;
using Tensorflow.Operations.Activation;
using static Tensorflow.Binding;

namespace Keras.Layers
{


+ 1
- 1
src/KerasNET.Core/Model.cs View File

@@ -19,7 +19,7 @@ using NumSharp;
using System;
using System.Collections.Generic;
using Tensorflow;
using static Tensorflow.Python;
using static Tensorflow.Binding;

namespace Keras
{


+ 10
- 10
src/TensorFlowNET.Core/APIs/tf.array.cs View File

@@ -20,7 +20,7 @@ using System.Linq;

namespace Tensorflow
{
public static partial class tf
public partial class tensorflow
{
/// <summary>
/// Concatenates tensors along one dimension.
@@ -29,7 +29,7 @@ namespace Tensorflow
/// <param name="axis"></param>
/// <param name="name"></param>
/// <returns>A `Tensor` resulting from concatenation of the input tensors.</returns>
public static Tensor concat(IList<Tensor> values, int axis, string name = "concat")
public Tensor concat(IList<Tensor> values, int axis, string name = "concat")
{
if (values.Count == 1)
throw new NotImplementedException("tf.concat length is 1");
@@ -48,7 +48,7 @@ namespace Tensorflow
/// A `Tensor` with the same data as `input`, but its shape has an additional
/// dimension of size 1 added.
/// </returns>
public static Tensor expand_dims(Tensor input, int axis = -1, string name = null, int dim = -1)
public Tensor expand_dims(Tensor input, int axis = -1, string name = null, int dim = -1)
=> array_ops.expand_dims(input, axis, name, dim);

/// <summary>
@@ -58,14 +58,14 @@ namespace Tensorflow
/// <param name="value"></param>
/// <param name="name"></param>
/// <returns></returns>
public static Tensor fill<T>(Tensor dims, T value, string name = null)
public Tensor fill<T>(Tensor dims, T value, string name = null)
=> gen_array_ops.fill(dims, value, name: name);

/// <summary>
/// Return the elements, either from `x` or `y`, depending on the `condition`.
/// </summary>
/// <returns></returns>
public static Tensor where<Tx, Ty>(Tensor condition, Tx x, Ty y, string name = null)
public Tensor where<Tx, Ty>(Tensor condition, Tx x, Ty y, string name = null)
=> array_ops.where(condition, x, y, name);

/// <summary>
@@ -76,10 +76,10 @@ namespace Tensorflow
/// <param name="name"></param>
/// <param name="conjugate"></param>
/// <returns></returns>
public static Tensor transpose<T1>(T1 a, int[] perm = null, string name = "transpose", bool conjugate = false)
public Tensor transpose<T1>(T1 a, int[] perm = null, string name = "transpose", bool conjugate = false)
=> array_ops.transpose(a, perm, name, conjugate);

public static Tensor squeeze(Tensor input, int[] axis = null, string name = null, int squeeze_dims = -1)
public Tensor squeeze(Tensor input, int[] axis = null, string name = null, int squeeze_dims = -1)
=> gen_array_ops.squeeze(input, axis, name);

/// <summary>
@@ -89,10 +89,10 @@ namespace Tensorflow
/// <param name="axis"></param>
/// <param name="name"></param>
/// <returns></returns>
public static Tensor stack(object values, int axis = 0, string name = "stack")
public Tensor stack(object values, int axis = 0, string name = "stack")
=> array_ops.stack(values, axis, name: name);

public static Tensor one_hot(Tensor indices, int depth,
public Tensor one_hot(Tensor indices, int depth,
Tensor on_value = null,
Tensor off_value = null,
TF_DataType dtype = TF_DataType.DtInvalid,
@@ -110,7 +110,7 @@ namespace Tensorflow
/// </param>
/// <param name="name">A name for the operation (optional).</param>
/// <returns>A `Tensor`. Has the same type as `input`.</returns>
public static Tensor placeholder_with_default<T>(T input, int[] shape, string name = null)
public Tensor placeholder_with_default<T>(T input, int[] shape, string name = null)
=> gen_array_ops.placeholder_with_default(input, shape, name: name);
}
}

+ 3
- 3
src/TensorFlowNET.Core/APIs/tf.control.cs View File

@@ -18,9 +18,9 @@ using System;

namespace Tensorflow
{
public static partial class tf
public partial class tensorflow
{
public static Tensor while_loop(Func<Tensor, Tensor> cond, Func<Tensor, Tensor> body, Tensor[] loop_vars,
public Tensor while_loop(Func<Tensor, Tensor> cond, Func<Tensor, Tensor> body, Tensor[] loop_vars,
TensorShape shape_invariants = null,
int parallel_iterations = 10,
bool back_prop = true,
@@ -37,7 +37,7 @@ namespace Tensorflow
maximum_iterations: maximum_iterations,
return_same_structure: return_same_structure);

public static _ControlDependenciesController control_dependencies(Operation[] control_inputs)
public _ControlDependenciesController control_dependencies(Operation[] control_inputs)
=> ops.control_dependencies(control_inputs);
}
}

+ 5
- 3
src/TensorFlowNET.Core/APIs/tf.distributions.cs View File

@@ -16,11 +16,13 @@

namespace Tensorflow
{
public static partial class tf
public partial class tensorflow
{
public static class distributions
public distributions_internal distributions { get; } = new distributions_internal();

public class distributions_internal
{
public static Normal Normal(Tensor loc,
public Normal Normal(Tensor loc,
Tensor scale,
bool validate_args = false,
bool allow_nan_stats = true,


+ 2
- 2
src/TensorFlowNET.Core/APIs/tf.exp.cs View File

@@ -16,9 +16,9 @@

namespace Tensorflow
{
public static partial class tf
public partial class tensorflow
{
public static Tensor exp(Tensor x,
public Tensor exp(Tensor x,
string name = null) => gen_math_ops.exp(x, name);

}


+ 4
- 4
src/TensorFlowNET.Core/APIs/tf.gradients.cs View File

@@ -16,9 +16,9 @@

namespace Tensorflow
{
public static partial class tf
public partial class tensorflow
{
public static Tensor[] gradients(Tensor[] ys,
public Tensor[] gradients(Tensor[] ys,
Tensor[] xs,
Tensor[] grad_ys = null,
string name = "gradients",
@@ -36,7 +36,7 @@ namespace Tensorflow
stop_gradients: stop_gradients);
}

public static Tensor[] gradients(Tensor ys,
public Tensor[] gradients(Tensor ys,
Tensor[] xs,
Tensor[] grad_ys = null,
string name = "gradients",
@@ -54,7 +54,7 @@ namespace Tensorflow
stop_gradients: stop_gradients);
}

public static Tensor[] gradients(Tensor ys,
public Tensor[] gradients(Tensor ys,
Tensor xs,
Tensor[] grad_ys = null,
string name = "gradients",


+ 4
- 4
src/TensorFlowNET.Core/APIs/tf.graph.cs View File

@@ -16,15 +16,15 @@

namespace Tensorflow
{
public static partial class tf
public partial class tensorflow
{
public static graph_util_impl graph_util => new graph_util_impl();
public static Graph get_default_graph()
public graph_util_impl graph_util => new graph_util_impl();
public Graph get_default_graph()
{
return ops.get_default_graph();
}

public static Graph Graph()
public Graph Graph()
=> new Graph();
}
}

+ 8
- 8
src/TensorFlowNET.Core/APIs/tf.init.cs View File

@@ -18,14 +18,14 @@ using Tensorflow.Operations.Initializers;

namespace Tensorflow
{
public static partial class tf
public partial class tensorflow
{
public static IInitializer zeros_initializer => new Zeros();
public static IInitializer ones_initializer => new Ones();
public static IInitializer glorot_uniform_initializer => new GlorotUniform();
public static IInitializer uniform_initializer => new RandomUniform();
public IInitializer zeros_initializer => new Zeros();
public IInitializer ones_initializer => new Ones();
public IInitializer glorot_uniform_initializer => new GlorotUniform();
public IInitializer uniform_initializer => new RandomUniform();

public static variable_scope variable_scope(string name,
public variable_scope variable_scope(string name,
string default_name = null,
Tensor[] values = null,
bool? reuse = null,
@@ -35,7 +35,7 @@ namespace Tensorflow
reuse: reuse,
auxiliary_name_scope: auxiliary_name_scope);

public static variable_scope variable_scope(VariableScope scope,
public variable_scope variable_scope(VariableScope scope,
string default_name = null,
Tensor[] values = null,
bool? reuse = null,
@@ -45,7 +45,7 @@ namespace Tensorflow
reuse: reuse,
auxiliary_name_scope: auxiliary_name_scope);

public static IInitializer truncated_normal_initializer(float mean = 0.0f,
public IInitializer truncated_normal_initializer(float mean = 0.0f,
float stddev = 1.0f,
int? seed = null,
TF_DataType dtype = TF_DataType.DtInvalid) => new TruncatedNormal(mean: mean,


+ 5
- 5
src/TensorFlowNET.Core/APIs/tf.io.cs View File

@@ -19,14 +19,14 @@ using Tensorflow.IO;

namespace Tensorflow
{
public static partial class tf
public partial class tensorflow
{
public static GFile gfile = new GFile();
public static Tensor read_file(string filename, string name = null) => gen_io_ops.read_file(filename, name);
public GFile gfile = new GFile();
public Tensor read_file(string filename, string name = null) => gen_io_ops.read_file(filename, name);

public static gen_image_ops image => new gen_image_ops();
public gen_image_ops image => new gen_image_ops();

public static void import_graph_def(GraphDef graph_def,
public void import_graph_def(GraphDef graph_def,
Dictionary<string, Tensor> input_map = null,
string[] return_elements = null,
string name = null,


+ 9
- 6
src/TensorFlowNET.Core/APIs/tf.layers.cs View File

@@ -16,14 +16,17 @@

using Tensorflow.Keras.Layers;
using Tensorflow.Operations.Activation;
using static Tensorflow.Binding;

namespace Tensorflow
{
public static partial class tf
public partial class tensorflow
{
public static class layers
public layers_internal layers { get; } = new layers_internal();

public class layers_internal
{
public static Tensor conv2d(Tensor inputs,
public Tensor conv2d(Tensor inputs,
int filters,
int[] kernel_size,
int[] strides = null,
@@ -80,7 +83,7 @@ namespace Tensorflow
/// <param name="renorm"></param>
/// <param name="renorm_momentum"></param>
/// <returns></returns>
public static Tensor batch_normalization(Tensor inputs,
public Tensor batch_normalization(Tensor inputs,
int axis = -1,
float momentum = 0.99f,
float epsilon = 0.001f,
@@ -124,7 +127,7 @@ namespace Tensorflow
/// <param name="data_format"></param>
/// <param name="name"></param>
/// <returns></returns>
public static Tensor max_pooling2d(Tensor inputs,
public Tensor max_pooling2d(Tensor inputs,
int[] pool_size,
int[] strides,
string padding = "valid",
@@ -140,7 +143,7 @@ namespace Tensorflow
return layer.apply(inputs);
}

public static Tensor dense(Tensor inputs,
public Tensor dense(Tensor inputs,
int units,
IActivation activation = null,
bool use_bias = true,


+ 4
- 4
src/TensorFlowNET.Core/APIs/tf.linalg.cs View File

@@ -16,15 +16,15 @@

namespace Tensorflow
{
public static partial class tf
public partial class tensorflow
{
public static Tensor diag(Tensor diagonal, string name = null)
public Tensor diag(Tensor diagonal, string name = null)
=> gen_array_ops.diag(diagonal, name: name);

public static Tensor matmul(Tensor a, Tensor b)
public Tensor matmul(Tensor a, Tensor b)
=> gen_math_ops.mat_mul(a, b);

public static Tensor batch_matmul(Tensor x, Tensor y)
public Tensor batch_matmul(Tensor x, Tensor y)
=> gen_math_ops.batch_mat_mul(x, y);
}
}

+ 2
- 2
src/TensorFlowNET.Core/APIs/tf.loss.cs View File

@@ -16,8 +16,8 @@

namespace Tensorflow
{
public static partial class tf
public partial class tensorflow
{
public static LossesImpl losses => new LossesImpl();
public LossesImpl losses => new LossesImpl();
}
}

+ 58
- 58
src/TensorFlowNET.Core/APIs/tf.math.cs View File

@@ -16,9 +16,9 @@

namespace Tensorflow
{
public static partial class tf
public partial class tensorflow
{
public static Tensor abs(Tensor x, string name = null)
public Tensor abs(Tensor x, string name = null)
=> math_ops.abs(x, name);

/// <summary>
@@ -27,7 +27,7 @@ namespace Tensorflow
/// <param name="x"></param>
/// <param name="name"></param>
/// <returns></returns>
public static Tensor acos(Tensor x, string name = null)
public Tensor acos(Tensor x, string name = null)
=> gen_math_ops.acos(x, name);

/// <summary>
@@ -36,10 +36,10 @@ namespace Tensorflow
/// <param name="x"></param>
/// <param name="name"></param>
/// <returns></returns>
public static Tensor asin(Tensor x, string name = null)
public Tensor asin(Tensor x, string name = null)
=> gen_math_ops.asin(x, name);

public static Tensor add<Tx, Ty>(Tx a, Ty b, string name = null)
public Tensor add<Tx, Ty>(Tx a, Ty b, string name = null)
=> gen_math_ops.add(a, b, name: name);

/// <summary>
@@ -48,19 +48,19 @@ namespace Tensorflow
/// <param name="x"></param>
/// <param name="name"></param>
/// <returns></returns>
public static Tensor atan(Tensor x, string name = null)
public Tensor atan(Tensor x, string name = null)
=> gen_math_ops.atan(x, name);

public static Tensor arg_max(Tensor input, int dimension, TF_DataType output_type = TF_DataType.TF_INT64, string name = null)
public Tensor arg_max(Tensor input, int dimension, TF_DataType output_type = TF_DataType.TF_INT64, string name = null)
=> gen_math_ops.arg_max(input, dimension, output_type: output_type, name: name);

public static Tensor arg_min(Tensor input, int dimension, TF_DataType output_type = TF_DataType.TF_INT64, string name = null)
public Tensor arg_min(Tensor input, int dimension, TF_DataType output_type = TF_DataType.TF_INT64, string name = null)
=> gen_math_ops.arg_min(input, dimension, output_type: output_type, name: name);

public static Tensor is_finite(Tensor input, string name = null)
public Tensor is_finite(Tensor input, string name = null)
=> gen_math_ops.is_finite(input, name);

public static Tensor is_nan(Tensor input, string name = null)
public Tensor is_nan(Tensor input, string name = null)
=> gen_math_ops.is_nan(input, name);

/// <summary>
@@ -69,7 +69,7 @@ namespace Tensorflow
/// <param name="x"></param>
/// <param name="name"></param>
/// <returns></returns>
public static Tensor ceil(Tensor x, string name = null)
public Tensor ceil(Tensor x, string name = null)
=> gen_math_ops.ceil(x, name);

/// <summary>
@@ -78,7 +78,7 @@ namespace Tensorflow
/// <param name="x"></param>
/// <param name="name"></param>
/// <returns></returns>
public static Tensor sin(Tensor x, string name = null)
public Tensor sin(Tensor x, string name = null)
=> gen_math_ops.sin(x, name);

/// <summary>
@@ -87,7 +87,7 @@ namespace Tensorflow
/// <param name="x"></param>
/// <param name="name"></param>
/// <returns></returns>
public static Tensor sinh(Tensor x, string name = null)
public Tensor sinh(Tensor x, string name = null)
=> gen_math_ops.sinh(x, name);

/// <summary>
@@ -96,7 +96,7 @@ namespace Tensorflow
/// <param name="x"></param>
/// <param name="name"></param>
/// <returns></returns>
public static Tensor cos(Tensor x, string name = null)
public Tensor cos(Tensor x, string name = null)
=> gen_math_ops.cos(x, name);

/// <summary>
@@ -105,13 +105,13 @@ namespace Tensorflow
/// <param name="x"></param>
/// <param name="name"></param>
/// <returns></returns>
public static Tensor cosh(Tensor x, string name = null)
public Tensor cosh(Tensor x, string name = null)
=> gen_math_ops.cosh(x, name);

public static Tensor tan(Tensor x, string name = null)
public Tensor tan(Tensor x, string name = null)
=> gen_math_ops.tan(x, name);

public static Tensor tanh(Tensor x, string name = null)
public Tensor tanh(Tensor x, string name = null)
=> gen_math_ops.tanh(x, name);

/// <summary>
@@ -120,7 +120,7 @@ namespace Tensorflow
/// <param name="x"></param>
/// <param name="name"></param>
/// <returns></returns>
public static Tensor floor(Tensor x, string name = null)
public Tensor floor(Tensor x, string name = null)
=> gen_math_ops.floor(x, name);

/// <summary>
@@ -132,7 +132,7 @@ namespace Tensorflow
/// <param name="y"></param>
/// <param name="name"></param>
/// <returns></returns>
public static Tensor greater<Tx, Ty>(Tx x, Ty y, string name = null)
public Tensor greater<Tx, Ty>(Tx x, Ty y, string name = null)
=> gen_math_ops.greater(x, y, name);

/// <summary>
@@ -144,7 +144,7 @@ namespace Tensorflow
/// <param name="y"></param>
/// <param name="name"></param>
/// <returns></returns>
public static Tensor greater_equal<Tx, Ty>(Tx x, Ty y, string name = null)
public Tensor greater_equal<Tx, Ty>(Tx x, Ty y, string name = null)
=> gen_math_ops.greater_equal(x, y, name);

/// <summary>
@@ -156,7 +156,7 @@ namespace Tensorflow
/// <param name="y"></param>
/// <param name="name"></param>
/// <returns></returns>
public static Tensor less<Tx, Ty>(Tx x, Ty y, string name = null)
public Tensor less<Tx, Ty>(Tx x, Ty y, string name = null)
=> gen_math_ops.less(x, y, name);

/// <summary>
@@ -165,7 +165,7 @@ namespace Tensorflow
/// <param name="x">A `Tensor`. Must be one of the following types: `bfloat16`, `half`, `float32`, `float64`.</param>
/// <param name="name">A name for the operation (optional).</param>
/// <returns>A `Tensor`. Has the same type as `x`.</returns>
public static Tensor lgamma(Tensor x, string name = null)
public Tensor lgamma(Tensor x, string name = null)
=> gen_math_ops.lgamma(x, name: name);

/// <summary>
@@ -177,7 +177,7 @@ namespace Tensorflow
/// <param name="y"></param>
/// <param name="name"></param>
/// <returns></returns>
public static Tensor less_equal<Tx, Ty>(Tx x, Ty y, string name = null)
public Tensor less_equal<Tx, Ty>(Tx x, Ty y, string name = null)
=> gen_math_ops.less_equal(x, y, name);

/// <summary>
@@ -186,19 +186,19 @@ namespace Tensorflow
/// <param name="x"></param>
/// <param name="name"></param>
/// <returns></returns>
public static Tensor log1p(Tensor x, string name = null)
public Tensor log1p(Tensor x, string name = null)
=> gen_math_ops.log1p(x, name);

public static Tensor logical_and(Tensor x, Tensor y, string name = null)
public Tensor logical_and(Tensor x, Tensor y, string name = null)
=> gen_math_ops.logical_and(x, y, name);

public static Tensor logical_not(Tensor x, string name = null)
public Tensor logical_not(Tensor x, string name = null)
=> gen_math_ops.logical_not(x, name);

public static Tensor logical_or(Tensor x, Tensor y, string name = null)
public Tensor logical_or(Tensor x, Tensor y, string name = null)
=> gen_math_ops.logical_or(x, y, name);

public static Tensor logical_xor(Tensor x, Tensor y, string name = "LogicalXor")
public Tensor logical_xor(Tensor x, Tensor y, string name = "LogicalXor")
=> gen_math_ops.logical_xor(x, y, name);

/// <summary>
@@ -209,28 +209,28 @@ namespace Tensorflow
/// <param name="clip_value_max"></param>
/// <param name="name"></param>
/// <returns></returns>
public static Tensor _clip_by_value(Tensor t, Tensor clip_value_min, Tensor clip_value_max, string name = null)
public Tensor _clip_by_value(Tensor t, Tensor clip_value_min, Tensor clip_value_max, string name = null)
=> gen_math_ops._clip_by_value(t, clip_value_min, clip_value_max);

public static Tensor sub(Tensor a, Tensor b)
public Tensor sub(Tensor a, Tensor b)
=> gen_math_ops.sub(a, b);

public static Tensor divide(Tensor a, Tensor b)
public Tensor divide(Tensor a, Tensor b)
=> gen_math_ops.real_div(a, b);

public static Tensor sqrt(Tensor a, string name = null)
public Tensor sqrt(Tensor a, string name = null)
=> gen_math_ops.sqrt(a, name);

public static Tensor sign(Tensor a, string name = null)
public Tensor sign(Tensor a, string name = null)
=> gen_math_ops.sign(a, name);

public static Tensor subtract<T>(Tensor x, T[] y, string name = null) where T : struct
public Tensor subtract<T>(Tensor x, T[] y, string name = null) where T : struct
=> gen_math_ops.sub(x, ops.convert_to_tensor(y, dtype: x.dtype.as_base_dtype(), name: "y"), name);

public static Tensor log(Tensor x, string name = null)
public Tensor log(Tensor x, string name = null)
=> gen_math_ops.log(x, name);

public static Tensor equal(Tensor x, Tensor y, string name = null)
public Tensor equal(Tensor x, Tensor y, string name = null)
=> gen_math_ops.equal(x, y, name);

/// <summary>
@@ -240,7 +240,7 @@ namespace Tensorflow
/// <param name="x"></param>
/// <param name="name"></param>
/// <returns></returns>
public static Tensor atan2(Tensor y, Tensor x, string name = null)
public Tensor atan2(Tensor y, Tensor x, string name = null)
=> gen_math_ops.atan2(y, x, name);

/// <summary>
@@ -253,7 +253,7 @@ namespace Tensorflow
/// <param name="keep_dims"></param>
/// <param name="name"></param>
/// <returns></returns>
public static Tensor max<Tx, Ty>(Tx input, Ty axis, bool keep_dims = false, string name = null)
public Tensor max<Tx, Ty>(Tx input, Ty axis, bool keep_dims = false, string name = null)
=> gen_math_ops._max(input, axis, keep_dims: keep_dims, name: name);

/// <summary>
@@ -266,7 +266,7 @@ namespace Tensorflow
/// <param name="keep_dims"></param>
/// <param name="name"></param>
/// <returns></returns>
public static Tensor min<Tx, Ty>(Tx input, Ty axis, bool keep_dims = false, string name = null)
public Tensor min<Tx, Ty>(Tx input, Ty axis, bool keep_dims = false, string name = null)
=> gen_math_ops._min(input, axis, keep_dims: keep_dims, name: name);

/// <summary>
@@ -278,7 +278,7 @@ namespace Tensorflow
/// <param name="y"></param>
/// <param name="name"></param>
/// <returns></returns>
public static Tensor maximum<T1, T2>(T1 x, T2 y, string name = null)
public Tensor maximum<T1, T2>(T1 x, T2 y, string name = null)
=> gen_math_ops.maximum(x, y, name: name);

/// <summary>
@@ -290,13 +290,13 @@ namespace Tensorflow
/// <param name="y"></param>
/// <param name="name"></param>
/// <returns></returns>
public static Tensor minimum<T1, T2>(T1 x, T2 y, string name = null)
public Tensor minimum<T1, T2>(T1 x, T2 y, string name = null)
=> gen_math_ops.minimum(x, y, name: name);

public static Tensor multiply<Tx, Ty>(Tx x, Ty y)
public Tensor multiply<Tx, Ty>(Tx x, Ty y)
=> gen_math_ops.mul(x, y);

public static Tensor negative(Tensor x, string name = null)
public Tensor negative(Tensor x, string name = null)
=> gen_math_ops.neg(x, name);

/// <summary>
@@ -306,13 +306,13 @@ namespace Tensorflow
/// <param name="y"></param>
/// <param name="name"></param>
/// <returns></returns>
public static Tensor div(Tensor x, Tensor y, string name = null)
public Tensor div(Tensor x, Tensor y, string name = null)
=> math_ops.div(x, y, name: name);

public static Tensor divide<T>(Tensor x, T[] y, string name = null) where T : struct
public Tensor divide<T>(Tensor x, T[] y, string name = null) where T : struct
=> x / ops.convert_to_tensor(y, dtype: x.dtype.as_base_dtype(), name: "y");

public static Tensor pow<T1, T2>(T1 x, T2 y)
public Tensor pow<T1, T2>(T1 x, T2 y)
=> gen_math_ops.pow(x, y);

/// <summary>
@@ -321,14 +321,14 @@ namespace Tensorflow
/// <param name="input"></param>
/// <param name="axis"></param>
/// <returns></returns>
public static Tensor reduce_sum(Tensor input, int? axis = null, int? reduction_indices = null)
public Tensor reduce_sum(Tensor input, int? axis = null, int? reduction_indices = null)
{
if(!axis.HasValue && reduction_indices.HasValue)
return math_ops.reduce_sum(input, reduction_indices.Value);
return math_ops.reduce_sum(input);
}

public static Tensor reduce_sum(Tensor input, int axis, int? reduction_indices = null)
public Tensor reduce_sum(Tensor input, int axis, int? reduction_indices = null)
=> math_ops.reduce_sum(input, axis);

/// <summary>
@@ -339,34 +339,34 @@ namespace Tensorflow
/// <param name="keepdims"></param>
/// <param name="name"></param>
/// <returns></returns>
public static Tensor reduce_max(Tensor input_tensor, int[] axis = null, bool keepdims = false, string name = null)
public Tensor reduce_max(Tensor input_tensor, int[] axis = null, bool keepdims = false, string name = null)
=> math_ops.reduce_max(input_tensor, axis, keepdims, name);

public static Tensor reduce_min(Tensor input_tensor, int[] axis = null, bool keepdims = false, string name = null)
public Tensor reduce_min(Tensor input_tensor, int[] axis = null, bool keepdims = false, string name = null)
=> math_ops.reduce_min(input_tensor, axis, keepdims, name);

public static Tensor sigmoid<T>(T x, string name = null)
public Tensor sigmoid<T>(T x, string name = null)
=> math_ops.sigmoid(x, name: name);

public static Tensor sum(Tensor input, int axis, bool keep_dims = false, string name = null)
public Tensor sum(Tensor input, int axis, bool keep_dims = false, string name = null)
=> gen_math_ops._sum(input, axis, keep_dims: keep_dims, name: name);

public static Tensor reduce_mean(Tensor input_tensor, int[] axis = null, bool keepdims = false, string name = null, int? reduction_indices = null)
public Tensor reduce_mean(Tensor input_tensor, int[] axis = null, bool keepdims = false, string name = null, int? reduction_indices = null)
=> math_ops.reduce_mean(input_tensor, axis: axis, keepdims: keepdims, name: name, reduction_indices: reduction_indices);

public static Tensor round(Tensor x, string name = null)
public Tensor round(Tensor x, string name = null)
=> gen_math_ops.round(x, name: name);

public static Tensor cast(Tensor x, TF_DataType dtype = TF_DataType.DtInvalid, string name = null)
public Tensor cast(Tensor x, TF_DataType dtype = TF_DataType.DtInvalid, string name = null)
=> math_ops.cast(x, dtype, name);

public static Tensor cumsum(Tensor x, int axis = 0, bool exclusive = false, bool reverse = false, string name = null)
public Tensor cumsum(Tensor x, int axis = 0, bool exclusive = false, bool reverse = false, string name = null)
=> math_ops.cumsum(x, axis: axis, exclusive: exclusive, reverse: reverse, name: name);

public static Tensor argmax(Tensor input, int axis = -1, string name = null, int? dimension = null, TF_DataType output_type = TF_DataType.TF_INT64)
public Tensor argmax(Tensor input, int axis = -1, string name = null, int? dimension = null, TF_DataType output_type = TF_DataType.TF_INT64)
=> gen_math_ops.arg_max(input, axis, name: name, output_type: output_type);

public static Tensor square(Tensor x, string name = null)
public Tensor square(Tensor x, string name = null)
=> gen_math_ops.square(x, name: name);
}
}

+ 26
- 24
src/TensorFlowNET.Core/APIs/tf.nn.cs View File

@@ -16,15 +16,17 @@

using Tensorflow.Operations;
using Tensorflow.Operations.Activation;
using static Tensorflow.Python;
using static Tensorflow.Binding;

namespace Tensorflow
{
public static partial class tf
public partial class tensorflow
{
public static class nn
public nn_internal nn { get; } = new nn_internal();

public class nn_internal
{
public static Tensor conv2d(Tensor input, RefVariable filter, int[] strides, string padding, bool use_cudnn_on_gpu = true,
public Tensor conv2d(Tensor input, RefVariable filter, int[] strides, string padding, bool use_cudnn_on_gpu = true,
string data_format= "NHWC", int[] dilations= null, string name = null)
{
var parameters = new Conv2dParams
@@ -54,7 +56,7 @@ namespace Tensorflow
/// <param name="name"></param>
/// <param name="rate">A scalar `Tensor` with the same type as `x`.</param>
/// <returns>A Tensor of the same shape of `x`.</returns>
public static Tensor dropout(Tensor x, Tensor keep_prob = null, Tensor noise_shape = null, int? seed = null, string name = null,
public Tensor dropout(Tensor x, Tensor keep_prob = null, Tensor noise_shape = null, int? seed = null, string name = null,
float? rate = null)
{
Tensor keep = null;
@@ -74,17 +76,17 @@ namespace Tensorflow
/// <param name="swap_memory"></param>
/// <param name="time_major"></param>
/// <returns>A pair (outputs, state)</returns>
public static (Tensor, Tensor) dynamic_rnn(RNNCell cell, Tensor inputs,
public (Tensor, Tensor) dynamic_rnn(RNNCell cell, Tensor inputs,
Tensor sequence_length = null, TF_DataType dtype = TF_DataType.DtInvalid,
int? parallel_iterations = null, bool swap_memory = false, bool time_major = false)
=> rnn.dynamic_rnn(cell, inputs, sequence_length: sequence_length, dtype: dtype,
parallel_iterations: parallel_iterations, swap_memory: swap_memory,
time_major: time_major);

public static Tensor elu(Tensor features, string name = null)
public Tensor elu(Tensor features, string name = null)
=> gen_nn_ops.elu(features, name: name);

public static (Tensor, Tensor) moments(Tensor x,
public (Tensor, Tensor) moments(Tensor x,
int[] axes,
string name = null,
bool keep_dims = false) => nn_impl.moments(x,
@@ -92,7 +94,7 @@ namespace Tensorflow
name: name,
keep_dims: keep_dims);

public static Tensor embedding_lookup(RefVariable @params,
public Tensor embedding_lookup(RefVariable @params,
Tensor ids,
string partition_strategy = "mod",
string name = null) => embedding_ops._embedding_lookup_and_transform(@params,
@@ -100,7 +102,7 @@ namespace Tensorflow
partition_strategy: partition_strategy,
name: name);

public static Tensor embedding_lookup(Tensor @params,
public Tensor embedding_lookup(Tensor @params,
Tensor ids,
string partition_strategy = "mod",
string name = null) => embedding_ops._embedding_lookup_and_transform(new Tensor[] { @params },
@@ -108,11 +110,11 @@ namespace Tensorflow
partition_strategy: partition_strategy,
name: name);

public static IActivation relu() => new relu();
public IActivation relu() => new relu();

public static Tensor relu(Tensor features, string name = null) => gen_nn_ops.relu(features, name);
public Tensor relu(Tensor features, string name = null) => gen_nn_ops.relu(features, name);

public static Tensor[] fused_batch_norm(Tensor x,
public Tensor[] fused_batch_norm(Tensor x,
RefVariable scale,
RefVariable offset,
Tensor mean = null,
@@ -126,29 +128,29 @@ namespace Tensorflow
is_training: is_training,
name: name);

public static IPoolFunction max_pool_fn => new MaxPoolFunction();
public IPoolFunction max_pool_fn => new MaxPoolFunction();

public static Tensor max_pool(Tensor value, int[] ksize, int[] strides, string padding, string data_format = "NHWC", string name = null)
public Tensor max_pool(Tensor value, int[] ksize, int[] strides, string padding, string data_format = "NHWC", string name = null)
=> nn_ops.max_pool(value, ksize, strides, padding, data_format: data_format, name: name);

public static Tensor in_top_k(Tensor predictions, Tensor targets, int k, string name = "InTopK")
public Tensor in_top_k(Tensor predictions, Tensor targets, int k, string name = "InTopK")
=> gen_ops.in_top_k(predictions, targets, k, name);

public static Tensor[] top_k(Tensor input, int k = 1, bool sorted = true, string name = null)
public Tensor[] top_k(Tensor input, int k = 1, bool sorted = true, string name = null)
=> gen_nn_ops.top_kv2(input, k: k, sorted: sorted, name: name);

public static Tensor bias_add(Tensor value, RefVariable bias, string data_format = null, string name = null)
public Tensor bias_add(Tensor value, RefVariable bias, string data_format = null, string name = null)
{
return Python.tf_with(ops.name_scope(name, "BiasAdd", new { value, bias }), scope =>
return tf_with(ops.name_scope(name, "BiasAdd", new { value, bias }), scope =>
{
name = scope;
return gen_nn_ops.bias_add(value, bias, data_format: data_format, name: name);
});
}

public static rnn_cell_impl rnn_cell => new rnn_cell_impl();
public rnn_cell_impl rnn_cell => new rnn_cell_impl();

public static Tensor softmax(Tensor logits, int axis = -1, string name = null)
public Tensor softmax(Tensor logits, int axis = -1, string name = null)
=> gen_nn_ops.softmax(logits, name);

/// <summary>
@@ -158,7 +160,7 @@ namespace Tensorflow
/// <param name="logits"></param>
/// <param name="name"></param>
/// <returns></returns>
public static Tensor sparse_softmax_cross_entropy_with_logits(Tensor labels = null,
public Tensor sparse_softmax_cross_entropy_with_logits(Tensor labels = null,
Tensor logits = null, string name = null)
=> nn_ops.sparse_softmax_cross_entropy_with_logits(labels: labels, logits: logits, name: name);

@@ -170,7 +172,7 @@ namespace Tensorflow
/// <param name="dim"></param>
/// <param name="name"></param>
/// <returns></returns>
public static Tensor softmax_cross_entropy_with_logits(Tensor labels, Tensor logits, int dim = -1, string name = null)
public Tensor softmax_cross_entropy_with_logits(Tensor labels, Tensor logits, int dim = -1, string name = null)
{
tf_with(ops.name_scope(name, "softmax_cross_entropy_with_logits_sg", new { logits, labels }), scope =>
{
@@ -181,7 +183,7 @@ namespace Tensorflow
return softmax_cross_entropy_with_logits_v2(labels, logits, axis: dim, name: name);
}

public static Tensor softmax_cross_entropy_with_logits_v2(Tensor labels, Tensor logits, int axis = -1, string name = null)
public Tensor softmax_cross_entropy_with_logits_v2(Tensor labels, Tensor logits, int axis = -1, string name = null)
=> nn_ops.softmax_cross_entropy_with_logits_v2_helper(labels, logits, axis: axis, name: name);
}
}


+ 4
- 4
src/TensorFlowNET.Core/APIs/tf.ops.cs View File

@@ -16,12 +16,12 @@

namespace Tensorflow
{
public static partial class tf
public partial class tensorflow
{
public static Tensor assign(Tensor @ref, object value, bool validate_shape = true, bool use_locking = true, string name = null)
public Tensor assign(Tensor @ref, object value, bool validate_shape = true, bool use_locking = true, string name = null)
=> state_ops.assign(@ref, value, validate_shape, use_locking, name);

public static object get_collection(string key, string scope = "")
public object get_collection(string key, string scope = "")
=> get_default_graph().get_collection(key, scope: scope);

/// <summary>
@@ -31,7 +31,7 @@ namespace Tensorflow
/// <param name="default_name">The default name to use if the name argument is None.</param>
/// <param name="values">The list of Tensor arguments that are passed to the op function.</param>
/// <returns>The scope name.</returns>
public static ops.NameScope name_scope(string name, string default_name = "", object values = null)
public ops.NameScope name_scope(string name, string default_name = "", object values = null)
=> new ops.NameScope(name, default_name, values);
}
}

+ 4
- 4
src/TensorFlowNET.Core/APIs/tf.random.cs View File

@@ -16,7 +16,7 @@

namespace Tensorflow
{
public static partial class tf
public partial class tensorflow
{
/// <summary>
/// Outputs random values from a normal distribution.
@@ -28,21 +28,21 @@ namespace Tensorflow
/// <param name="seed"></param>
/// <param name="name"></param>
/// <returns></returns>
public static Tensor random_normal(int[] shape,
public Tensor random_normal(int[] shape,
float mean = 0.0f,
float stddev = 1.0f,
TF_DataType dtype = TF_DataType.TF_FLOAT,
int? seed = null,
string name = null) => random_ops.random_normal(shape, mean, stddev, dtype, seed, name);

public static Tensor random_uniform(int[] shape,
public Tensor random_uniform(int[] shape,
float minval = 0,
float maxval = 1,
TF_DataType dtype = TF_DataType.TF_FLOAT,
int? seed = null,
string name = null) => random_ops.random_uniform(shape, minval, maxval, dtype, seed, name);

public static Tensor truncated_normal(int[] shape,
public Tensor truncated_normal(int[] shape,
float mean = 0.0f,
float stddev = 1.0f,
TF_DataType dtype = TF_DataType.TF_FLOAT,


+ 2
- 2
src/TensorFlowNET.Core/APIs/tf.reduce_logsumexp.cs View File

@@ -16,9 +16,9 @@

namespace Tensorflow
{
public static partial class tf
public partial class tensorflow
{
public static Tensor reduce_logsumexp(Tensor input_tensor,
public Tensor reduce_logsumexp(Tensor input_tensor,
int[] axis = null,
bool keepdims = false,
string name = null) => math_ops.reduce_logsumexp(input_tensor, axis, keepdims, name);


+ 3
- 3
src/TensorFlowNET.Core/APIs/tf.reshape.cs View File

@@ -16,13 +16,13 @@

namespace Tensorflow
{
public static partial class tf
public partial class tensorflow
{
public static Tensor reshape(Tensor tensor,
public Tensor reshape(Tensor tensor,
Tensor shape,
string name = null) => gen_array_ops.reshape(tensor, shape, name);

public static Tensor reshape(Tensor tensor,
public Tensor reshape(Tensor tensor,
int[] shape,
string name = null) => gen_array_ops.reshape(tensor, shape, name);
}


+ 3
- 3
src/TensorFlowNET.Core/APIs/tf.summary.cs View File

@@ -16,11 +16,11 @@

namespace Tensorflow
{
public static partial class tf
public partial class tensorflow
{
public static Summaries.Summary summary = new Summaries.Summary();
public Summaries.Summary summary = new Summaries.Summary();

public static Tensor scalar(string name, Tensor tensor)
public Tensor scalar(string name, Tensor tensor)
=> summary.scalar(name, tensor);
}
}

+ 4
- 4
src/TensorFlowNET.Core/APIs/tf.tensor.cs View File

@@ -16,12 +16,12 @@

namespace Tensorflow
{
public static partial class tf
public partial class tensorflow
{
public static Tensor convert_to_tensor(object value,
public Tensor convert_to_tensor(object value,
string name = null) => ops.convert_to_tensor(value, name: name);

public static Tensor strided_slice(Tensor input, Tensor begin, Tensor end, Tensor strides = null,
public Tensor strided_slice(Tensor input, Tensor begin, Tensor end, Tensor strides = null,
int begin_mask = 0,
int end_mask = 0,
int ellipsis_mask = 0,
@@ -38,7 +38,7 @@ namespace Tensorflow
shrink_axis_mask: shrink_axis_mask,
name: name);

public static Tensor strided_slice<T>(Tensor input, T[] begin, T[] end, T[] strides = null,
public Tensor strided_slice<T>(Tensor input, T[] begin, T[] end, T[] strides = null,
int begin_mask = 0,
int end_mask = 0,
int ellipsis_mask = 0,


+ 3
- 3
src/TensorFlowNET.Core/APIs/tf.tile.cs View File

@@ -18,12 +18,12 @@ using NumSharp;

namespace Tensorflow
{
public static partial class tf
public partial class tensorflow
{
public static Tensor tile(Tensor input,
public Tensor tile(Tensor input,
Tensor multiples,
string name = null) => gen_array_ops.tile(input, multiples, name);
public static Tensor tile(NDArray input,
public Tensor tile(NDArray input,
int[] multiples,
string name = null) => gen_array_ops.tile(input, multiples, name);



+ 4
- 4
src/TensorFlowNET.Core/APIs/tf.variable.cs View File

@@ -18,21 +18,21 @@ using System.Collections.Generic;

namespace Tensorflow
{
public static partial class tf
public partial class tensorflow
{
public static VariableV1[] global_variables(string scope = null)
public VariableV1[] global_variables(string scope = null)
{
return (ops.get_collection(ops.GraphKeys.GLOBAL_VARIABLES, scope) as List<VariableV1>)
.ToArray();
}

public static Operation global_variables_initializer()
public Operation global_variables_initializer()
{
var g = variables.global_variables();
return variables.variables_initializer(g.ToArray());
}

public static RefVariable get_variable(string name,
public RefVariable get_variable(string name,
TensorShape shape = null,
TF_DataType dtype = TF_DataType.DtInvalid,
object initializer = null, // IInitializer or Tensor


src/TensorFlowNET.Core/Python.cs → src/TensorFlowNET.Core/Binding.Util.cs View File

@@ -15,7 +15,6 @@
******************************************************************************/

using NumSharp;
using NumSharp.Backends;
using System;
using System.Collections;
using System.Collections.Generic;
@@ -26,18 +25,15 @@ using System.Linq;
namespace Tensorflow
{
/// <summary>
/// Mapping C# functions to Python
/// Binding utilities to mimic python functions.
/// </summary>
public static class Python
public static partial class Binding
{
public static void print(object obj)
{
Console.WriteLine(obj.ToString());
}

//protected int len<T>(IEnumerable<T> a)
// => a.Count();

public static int len(object a)
{
switch (a)
@@ -66,17 +62,15 @@ namespace Tensorflow
return Enumerable.Range(start, end - start);
}

public static T New<T>(object args) where T : IPyClass
public static T New<T>() where T : IObjectLife, new()
{
var instance = Activator.CreateInstance<T>();

instance.__init__(instance, args);

var instance = new T();
instance.__init__();
return instance;
}

[DebuggerNonUserCode()] // with "Just My Code" enabled this lets the debugger break at the origin of the exception
public static void tf_with(IPython py, Action<IPython> action)
public static void tf_with(IObjectLife py, Action<IObjectLife> action)
{
try
{
@@ -96,7 +90,7 @@ namespace Tensorflow
}

[DebuggerNonUserCode()] // with "Just My Code" enabled this lets the debugger break at the origin of the exception
public static void tf_with<T>(T py, Action<T> action) where T : IPython
public static void tf_with<T>(T py, Action<T> action) where T : IObjectLife
{
try
{
@@ -116,7 +110,7 @@ namespace Tensorflow
}

[DebuggerNonUserCode()] // with "Just My Code" enabled this lets the debugger break at the origin of the exception
public static TOut tf_with<TIn, TOut>(TIn py, Func<TIn, TOut> action) where TIn : IPython
public static TOut tf_with<TIn, TOut>(TIn py, Func<TIn, TOut> action) where TIn : IObjectLife
{
try
{
@@ -126,7 +120,6 @@ namespace Tensorflow
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
throw;
return default(TOut);
}
finally
@@ -278,7 +271,9 @@ namespace Tensorflow
var __memberobject__ = __type__.GetMember(key);
return (__memberobject__.Length > 0) ? true : false;
}

public delegate object __object__(params object[] args);

public static __object__ getattr(object obj, string key, params Type[] ___parameter_type__)
{
var __dyn_obj__ = obj.GetType().GetMember(key);
@@ -290,7 +285,7 @@ namespace Tensorflow
try
{
var __method__ = (___parameter_type__.Length > 0) ? obj.GetType().GetMethod(key, ___parameter_type__) : obj.GetType().GetMethod(key);
return (__object__)((object[] args) => __method__.Invoke(obj, args));
return (object[] args) => __method__.Invoke(obj, args);
}
catch (System.Reflection.AmbiguousMatchException ex)
{
@@ -299,27 +294,48 @@ namespace Tensorflow
}
else if (__type__.MemberType == System.Reflection.MemberTypes.Field)
{
var __field__ = (object)obj.GetType().GetField(key).GetValue(obj);
return (__object__)((object[] args) => { return __field__; });
var __field__ = obj.GetType().GetField(key).GetValue(obj);
return (object[] args) => { return __field__; };
}
else if (__type__.MemberType == System.Reflection.MemberTypes.Property)
{
var __property__ = (object)obj.GetType().GetProperty(key).GetValue(obj);
return (__object__)((object[] args) => { return __property__; });
var __property__ = obj.GetType().GetProperty(key).GetValue(obj);
return (object[] args) => { return __property__; };
}
return (__object__)((object[] args) => { return "NaN"; });
return (object[] args) => { return "NaN"; };
}
}

public interface IPython : IDisposable
{
void __enter__();
public static IEnumerable TupleToEnumerable(object tuple)
{
Type t = tuple.GetType();
if(t.IsGenericType && (t.FullName.StartsWith("System.Tuple") || t.FullName.StartsWith("System.ValueTuple")))
{
var flds = t.GetFields();
for(int i = 0; i < flds.Length;i++)
{
yield return flds[i].GetValue(tuple);
}
}
else
{
throw new System.Exception("Expected Tuple.");
}
}

void __exit__();
}
public static bool isinstance(object Item1, Type Item2)
{
return Item1.GetType() == Item2;
}

public class PyObject<T> where T : IPyClass
{
public T Instance { get; set; }
public static bool isinstance(object Item1, object tuple)
{
var tup = TupleToEnumerable(tuple);
foreach(var t in tup)
{
if(isinstance(Item1, (Type)t))
return true;
}
return false;
}
}
}

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

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

namespace Tensorflow
{
public static partial class Binding
{
public static tensorflow tf { get; } = New<tensorflow>();
}
}

+ 1
- 0
src/TensorFlowNET.Core/Clustering/KMeans.cs View File

@@ -15,6 +15,7 @@
******************************************************************************/

using System;
using static Tensorflow.Binding;

namespace Tensorflow.Clustering
{


+ 1
- 1
src/TensorFlowNET.Core/Clustering/_InitializeClustersOpFactory.cs View File

@@ -15,7 +15,7 @@
******************************************************************************/

using System.Linq;
using static Tensorflow.Python;
using static Tensorflow.Binding;

namespace Tensorflow.Clustering
{


+ 1
- 1
src/TensorFlowNET.Core/Framework/graph_util_impl.cs View File

@@ -18,7 +18,7 @@ using NumSharp;
using System;
using System.Collections.Generic;
using System.Linq;
using static Tensorflow.Python;
using static Tensorflow.Binding;

namespace Tensorflow
{


+ 1
- 1
src/TensorFlowNET.Core/Framework/importer.py.cs View File

@@ -19,7 +19,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
using static Tensorflow.OpDef.Types;
using static Tensorflow.Python;
using static Tensorflow.Binding;

namespace Tensorflow
{


+ 1
- 0
src/TensorFlowNET.Core/Framework/meta_graph.py.cs View File

@@ -22,6 +22,7 @@ using System.Linq;
using Tensorflow.Operations;
using static Tensorflow.CollectionDef;
using static Tensorflow.MetaGraphDef.Types;
using static Tensorflow.Binding;

namespace Tensorflow
{


+ 7
- 1
src/TensorFlowNET.Core/Gradients/array_grad.cs View File

@@ -17,7 +17,7 @@
using System.Collections.Generic;
using System.Linq;
using Tensorflow.Framework;
using static Tensorflow.Python;
using static Tensorflow.Binding;

namespace Tensorflow.Gradients
{
@@ -196,6 +196,12 @@ namespace Tensorflow.Gradients
return new Tensor[] { _ReshapeToInput(op, grads[0]) };
}

[RegisterGradient("StopGradient")]
public static Tensor[] _NoGradient(Operation op, Tensor[] grads)
{
return new Tensor[] {null};
}

/// <summary>
/// Gradient for StridedSlice op.
/// </summary>


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

@@ -17,7 +17,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using static Tensorflow.Python;
using static Tensorflow.Binding;

namespace Tensorflow
{


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

@@ -17,7 +17,7 @@
using System;
using System.Linq;
using Tensorflow.Operations;
using static Tensorflow.Python;
using static Tensorflow.Binding;

namespace Tensorflow.Gradients
{


+ 1
- 0
src/TensorFlowNET.Core/Graphs/DefaultGraphStack.cs View File

@@ -16,6 +16,7 @@

using System.Collections.Generic;
using System.Linq;
using static Tensorflow.Binding;

namespace Tensorflow
{


+ 1
- 0
src/TensorFlowNET.Core/Graphs/Graph.Operation.cs View File

@@ -18,6 +18,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using static Tensorflow.Binding;

namespace Tensorflow
{


+ 2
- 1
src/TensorFlowNET.Core/Graphs/Graph.cs View File

@@ -19,6 +19,7 @@ using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using static Tensorflow.Binding;

namespace Tensorflow
{
@@ -247,7 +248,7 @@ namespace Tensorflow
if (inputs == null)
inputs = new Tensor[0];

foreach ((int idx, Tensor a) in Python.enumerate(inputs))
foreach ((int idx, Tensor a) in enumerate(inputs))
{

}


+ 12
- 2
src/TensorFlowNET.Core/Graphs/_ControlDependenciesController.cs View File

@@ -22,7 +22,7 @@ namespace Tensorflow
/// <summary>
/// Context manager for `control_dependencies()`
/// </summary>
public class _ControlDependenciesController : IPython
public class _ControlDependenciesController : IObjectLife
{
private Graph _graph;
private List<ITensorOrOperation> _control_inputs_val;
@@ -110,6 +110,16 @@ namespace Tensorflow
public void Dispose()
{
}
}
public void __init__()
{
}
public void __del__()
{
}
}
}

src/TensorFlowNET.Core/IPyClass.cs → src/TensorFlowNET.Core/IObjectLife.cs View File

@@ -14,20 +14,22 @@
limitations under the License.
******************************************************************************/

using System;

namespace Tensorflow
{
public interface IPyClass
public interface IObjectLife : IDisposable
{
/// <summary>
/// Called when the instance is created.
/// </summary>
/// <param name="args"></param>
void __init__(IPyClass self, dynamic args);
void __init__();

void __enter__(IPyClass self);
void __enter__();

void __exit__(IPyClass self);
void __exit__();

void __del__(IPyClass self);
void __del__();
}
}

+ 3
- 2
src/TensorFlowNET.Core/Keras/BackendBase.cs View File

@@ -15,6 +15,7 @@
******************************************************************************/

using System;
using static Tensorflow.Binding;

namespace Tensorflow.Keras
{
@@ -43,9 +44,9 @@ namespace Tensorflow.Keras
{
if (value == null)
value = _IMAGE_DATA_FORMAT;
if (value.GetType() == typeof(ImageDataFormat))
if (isinstance(value, typeof(ImageDataFormat)))
return (ImageDataFormat)value;
else if (value.GetType() == typeof(string))
else if (isinstance(value, typeof(string)))
{
ImageDataFormat dataFormat;
if(Enum.TryParse((string)value, true, out dataFormat))


+ 11
- 1
src/TensorFlowNET.Core/Keras/Engine/Sequential.cs View File

@@ -18,7 +18,7 @@ using Tensorflow.Keras.Layers;

namespace Tensorflow.Keras.Engine
{
public class Sequential : Model, IPython
public class Sequential : Model, IObjectLife
{
public Sequential(string name = null)
: base(name: name)
@@ -69,5 +69,15 @@ namespace Tensorflow.Keras.Engine
{

}

public void __init__()
{
}

public void __del__()
{
}
}
}

+ 3
- 2
src/TensorFlowNET.Core/Keras/Layers/BatchNormalization.cs View File

@@ -17,6 +17,7 @@
using System;
using System.Linq;
using Tensorflow.Keras.Utils;
using static Tensorflow.Binding;

namespace Tensorflow.Keras.Layers
{
@@ -82,7 +83,7 @@ namespace Tensorflow.Keras.Layers
protected override void build(TensorShape input_shape)
{
var ndims = input_shape.ndim;
foreach (var (idx, x) in Python.enumerate(axis))
foreach (var (idx, x) in enumerate(axis))
if (x < 0)
axis[idx] = ndims + x;

@@ -207,7 +208,7 @@ namespace Tensorflow.Keras.Layers

public Tensor _assign_moving_average(RefVariable variable, Tensor value, Tensor momentum)
{
return Python.tf_with(ops.name_scope(null, "AssignMovingAvg", new { variable, value, momentum }), scope =>
return tf_with(ops.name_scope(null, "AssignMovingAvg", new { variable, value, momentum }), scope =>
{
// var cm = ops.colocate_with(variable);
var decay = ops.convert_to_tensor(1.0f - momentum, name: "decay");


+ 2
- 2
src/TensorFlowNET.Core/Keras/Layers/Dense.cs View File

@@ -19,7 +19,7 @@ using System.Collections.Generic;
using System.Linq;
using Tensorflow.Keras.Engine;
using Tensorflow.Operations.Activation;
using static Tensorflow.tf;
using static Tensorflow.Binding;

namespace Tensorflow.Keras.Layers
{
@@ -86,7 +86,7 @@ namespace Tensorflow.Keras.Layers
}

if (use_bias)
outputs = nn.bias_add(outputs, bias);
outputs = tf.nn.bias_add(outputs, bias);
if (activation != null)
return activation.Activate(outputs);



+ 2
- 0
src/TensorFlowNET.Core/Keras/Layers/Embedding.cs View File

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

using static Tensorflow.Binding;

namespace Tensorflow.Keras.Layers
{
public class Embedding : Layer


+ 1
- 1
src/TensorFlowNET.Core/Keras/Layers/Layer.cs View File

@@ -20,7 +20,7 @@ using System.Linq;
using Tensorflow.Keras.Engine;
using Tensorflow.Keras.Utils;
using Tensorflow.Train;
using static Tensorflow.Python;
using static Tensorflow.Binding;

namespace Tensorflow.Keras.Layers
{


+ 2
- 2
src/TensorFlowNET.Core/Keras/Layers/MaxPooling2D.cs View File

@@ -1,4 +1,4 @@
using static Tensorflow.tf;
using static Tensorflow.Binding;

namespace Tensorflow.Keras.Layers
{
@@ -9,7 +9,7 @@ namespace Tensorflow.Keras.Layers
int[] strides,
string padding = "valid",
string data_format = null,
string name = null) : base(nn.max_pool_fn, pool_size,
string name = null) : base(tf.nn.max_pool_fn, pool_size,
strides,
padding: padding,
data_format: data_format,


+ 1
- 0
src/TensorFlowNET.Core/Keras/Utils/base_layer_utils.cs View File

@@ -17,6 +17,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using static Tensorflow.Binding;

namespace Tensorflow.Keras.Utils
{


+ 2
- 2
src/TensorFlowNET.Core/Keras/backend.cs View File

@@ -16,7 +16,7 @@

using System;
using System.Collections.Generic;
using static Tensorflow.Python;
using static Tensorflow.Binding;

namespace Tensorflow.Keras
{
@@ -28,7 +28,7 @@ namespace Tensorflow.Keras
//Func<Array, bool> py_any = any;
//Func<double, double, double, IEnumerable<double>> py_slice = slice;

public static Session _SESSION = Tensorflow.tf.defaultSession;
public static Session _SESSION = tf.defaultSession;
public static Graph _GRAPH = null;
public static Dictionary<Graph, GraphLearningPhase> _GRAPH_LEARNING_PHASES;
//Dictionary<Graph, Dictionary<string, int>> PER_GRAPH_LAYER_NAME_UIDS;


+ 2
- 2
src/TensorFlowNET.Core/Keras/tf.keras.cs View File

@@ -2,9 +2,9 @@

namespace Tensorflow
{
public static partial class tf
public partial class tensorflow
{
public static class keras
public class keras
{
public static Initializers initializers => new Initializers();
}


+ 1
- 1
src/TensorFlowNET.Core/Layers/Layer.cs View File

@@ -16,7 +16,7 @@

using System;
using System.Collections.Generic;
using static Tensorflow.Python;
using static Tensorflow.Binding;

namespace Tensorflow.Layers
{


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

@@ -18,7 +18,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
using Tensorflow.Operations.ControlFlows;
using static Tensorflow.Python;
using static Tensorflow.Binding;

namespace Tensorflow.Operations
{


+ 10
- 1
src/TensorFlowNET.Core/Operations/ControlFlows/ControlFlowContext.cs View File

@@ -39,7 +39,7 @@ namespace Tensorflow.Operations
/// 4. A ControlFlowContext has _context_stack.
/// Pushed and popped by ctxt.Enter() and ctxt.Exit()
/// </summary>
public abstract class ControlFlowContext : IPython
public abstract class ControlFlowContext : IObjectLife
{
/// <summary>
/// The predicate tensor in this branch
@@ -265,5 +265,14 @@ namespace Tensorflow.Operations
{
}

public void __init__()
{
}

public void __del__()
{
}
}
}

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

@@ -19,8 +19,8 @@ using System.Collections.Generic;
using System.Linq;
using Tensorflow.Operations.ControlFlows;
using Tensorflow.Util;
using static Tensorflow.Python;
using static Tensorflow.control_flow_ops;
using static Tensorflow.Binding;

namespace Tensorflow.Operations
{


+ 1
- 1
src/TensorFlowNET.Core/Operations/Distributions/distribution.py.cs View File

@@ -17,7 +17,7 @@
//Base classes for probability distributions.
using System;
using System.Collections.Generic;
using static Tensorflow.Python;
using static Tensorflow.Binding;


namespace Tensorflow


+ 1
- 1
src/TensorFlowNET.Core/Operations/Distributions/normal.py.cs View File

@@ -16,7 +16,7 @@

using System;
using System.Collections.Generic;
using static Tensorflow.Python;
using static Tensorflow.Binding;

namespace Tensorflow
{


+ 1
- 1
src/TensorFlowNET.Core/Operations/Losses/losses_impl.py.cs View File

@@ -15,7 +15,7 @@
******************************************************************************/

using System;
using static Tensorflow.Python;
using static Tensorflow.Binding;

namespace Tensorflow
{


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

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

using static Tensorflow.Python;
using static Tensorflow.Binding;

namespace Tensorflow.Operations
{


+ 1
- 2
src/TensorFlowNET.Core/Operations/NnOps/rnn.cs View File

@@ -17,9 +17,8 @@
using System;
using System.Collections.Generic;
using System.Linq;
using static Tensorflow.Python;
using Tensorflow.Util;
using NumSharp;
using static Tensorflow.Binding;

namespace Tensorflow.Operations
{


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

@@ -18,7 +18,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
using static Tensorflow.OpDef.Types;
using static Tensorflow.Python;
using static Tensorflow.Binding;

namespace Tensorflow
{
@@ -141,7 +141,7 @@ namespace Tensorflow
dtype = input_arg.Type;
else if (attrs.ContainsKey(input_arg.TypeAttr))
dtype = (DataType)attrs[input_arg.TypeAttr];
else if (values.GetType() == typeof(string) && dtype == DataType.DtInvalid)
else if (isinstance(values, typeof(string)) && dtype == DataType.DtInvalid)
dtype = DataType.DtString;
else if (default_type_attr_map.ContainsKey(input_arg.TypeAttr))
default_dtype = (DataType)default_type_attr_map[input_arg.TypeAttr];


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

@@ -17,7 +17,7 @@
using System;
using Tensorflow.Operations;
using Tensorflow.Util;
using static Tensorflow.Python;
using static Tensorflow.Binding;

namespace Tensorflow
{


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

@@ -17,7 +17,7 @@
using System;
using System.Collections.Generic;
using System.Text;
using static Tensorflow.Python;
using static Tensorflow.Binding;

namespace Tensorflow.Operations
{


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

@@ -17,7 +17,7 @@
using NumSharp;
using System;
using System.Collections.Generic;
using static Tensorflow.Python;
using static Tensorflow.Binding;
namespace Tensorflow
{


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

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

using static Tensorflow.Python;
using static Tensorflow.Binding;

namespace Tensorflow
{


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

@@ -15,7 +15,7 @@
******************************************************************************/

using System;
using static Tensorflow.Python;
using static Tensorflow.Binding;

namespace Tensorflow
{


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

@@ -20,7 +20,7 @@ using System.Linq;
using Tensorflow.Operations;
using Tensorflow.Operations.ControlFlows;
using util = Tensorflow.control_flow_util;
using static Tensorflow.Python;
using static Tensorflow.Binding;

namespace Tensorflow
{


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

@@ -15,7 +15,7 @@
******************************************************************************/

using System;
using static Tensorflow.Python;
using static Tensorflow.Binding;

namespace Tensorflow
{


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

@@ -15,7 +15,7 @@
******************************************************************************/

using System;
using static Tensorflow.Python;
using static Tensorflow.Binding;

namespace Tensorflow
{


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

@@ -18,7 +18,7 @@ using NumSharp;
using System;
using System.Collections.Generic;
using Tensorflow.Framework;
using static Tensorflow.Python;
using static Tensorflow.Binding;

namespace Tensorflow
{


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

@@ -15,7 +15,7 @@
******************************************************************************/

using Tensorflow.Operations;
using static Tensorflow.Python;
using static Tensorflow.Binding;

namespace Tensorflow
{


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

@@ -17,7 +17,7 @@
using System;
using System.Linq;
using Tensorflow.Operations;
using static Tensorflow.Python;
using static Tensorflow.Binding;

namespace Tensorflow
{
@@ -50,7 +50,7 @@ namespace Tensorflow
string data_format = null,
string name = null)
{
return Python.tf_with(ops.name_scope(name, "BiasAdd", new { value, bias }), scope =>
return tf_with(ops.name_scope(name, "BiasAdd", new { value, bias }), scope =>
{
name = scope;
value = ops.convert_to_tensor(value, name: "input");


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

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

using static Tensorflow.Python;
using static Tensorflow.Binding;

namespace Tensorflow
{


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

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

using static Tensorflow.Python;
using static Tensorflow.Binding;

namespace Tensorflow
{


+ 12
- 2
src/TensorFlowNET.Core/Sessions/Session.cs View File

@@ -15,11 +15,11 @@
******************************************************************************/

using System;
using System.Runtime.InteropServices;
using static Tensorflow.Binding;

namespace Tensorflow
{
public class Session : BaseSession, IPython
public class Session : BaseSession, IObjectLife
{
public Session(string target = "", Graph g = null)
: base(target, g, null)
@@ -85,5 +85,15 @@ namespace Tensorflow
{

}

public void __init__()
{
}

public void __del__()
{
}
}
}

+ 1
- 1
src/TensorFlowNET.Core/Summaries/Summary.cs View File

@@ -16,7 +16,7 @@

using System.Collections.Generic;
using System.Linq;
using static Tensorflow.Python;
using static Tensorflow.Binding;

namespace Tensorflow.Summaries
{


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

@@ -16,7 +16,7 @@

using System;
using System.Linq;
using static Tensorflow.Python;
using static Tensorflow.Binding;

namespace Tensorflow
{


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

@@ -21,7 +21,7 @@ using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using Tensorflow.Framework;
using static Tensorflow.Python;
using static Tensorflow.Binding;

namespace Tensorflow
{


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

@@ -16,6 +16,7 @@

using System;
using System.Collections.Generic;
using static Tensorflow.Binding;

namespace Tensorflow
{


+ 9
- 9
src/TensorFlowNET.Core/Tensors/tf.constant.cs View File

@@ -18,11 +18,11 @@ using NumSharp;

namespace Tensorflow
{
public static partial class tf
public partial class tensorflow
{
// public static Tensor constant(NDArray nd, string name = "Const") => constant_op.constant(nd, name: name);

public static Tensor constant(object value,
public Tensor constant(object value,
TF_DataType dtype = TF_DataType.DtInvalid,
int[] shape = null,
string name = "Const",
@@ -33,30 +33,30 @@ namespace Tensorflow
verify_shape: verify_shape,
allow_broadcast: false);

public static Tensor constant(string value,
public Tensor constant(string value,
string name = "Const") => constant_op._constant_impl(value,
tf.@string,
@string,
new int[] { 1 },
name,
verify_shape: false,
allow_broadcast: false);

public static Tensor constant(float value,
public Tensor constant(float value,
int shape,
string name = "Const") => constant_op._constant_impl(value,
tf.float32,
float32,
new int[] { shape },
name,
verify_shape: false,
allow_broadcast: false);

public static Tensor zeros(TensorShape shape, TF_DataType dtype = TF_DataType.TF_FLOAT, string name = null)
public Tensor zeros(TensorShape shape, TF_DataType dtype = TF_DataType.TF_FLOAT, string name = null)
=> array_ops.zeros(shape, dtype, name);

public static Tensor ones(TensorShape shape, TF_DataType dtype = TF_DataType.TF_FLOAT, string name = null)
public Tensor ones(TensorShape shape, TF_DataType dtype = TF_DataType.TF_FLOAT, string name = null)
=> array_ops.ones(shape, dtype, name);

public static Tensor size(Tensor input,
public Tensor size(Tensor input,
string name = null,
TF_DataType out_type = TF_DataType.TF_INT32) => array_ops.size(input,
name,


+ 1
- 1
src/TensorFlowNET.Core/Train/AdamOptimizer.cs View File

@@ -18,7 +18,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
using Tensorflow.Framework;
using static Tensorflow.Python;
using static Tensorflow.Binding;

namespace Tensorflow.Train
{


+ 2
- 2
src/TensorFlowNET.Core/Train/Optimizer.cs View File

@@ -19,7 +19,7 @@ using System.Collections.Generic;
using System.Linq;
using Tensorflow.Framework;
using Tensorflow.Train;
using static Tensorflow.Python;
using static Tensorflow.Binding;

namespace Tensorflow
{
@@ -382,7 +382,7 @@ namespace Tensorflow
if ((int)gate_gradients == Optimizer.GATE_GRAPH)
grads = control_flow_ops.tuple(grads);

var grads_and_vars = Python.zip(grads, var_list)
var grads_and_vars = zip(grads, var_list)
.Select(x => new Tuple<Tensor, RefVariable>(x.Item1, x.Item2))
.ToArray();



+ 1
- 1
src/TensorFlowNET.Core/Train/Saving/BaseSaverBuilder.cs View File

@@ -18,7 +18,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
using Tensorflow.Operations;
using static Tensorflow.Python;
using static Tensorflow.Binding;

namespace Tensorflow
{


+ 2
- 2
src/TensorFlowNET.Core/Train/Saving/Saver.cs View File

@@ -18,7 +18,7 @@ using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using static Tensorflow.Python;
using static Tensorflow.Binding;

namespace Tensorflow
{
@@ -144,7 +144,7 @@ namespace Tensorflow

_check_saver_def();

_next_checkpoint_time = Python.time() + _saver_def.KeepCheckpointEveryNHours * 3600;
_next_checkpoint_time = time() + _saver_def.KeepCheckpointEveryNHours * 3600;
}

private void _check_saver_def()


+ 1
- 1
src/TensorFlowNET.Core/Train/Saving/saveable_object_util.py.cs View File

@@ -17,7 +17,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using static Tensorflow.Python;
using static Tensorflow.Binding;

namespace Tensorflow
{


+ 1
- 1
src/TensorFlowNET.Core/Train/SlotCreator.cs View File

@@ -16,7 +16,7 @@

using System;
using Tensorflow.Operations.Initializers;
using static Tensorflow.Python;
using static Tensorflow.Binding;

namespace Tensorflow.Train
{


+ 10
- 8
src/TensorFlowNET.Core/Train/tf.optimizers.cs View File

@@ -19,28 +19,30 @@ using Tensorflow.Train;

namespace Tensorflow
{
public static partial class tf
public partial class tensorflow
{
public static class train
public train_internal train { get; } = new train_internal();

public class train_internal
{
public static Optimizer GradientDescentOptimizer(float learning_rate)
public Optimizer GradientDescentOptimizer(float learning_rate)
=> new GradientDescentOptimizer(learning_rate);

public static Optimizer AdamOptimizer(float learning_rate, string name = "Adam")
public Optimizer AdamOptimizer(float learning_rate, string name = "Adam")
=> new AdamOptimizer(learning_rate, name: name);

public static Saver Saver(VariableV1[] var_list = null) => new Saver(var_list: var_list);
public Saver Saver(VariableV1[] var_list = null) => new Saver(var_list: var_list);

public static string write_graph(Graph graph, string logdir, string name, bool as_text = true)
public string write_graph(Graph graph, string logdir, string name, bool as_text = true)
=> graph_io.write_graph(graph, logdir, name, as_text);

public static Saver import_meta_graph(string meta_graph_or_file,
public Saver import_meta_graph(string meta_graph_or_file,
bool clear_devices = false,
string import_scope = "") => saver._import_meta_graph_with_return_elements(meta_graph_or_file,
clear_devices,
import_scope).Item1;

public static (MetaGraphDef, Dictionary<string, RefVariable>) export_meta_graph(string filename = "",
public (MetaGraphDef, Dictionary<string, RefVariable>) export_meta_graph(string filename = "",
bool as_text = false,
bool clear_devices = false,
bool clear_extraneous_savers = false,


+ 2
- 2
src/TensorFlowNET.Core/Util/nest.py.cs View File

@@ -79,10 +79,10 @@ namespace Tensorflow.Util
}
public static IEnumerable<(T1, T2)> zip<T1, T2>(IEnumerable<T1> e1, IEnumerable<T2> e2)
=> Python.zip(e1, e2);
=> zip(e1, e2);
public static Dictionary<string, object> ConvertToDict(object dyn)
=> Python.ConvertToDict(dyn);
=> ConvertToDict(dyn);
//def _get_attrs_values(obj):
// """Returns the list of values from an attrs instance."""


+ 11
- 1
src/TensorFlowNET.Core/Variables/PureVariableScope.cs View File

@@ -19,7 +19,7 @@ using System.Linq;

namespace Tensorflow
{
public class PureVariableScope : IPython
public class PureVariableScope : IObjectLife
{
private string _name;
private VariableScope _scope;
@@ -101,6 +101,16 @@ namespace Tensorflow
_var_scope_store.current_scope = _old;
}

public void __init__()
{
}

public void __del__()
{
}

public static implicit operator VariableScope(PureVariableScope scope)
{
return scope.variable_scope_object;


+ 1
- 1
src/TensorFlowNET.Core/Variables/RefVariable.Operators.cs View File

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

using static Tensorflow.Python;
using static Tensorflow.Binding;

namespace Tensorflow
{


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

@@ -17,7 +17,7 @@
using Google.Protobuf;
using System;
using System.Collections.Generic;
using static Tensorflow.Python;
using static Tensorflow.Binding;

namespace Tensorflow
{


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

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

using static Tensorflow.Python;
using static Tensorflow.Binding;

namespace Tensorflow
{


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

@@ -16,6 +16,7 @@

using System;
using System.Collections.Generic;
using static Tensorflow.Binding;

namespace Tensorflow
{


+ 11
- 1
src/TensorFlowNET.Core/Variables/variable_scope.py.cs View File

@@ -23,7 +23,7 @@ namespace Tensorflow
/// <summary>
/// A context manager for defining ops that creates variables (layers).
/// </summary>
public class variable_scope : IPython
public class variable_scope : IObjectLife
{
public static string _VARSTORE_KEY = "__variable_store";
public static string _VARSCOPESTORE_KEY = "__varscope";
@@ -293,5 +293,15 @@ namespace Tensorflow
{
throw new NotImplementedException();
}

public void __init__()
{
}

public void __del__()
{
}
}
}

+ 13
- 3
src/TensorFlowNET.Core/ops._DefaultStack.cs View File

@@ -23,7 +23,7 @@ namespace Tensorflow
{
_DefaultStack _default_session_stack = new _DefaultStack();

public class _DefaultStack : IPython
public class _DefaultStack : IObjectLife
{
Stack<object> stack;
bool _enforce_nesting = true;
@@ -35,18 +35,28 @@ namespace Tensorflow

public void __enter__()
{
throw new NotImplementedException();
}

public void __exit__()
{
throw new NotImplementedException();
}

public void Dispose()
{
throw new NotImplementedException();
}

public void __init__()
{
}

public void __del__()
{
}
}
}
}

src/TensorFlowNET.Core/ops.py.cs → src/TensorFlowNET.Core/ops.cs View File

@@ -20,7 +20,7 @@ using System.Runtime.InteropServices;
using Google.Protobuf;
using System.Linq;
using NumSharp;
using static Tensorflow.Python;
using static Tensorflow.Binding;

namespace Tensorflow
{
@@ -447,7 +447,7 @@ namespace Tensorflow
{
var ret = new List<Tensor>();

foreach(var (i, value) in Python.enumerate(values))
foreach(var (i, value) in enumerate(values))
{
if (value == null)
{

+ 11
- 1
src/TensorFlowNET.Core/ops.name_scope.cs View File

@@ -27,7 +27,7 @@ namespace Tensorflow
/// <summary>
/// Returns a context manager that creates hierarchical names for operations.
/// </summary>
public class NameScope : IPython
public class NameScope : IObjectLife
{
public string _name;
public string _default_name;
@@ -70,6 +70,16 @@ namespace Tensorflow
{
}

public void __init__()
{
}

public void __del__()
{
}

/// <summary>
/// __enter__()
/// </summary>


src/TensorFlowNET.Core/tf.cs → src/TensorFlowNET.Core/tensorflow.cs View File

@@ -18,25 +18,25 @@ using Tensorflow.Eager;

namespace Tensorflow
{
public static partial class tf
public partial class tensorflow : IObjectLife
{
public static TF_DataType @byte = TF_DataType.TF_UINT8;
public static TF_DataType @sbyte = TF_DataType.TF_INT8;
public static TF_DataType int16 = TF_DataType.TF_INT16;
public static TF_DataType int32 = TF_DataType.TF_INT32;
public static TF_DataType int64 = TF_DataType.TF_INT64;
public static TF_DataType float16 = TF_DataType.TF_HALF;
public static TF_DataType float32 = TF_DataType.TF_FLOAT;
public static TF_DataType float64 = TF_DataType.TF_DOUBLE;
public static TF_DataType @bool = TF_DataType.TF_BOOL;
public static TF_DataType chars = TF_DataType.TF_STRING;
public static TF_DataType @string = TF_DataType.TF_STRING;
public static Context context = new Context(new ContextOptions(), new Status());
public static Session defaultSession;
public static RefVariable Variable<T>(T data,
public TF_DataType @byte = TF_DataType.TF_UINT8;
public TF_DataType @sbyte = TF_DataType.TF_INT8;
public TF_DataType int16 = TF_DataType.TF_INT16;
public TF_DataType int32 = TF_DataType.TF_INT32;
public TF_DataType int64 = TF_DataType.TF_INT64;
public TF_DataType float16 = TF_DataType.TF_HALF;
public TF_DataType float32 = TF_DataType.TF_FLOAT;
public TF_DataType float64 = TF_DataType.TF_DOUBLE;
public TF_DataType @bool = TF_DataType.TF_BOOL;
public TF_DataType chars = TF_DataType.TF_STRING;
public TF_DataType @string = TF_DataType.TF_STRING;
public Context context = new Context(new ContextOptions(), new Status());
public Session defaultSession;
public RefVariable Variable<T>(T data,
bool trainable = true,
bool validate_shape = true,
string name = null,
@@ -49,33 +49,58 @@ namespace Tensorflow
dtype: dtype);
}

public static unsafe Tensor placeholder(TF_DataType dtype, TensorShape shape = null, string name = null)
public unsafe Tensor placeholder(TF_DataType dtype, TensorShape shape = null, string name = null)
{
return gen_array_ops.placeholder(dtype, shape, name);
}

public static void enable_eager_execution()
public void enable_eager_execution()
{
// contex = new Context();
context.default_execution_mode = Context.EAGER_MODE;
}

public static string VERSION => c_api.StringPiece(c_api.TF_Version());
public string VERSION => c_api.StringPiece(c_api.TF_Version());

public static Session Session()
public Session Session()
{
defaultSession = new Session();
return defaultSession;
}

public static Session Session(Graph graph)
public Session Session(Graph graph)
{
return new Session(graph);
}

public static Session Session(SessionOptions opts)
public Session Session(SessionOptions opts)
{
return new Session(null, opts);
}

public void __init__()
{
}

public void __enter__()
{
}

public void __exit__()
{
}

public void __del__()
{
}

public void Dispose()
{
}
}
}

+ 1
- 0
src/TensorFlowNet.Benchmarks/TensorBenchmark.cs View File

@@ -2,6 +2,7 @@
using BenchmarkDotNet.Attributes;
using NumSharp;
using Tensorflow;
using static Tensorflow.Binding;
namespace TensorFlowBenchmark
{


+ 2
- 2
test/TensorFlowNET.Examples.FSharp/FunctionApproximation.fs View File

@@ -6,7 +6,6 @@ open NumSharp
open Tensorflow
open System


let run()=
let N_points = 75 // Number of points for constructing function
@@ -40,6 +39,7 @@ let run()=
let n_hidden_layer_1 = 25 // Hidden layer 1
let n_hidden_layer_2 = 25 // Hidden layer 2

let tf = Binding.New<tensorflow>()
let x = tf.placeholder(tf.float64, new TensorShape(N_points,n_input))
let y = tf.placeholder(tf.float64, new TensorShape(n_output))
@@ -77,7 +77,7 @@ let run()=
let init = tf.global_variables_initializer()
Tensorflow.Python.``tf_with``(tf.Session(), fun (sess:Session) ->
Tensorflow.Binding.``tf_with``(tf.Session(), fun (sess:Session) ->
sess.run(init) |> ignore
// Loop over epochs
for epoch in [0..training_epochs] do


+ 1
- 0
test/TensorFlowNET.Examples/BasicEagerApi.cs View File

@@ -1,5 +1,6 @@
using System;
using Tensorflow;
using static Tensorflow.Binding;

namespace TensorFlowNET.Examples
{


Some files were not shown because too many files changed in this diff

Loading…
Cancel
Save