-
Notifications
You must be signed in to change notification settings - Fork 537
Expand file tree
/
Copy pathc_api.graph.cs
More file actions
342 lines (305 loc) · 17.2 KB
/
c_api.graph.cs
File metadata and controls
342 lines (305 loc) · 17.2 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
/*****************************************************************************
Copyright 2018 The TensorFlow.NET Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
******************************************************************************/
using System;
using System.Runtime.InteropServices;
namespace Tensorflow
{
public partial class c_api
{
/// <summary>
/// Destroy an options object. Graph will be deleted once no more
/// TFSession's are referencing it.
/// </summary>
/// <param name="graph"></param>
[DllImport(TensorFlowLibName)]
public static extern void TF_DeleteGraph(IntPtr graph);
/// <summary>
///
/// </summary>
/// <param name="opts">TF_ImportGraphDefOptions*</param>
[DllImport(TensorFlowLibName)]
public static extern void TF_DeleteImportGraphDefOptions(IntPtr opts);
/// <summary>
/// Deletes a results object returned by TF_GraphImportGraphDefWithResults().
/// </summary>
/// <param name="results"></param>
[DllImport(TensorFlowLibName)]
public static extern void TF_DeleteImportGraphDefResults(IntPtr results);
[DllImport(TensorFlowLibName)]
public static extern string TF_GraphDebugString(IntPtr graph, out int len);
[DllImport(TensorFlowLibName)]
public static extern void TF_GraphGetOpDef(IntPtr graph, string op_name, SafeBufferHandle output_op_def, SafeStatusHandle status);
/// <summary>
/// Returns the shape of the Tensor referenced by `output` in `graph`
/// into `dims`. `dims` must be an array large enough to hold `num_dims`
/// entries (e.g., the return value of TF_GraphGetTensorNumDims).
/// </summary>
/// <param name="graph"></param>
/// <param name="output"></param>
/// <param name="dims"></param>
/// <param name="num_dims"></param>
/// <param name="status"></param>
[DllImport(TensorFlowLibName)]
public static extern void TF_GraphGetTensorShape(SafeGraphHandle graph, TF_Output output, long[] dims, int num_dims, SafeStatusHandle status);
/// <summary>
/// Import the graph serialized in `graph_def` into `graph`.
/// Convenience function for when only return outputs are needed.
///
/// `num_return_outputs` must be the number of return outputs added (i.e. the
/// result of TF_ImportGraphDefOptionsNumReturnOutputs()). If
/// `num_return_outputs` is non-zero, `return_outputs` must be of length
/// `num_return_outputs`. Otherwise it can be null.
/// </summary>
/// <param name="graph">TF_Graph* graph</param>
/// <param name="graph_def">const TF_Buffer*</param>
/// <param name="options">const TF_ImportGraphDefOptions*</param>
/// <param name="return_outputs">TF_Output*</param>
/// <param name="num_return_outputs">int</param>
/// <param name="status">TF_Status*</param>
[DllImport(TensorFlowLibName)]
public static extern unsafe void TF_GraphImportGraphDefWithReturnOutputs(SafeGraphHandle graph, SafeBufferHandle graph_def, SafeImportGraphDefOptionsHandle options, IntPtr return_outputs, int num_return_outputs, SafeStatusHandle status);
/// <summary>
/// Import the graph serialized in `graph_def` into `graph`. Returns nullptr and
/// a bad status on error. Otherwise, returns a populated
/// TF_ImportGraphDefResults instance. The returned instance must be deleted via
/// TF_DeleteImportGraphDefResults().
/// </summary>
/// <param name="graph">TF_Graph*</param>
/// <param name="graph_def">const TF_Buffer*</param>
/// <param name="options">const TF_ImportGraphDefOptions*</param>
/// <param name="status">TF_Status*</param>
/// <returns>TF_ImportGraphDefResults*</returns>
[DllImport(TensorFlowLibName)]
public static extern SafeImportGraphDefResultsHandle TF_GraphImportGraphDefWithResults(SafeGraphHandle graph, SafeBufferHandle graph_def, SafeImportGraphDefOptionsHandle options, SafeStatusHandle status);
/// <summary>
/// Import the graph serialized in `graph_def` into `graph`.
/// </summary>
/// <param name="graph">TF_Graph*</param>
/// <param name="graph_def">TF_Buffer*</param>
/// <param name="options">TF_ImportGraphDefOptions*</param>
/// <param name="status">TF_Status*</param>
[DllImport(TensorFlowLibName)]
public static extern void TF_GraphImportGraphDef(SafeGraphHandle graph, SafeBufferHandle graph_def, SafeImportGraphDefOptionsHandle options, SafeStatusHandle status);
/// <summary>
/// Iterate through the operations of a graph.
/// </summary>
/// <param name="graph"></param>
/// <param name="pos"></param>
/// <returns></returns>
[DllImport(TensorFlowLibName)]
public static extern IntPtr TF_GraphNextOperation(SafeGraphHandle graph, ref uint pos);
/// <summary>
/// Returns the operation in the graph with `oper_name`. Returns nullptr if
/// no operation found.
/// </summary>
/// <param name="graph"></param>
/// <param name="oper_name"></param>
/// <returns></returns>
[DllImport(TensorFlowLibName)]
public static extern IntPtr TF_GraphOperationByName(SafeGraphHandle graph, string oper_name);
/// <summary>
/// Sets the shape of the Tensor referenced by `output` in `graph` to
/// the shape described by `dims` and `num_dims`.
/// </summary>
[DllImport(TensorFlowLibName)]
public static extern void TF_GraphSetTensorShape(SafeGraphHandle graph, TF_Output output, long[] dims, int num_dims, SafeStatusHandle status);
/// <summary>
/// Write out a serialized representation of `graph` (as a GraphDef protocol
/// message) to `output_graph_def` (allocated by TF_NewBuffer()).
/// </summary>
/// <param name="graph">TF_Graph*</param>
/// <param name="output_graph_def">TF_Buffer*</param>
/// <param name="status">TF_Status*</param>
[DllImport(TensorFlowLibName)]
public static extern void TF_GraphToGraphDef(SafeGraphHandle graph, SafeBufferHandle output_graph_def, SafeStatusHandle status);
/// <summary>
/// Returns the number of dimensions of the Tensor referenced by `output`
/// in `graph`.
///
/// If the number of dimensions in the shape is unknown, returns -1.
/// </summary>
/// <param name="graph"></param>
/// <param name="output"></param>
/// <param name="status"></param>
/// <returns></returns>
[DllImport(TensorFlowLibName)]
public static extern int TF_GraphGetTensorNumDims(SafeGraphHandle graph, TF_Output output, SafeStatusHandle status);
/// <summary>
/// Cause the imported graph to have a control dependency on `oper`. `oper`
/// should exist in the graph being imported into.
/// </summary>
/// <param name="opts"></param>
/// <param name="oper"></param>
[DllImport(TensorFlowLibName)]
public static extern void TF_ImportGraphDefOptionsAddControlDependency(SafeImportGraphDefOptionsHandle opts, IntPtr oper);
/// <summary>
/// Set any imported nodes with input `src_name:src_index` to have that input
/// replaced with `dst`. `src_name` refers to a node in the graph to be imported,
/// `dst` references a node already existing in the graph being imported into.
/// `src_name` is copied and has no lifetime requirements.
/// </summary>
/// <param name="opts">TF_ImportGraphDefOptions*</param>
/// <param name="src_name">const char*</param>
/// <param name="src_index">int</param>
/// <param name="dst">TF_Output</param>
[DllImport(TensorFlowLibName)]
public static extern void TF_ImportGraphDefOptionsAddInputMapping(SafeImportGraphDefOptionsHandle opts, string src_name, int src_index, TF_Output dst);
/// <summary>
/// Add an operation in `graph_def` to be returned via the `return_opers` output
/// parameter of TF_GraphImportGraphDef(). `oper_name` is copied and has no
/// lifetime requirements.
/// </summary>
/// <param name="opts">TF_ImportGraphDefOptions* opts</param>
/// <param name="oper_name">const char*</param>
[DllImport(TensorFlowLibName)]
public static extern void TF_ImportGraphDefOptionsAddReturnOperation(SafeImportGraphDefOptionsHandle opts, string oper_name);
[DllImport(TensorFlowLibName)]
public static extern void TF_ImportGraphDefOptionsSetValidateColocationConstraints(SafeImportGraphDefOptionsHandle options, bool validate_colocation_constraints);
/// <summary>
/// Add an output in `graph_def` to be returned via the `return_outputs` output
/// parameter of TF_GraphImportGraphDef(). If the output is remapped via an input
/// mapping, the corresponding existing tensor in `graph` will be returned.
/// `oper_name` is copied and has no lifetime requirements.
/// </summary>
/// <param name="opts">TF_ImportGraphDefOptions*</param>
/// <param name="oper_name">const char*</param>
/// <param name="index">int</param>
[DllImport(TensorFlowLibName)]
public static extern void TF_ImportGraphDefOptionsAddReturnOutput(SafeImportGraphDefOptionsHandle opts, string oper_name, int index);
/// <summary>
/// Returns the number of return operations added via
/// TF_ImportGraphDefOptionsAddReturnOperation().
/// </summary>
/// <param name="opts"></param>
/// <returns></returns>
[DllImport(TensorFlowLibName)]
public static extern int TF_ImportGraphDefOptionsNumReturnOperations(SafeImportGraphDefOptionsHandle opts);
/// <summary>
/// Returns the number of return outputs added via
/// TF_ImportGraphDefOptionsAddReturnOutput().
/// </summary>
/// <param name="opts">const TF_ImportGraphDefOptions*</param>
/// <returns></returns>
[DllImport(TensorFlowLibName)]
public static extern int TF_ImportGraphDefOptionsNumReturnOutputs(SafeImportGraphDefOptionsHandle opts);
/// <summary>
/// Set any imported nodes with control input `src_name` to have that input
/// replaced with `dst`. `src_name` refers to a node in the graph to be imported,
/// `dst` references an operation already existing in the graph being imported
/// into. `src_name` is copied and has no lifetime requirements.
/// </summary>
/// <param name="opts">TF_ImportGraphDefOptions*</param>
/// <param name="src_name">const char*</param>
/// <param name="dst">TF_Operation*</param>
[DllImport(TensorFlowLibName)]
public static extern void TF_ImportGraphDefOptionsRemapControlDependency(SafeImportGraphDefOptionsHandle opts, string src_name, IntPtr dst);
/// <summary>
/// Set the prefix to be prepended to the names of nodes in `graph_def` that will
/// be imported into `graph`. `prefix` is copied and has no lifetime
/// requirements.
/// </summary>
/// <param name="ops"></param>
[DllImport(TensorFlowLibName)]
public static extern void TF_ImportGraphDefOptionsSetPrefix(SafeImportGraphDefOptionsHandle ops, string prefix);
/// <summary>
/// Set whether to uniquify imported operation names. If true, imported operation
/// names will be modified if their name already exists in the graph. If false,
/// conflicting names will be treated as an error. Note that this option has no
/// effect if a prefix is set, since the prefix will guarantee all names are
/// unique. Defaults to false.
/// </summary>
/// <param name="ops">TF_ImportGraphDefOptions*</param>
/// <param name="uniquify_prefix">unsigned char</param>
[DllImport(TensorFlowLibName)]
public static extern void TF_ImportGraphDefOptionsSetUniquifyNames(SafeImportGraphDefOptionsHandle ops, bool uniquify_prefix);
/// <summary>
/// Fetches the return operations requested via
/// TF_ImportGraphDefOptionsAddReturnOperation(). The number of fetched
/// operations is returned in `num_opers`. The array of return operations is
/// returned in `opers`. `*opers` is owned by and has the lifetime of `results`.
/// </summary>
/// <param name="results">TF_ImportGraphDefResults*</param>
/// <param name="num_opers">int*</param>
/// <param name="opers">TF_Operation***</param>
[DllImport(TensorFlowLibName)]
public static extern void TF_ImportGraphDefResultsReturnOperations(SafeImportGraphDefResultsHandle results, ref int num_opers, ref TF_Operation opers);
/// <summary>
/// Fetches the return outputs requested via
/// TF_ImportGraphDefOptionsAddReturnOutput(). The number of fetched outputs is
/// returned in `num_outputs`. The array of return outputs is returned in
/// `outputs`. `*outputs` is owned by and has the lifetime of `results`.
/// </summary>
/// <param name="results">TF_ImportGraphDefResults* results</param>
/// <param name="num_outputs">int*</param>
/// <param name="outputs">TF_Output**</param>
[DllImport(TensorFlowLibName)]
public static extern void TF_ImportGraphDefResultsReturnOutputs(SafeImportGraphDefResultsHandle results, ref int num_outputs, ref IntPtr outputs);
/// <summary>
/// This function creates a new TF_Session (which is created on success) using
/// `session_options`, and then initializes state (restoring tensors and other
/// assets) using `run_options`.
/// </summary>
/// <param name="session_options">const TF_SessionOptions*</param>
/// <param name="run_options">const TF_Buffer*</param>
/// <param name="export_dir">const char*</param>
/// <param name="tags">const char* const*</param>
/// <param name="tags_len">int</param>
/// <param name="graph">TF_Graph*</param>
/// <param name="meta_graph_def">TF_Buffer*</param>
/// <param name="status">TF_Status*</param>
/// <returns></returns>
[DllImport(TensorFlowLibName)]
public static extern SafeSessionHandle TF_LoadSessionFromSavedModel(SafeSessionOptionsHandle session_options, IntPtr run_options,
string export_dir, string[] tags, int tags_len,
SafeGraphHandle graph, IntPtr meta_graph_def, SafeStatusHandle status);
[DllImport(TensorFlowLibName)]
public static extern SafeGraphHandle TF_NewGraph();
[DllImport(TensorFlowLibName)]
public static extern SafeImportGraphDefOptionsHandle TF_NewImportGraphDefOptions();
/// <summary>
/// Set the shapes and types of the output's handle.
/// </summary>
/// <param name="graph">TF_Graph*</param>
/// <param name="output">TF_Output</param>
/// <param name="num_shapes_and_types">int</param>
/// <param name="shapes">const int64_t**</param>
/// <param name="ranks">const int*</param>
/// <param name="types">const TF_DataType*</param>
/// <param name="status">TF_Status*</param>
[DllImport(TensorFlowLibName)]
public static extern void TF_GraphSetOutputHandleShapesAndTypes(SafeGraphHandle graph, TF_Output output,
int num_shapes_and_types, IntPtr[] shapes, int[] ranks, DataType[] types,
SafeStatusHandle status);
/// <summary>
/// Updates 'dst' to consume 'new_src'.
/// </summary>
/// <param name="graph">TF_Graph*</param>
/// <param name="new_src"></param>
/// <param name="dst"></param>
/// <param name="status">TF_Status*</param>
[DllImport(TensorFlowLibName)]
public static extern void TF_UpdateEdge(IntPtr graph, TF_Output new_src, TF_Input dst, SafeStatusHandle status);
/// <summary>
/// Attempts to evaluate `output`. This will only be possible if `output` doesn't
/// depend on any graph inputs (this function is safe to call if this isn't the
/// case though).
/// </summary>
/// <param name="graph"></param>
/// <param name="output"></param>
/// <param name="result"></param>
/// <param name="status"></param>
/// <returns></returns>
[DllImport(TensorFlowLibName)]
public static extern bool TF_TryEvaluateConstant(SafeGraphHandle graph, TF_Output output, IntPtr[] result, SafeStatusHandle status);
}
}