Browse Source

RefVairable and Variable

tags/v0.1.0-Tensor
Oceania2018 6 years ago
parent
commit
8aa30b9ef6
5 changed files with 73 additions and 0 deletions
  1. +12
    -0
      src/TensorFlowNET.Core/Operations/ops.cs
  2. +24
    -0
      src/TensorFlowNET.Core/Tensors/RefVariable.cs
  3. +14
    -0
      src/TensorFlowNET.Core/Tensors/Variable.cs
  4. +6
    -0
      src/TensorFlowNET.Core/tf.cs
  5. +17
    -0
      test/TensorFlowNET.UnitTest/VariableTest.cs

+ 12
- 0
src/TensorFlowNET.Core/Operations/ops.cs View File

@@ -16,6 +16,18 @@ namespace Tensorflow
return tf.Graph();
}

public static Tensor convert_to_tensor()
{
return internal_convert_to_tensor();
}

private static Tensor internal_convert_to_tensor()
{
return null;
}



public static unsafe IntPtr _create_c_op(Graph graph, NodeDef node_def, List<Tensor> inputs)
{
var op_desc = c_api.TF_NewOperation(graph.Handle, node_def.Op, node_def.Name);


+ 24
- 0
src/TensorFlowNET.Core/Tensors/RefVariable.cs View File

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

namespace Tensorflow
{
public class RefVariable : Variable
{
public bool _in_graph_mode = true;

public RefVariable(object initial_value,
TF_DataType trainable,
bool validate_shape = true) :
base(initial_value, trainable, validate_shape)
{

}

private void _init_from_args()
{

}
}
}

+ 14
- 0
src/TensorFlowNET.Core/Tensors/Variable.cs View File

@@ -4,7 +4,21 @@ using System.Text;

namespace Tensorflow
{
/// <summary>
/// A variable maintains state in the graph across calls to `run()`. You add a
/// variable to the graph by constructing an instance of the class `Variable`.
///
/// The `Variable()` constructor requires an initial value for the variable,
/// which can be a `Tensor` of any type and shape. The initial value defines the
/// type and shape of the variable. After construction, the type and shape of
/// the variable are fixed. The value can be changed using one of the assign methods.
/// https://tensorflow.org/guide/variables
/// </summary>
public class Variable
{
public Variable(object initial_value, TF_DataType trainable, bool validate_shape = true)
{

}
}
}

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

@@ -11,11 +11,17 @@ namespace Tensorflow
public static class tf
{
public static TF_DataType float32 = TF_DataType.TF_FLOAT;
public static TF_DataType chars = TF_DataType.TF_STRING;

public static Context context = new Context();

public static Graph g = new Graph(c_api.TF_NewGraph());

public static object Variable<T>(T data, TF_DataType dtype)
{
return new Variable(null, TF_DataType.DtInvalid);
}

public static unsafe Tensor add(Tensor a, Tensor b)
{
return gen_math_ops.add(a, b);


+ 17
- 0
test/TensorFlowNET.UnitTest/VariableTest.cs View File

@@ -0,0 +1,17 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.Text;
using Tensorflow;

namespace TensorFlowNET.UnitTest
{
[TestClass]
public class VariableTest
{
public void Creating()
{
var mammal = tf.Variable("Elephant", tf.chars);
}
}
}

Loading…
Cancel
Save