Skip to content

Commit ff8f72a

Browse files
committed
added OpDef for Operation
1 parent b58cf9a commit ff8f72a

5 files changed

Lines changed: 47 additions & 6 deletions

File tree

src/TensorFlowNET.Core/Graph.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,13 @@ public unsafe Operation create_op(string op_type, object inputs, TF_DataType[] d
4141
name = op_type;
4242
}
4343

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

47-
var op = new Operation(node_def, this, inputs, dtypes);
47+
var op = new Operation(node_def, this,
48+
inputs: inputs,
49+
output_types: dtypes,
50+
op_def: op_def);
4851

4952
return op;
5053
}

src/TensorFlowNET.Core/OpDefLibrary.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ public unsafe Operation _apply_op_helper(string op_type_name, string name = "",
8686
var op = g.create_op(op_type_name, null, output_types.ToArray(),
8787
name: "Placeholder_1/",
8888
input_types: new DataType[] { },
89-
attrs: null,
90-
op_def: null);
89+
attrs: attr_protos,
90+
op_def: op_def);
9191

9292
return op;
9393
}

src/TensorFlowNET.Core/Operation.cs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ public class Operation
1515
public string name;
1616
private Tensor[] _outputs;
1717
public Tensor[] outputs => _outputs;
18+
public Tensor[] inputs;
1819

19-
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 = "")
20+
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)
2021
{
2122
_graph = g;
2223

@@ -32,5 +33,24 @@ public Operation(NodeDef node_def, Graph g, object inputs = null, TF_DataType[]
3233

3334
_graph._add_op(this);
3435
}
36+
37+
public object get_attr(string name)
38+
{
39+
object ret = null;
40+
41+
var fields = new string[] { "s", "i", "f", "b", "type", "shape", "tensor", "func" };
42+
43+
switch (name)
44+
{
45+
case "dtype":
46+
ret = _outputs[0];
47+
break;
48+
case "shape":
49+
ret = new TensorShapeProto();
50+
break;
51+
}
52+
53+
return ret;
54+
}
3555
}
3656
}

src/TensorFlowNET.Core/gen_array_ops.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,13 @@ public static class gen_array_ops
1212

1313
public static Tensor placeholder(DataType dtype, TensorShape shape = null)
1414
{
15-
var op = _op_def_lib._apply_op_helper("Placeholder", dtype: dtype, shape: shape);
15+
var _op = _op_def_lib._apply_op_helper("Placeholder", dtype: dtype, shape: shape);
16+
var _result = _op.outputs;
17+
var _inputs_flat = _op.inputs;
18+
var _attrs = new Dictionary<string, object>();
19+
20+
_attrs["dtype"] = _op.get_attr("dtype");
21+
_attrs["shape"] = _op.get_attr("shape");
1622

1723
return null;
1824
}

src/TensorFlowNET.Core/ops.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,18 @@ public static NodeDef _NodeDef(string op_type, string name, string device = "",
4949
return node_def;
5050
}
5151

52+
public static string _name_from_scope_name(string name)
53+
{
54+
if (name.EndsWith("/"))
55+
{
56+
return name.Substring(0, name.Length - 1);
57+
}
58+
else
59+
{
60+
return name;
61+
}
62+
}
63+
5264
public static int uid()
5365
{
5466
return 1;

0 commit comments

Comments
 (0)