Repository navigation
Expand file tree
/
Copy pathOperation.cs
More file actions
67 lines (55 loc) · 1.94 KB
/
Copy pathOperation.cs
File metadata and controls
67 lines (55 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
using System;
using System.Collections.Generic;
using System.Text;
using TF_DataType = Tensorflow.DataType;
namespace Tensorflow
{
public class Operation
{
private Graph _graph;
public Graph graph => _graph;
public IntPtr _c_op;
public int _id => _id_value;
private int _id_value;
public string name;
private Tensor[] _outputs;
public Tensor[] outputs => _outputs;
public Tensor[] inputs;
public Operation(Graph g, string opType, string oper_name)
{
_graph = g;
var status = new Status();
var desc = c_api.TF_NewOperation(g.Handle, opType, oper_name);
c_api.TF_SetAttrType(desc, "dtype", TF_DataType.TF_INT32);
c_api.TF_FinishOperation(desc, status.Handle);
}
public Operation(NodeDef node_def, Graph g, List<Tensor> 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;
_id_value = _graph._next_id();
_c_op = ops._create_c_op(g, node_def, inputs);
var num_outputs = c_api.TF_OperationNumOutputs(_c_op);
_outputs = new Tensor[num_outputs];
for (int i = 0; i < num_outputs; i++)
{
_outputs[i] = new Tensor(this, i, TF_DataType.TF_FLOAT);
}
_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;
}
}
}