Browse Source

added OpDef for Operation

tags/v0.1.0-Tensor
Oceania2018 6 years ago
parent
commit
ff8f72a38e
5 changed files with 47 additions and 6 deletions
  1. +5
    -2
      src/TensorFlowNET.Core/Graph.cs
  2. +2
    -2
      src/TensorFlowNET.Core/OpDefLibrary.cs
  3. +21
    -1
      src/TensorFlowNET.Core/Operation.cs
  4. +7
    -1
      src/TensorFlowNET.Core/gen_array_ops.cs
  5. +12
    -0
      src/TensorFlowNET.Core/ops.cs

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

@@ -41,10 +41,13 @@ namespace TensorFlowNET.Core
name = op_type;
}

name = unique_name(name);
name = name.EndsWith("/") ? ops._name_from_scope_name(name) : unique_name(name);
var node_def = ops._NodeDef(op_type, name, device: "", attrs: attrs);

var op = new Operation(node_def, this, inputs, dtypes);
var op = new Operation(node_def, this,
inputs: inputs,
output_types: dtypes,
op_def: op_def);

return op;
}


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

@@ -86,8 +86,8 @@ namespace TensorFlowNET.Core
var op = g.create_op(op_type_name, null, output_types.ToArray(),
name: "Placeholder_1/",
input_types: new DataType[] { },
attrs: null,
op_def: null);
attrs: attr_protos,
op_def: op_def);

return op;
}


+ 21
- 1
src/TensorFlowNET.Core/Operation.cs View File

@@ -15,8 +15,9 @@ namespace TensorFlowNET.Core
public string name;
private Tensor[] _outputs;
public Tensor[] outputs => _outputs;
public Tensor[] inputs;

public Operation(NodeDef node_def, Graph g, object inputs = null, TF_DataType[] output_types = null, object control_inputs = null, TF_DataType[] input_types = null, string original_op = "", string op_def = "")
public Operation(NodeDef node_def, Graph g, object inputs = null, TF_DataType[] output_types = null, object control_inputs = null, TF_DataType[] input_types = null, string original_op = "", OpDef op_def = null)
{
_graph = g;

@@ -32,5 +33,24 @@ namespace TensorFlowNET.Core

_graph._add_op(this);
}

public object get_attr(string name)
{
object ret = null;

var fields = new string[] { "s", "i", "f", "b", "type", "shape", "tensor", "func" };

switch (name)
{
case "dtype":
ret = _outputs[0];
break;
case "shape":
ret = new TensorShapeProto();
break;
}

return ret;
}
}
}

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

@@ -12,7 +12,13 @@ namespace TensorFlowNET.Core

public static Tensor placeholder(DataType dtype, TensorShape shape = null)
{
var op = _op_def_lib._apply_op_helper("Placeholder", dtype: dtype, shape: shape);
var _op = _op_def_lib._apply_op_helper("Placeholder", dtype: dtype, shape: shape);
var _result = _op.outputs;
var _inputs_flat = _op.inputs;
var _attrs = new Dictionary<string, object>();

_attrs["dtype"] = _op.get_attr("dtype");
_attrs["shape"] = _op.get_attr("shape");

return null;
}


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

@@ -49,6 +49,18 @@ namespace TensorFlowNET.Core
return node_def;
}

public static string _name_from_scope_name(string name)
{
if (name.EndsWith("/"))
{
return name.Substring(0, name.Length - 1);
}
else
{
return name;
}
}

public static int uid()
{
return 1;


Loading…
Cancel
Save