Skip to content

Commit 4977716

Browse files
2 parents 1c35292 + c60fe3c commit 4977716

5 files changed

Lines changed: 61 additions & 16 deletions

File tree

‎src/TensorFlowNET.Core/APIs/tf.io.cs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public partial class tensorflow
2323
{
2424
public GFile gfile = new GFile();
2525
public Tensor read_file(string filename, string name = null) => gen_io_ops.read_file(filename, name);
26+
public Tensor read_file(Tensor filename, string name = null) => gen_io_ops.read_file(filename, name);
2627

2728
public ITensorOrOperation[] import_graph_def(GraphDef graph_def,
2829
Dictionary<string, Tensor> input_map = null,

‎src/TensorFlowNET.Core/GraphTransformation/GraphTransformer.cs‎

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.IO;
34
using System.Text;
5+
using Google.Protobuf;
46

57
namespace Tensorflow
68
{
@@ -15,17 +17,30 @@ public class GraphTransformer
1517
/// <param name="outputs">the model outputs</param>
1618
/// <param name="transforms">transform names and parameters</param>
1719
/// <returns></returns>
18-
public GraphDef TransformGraph(GraphDef input_graph_def,
19-
string[] inputs,
20-
string[] outputs,
20+
public GraphDef TransformGraph(GraphDef input_graph_def,
21+
string[] inputs,
22+
string[] outputs,
2123
string[] transforms)
2224
{
23-
var input_graph_def_string = input_graph_def.ToString();
25+
var input_graph_def_string = input_graph_def.ToByteArray();
2426
var inputs_string = string.Join(",", inputs);
2527
var outputs_string = string.Join(",", outputs);
26-
var transforms_string = string.Join(",", transforms);
28+
var transforms_string = string.Join(" ", transforms);
29+
using (var status = new Status())
30+
{
31+
var buffer = new Buffer();
32+
var len = c_api.TransformGraphWithStringInputs(input_graph_def_string,
33+
input_graph_def_string.Length,
34+
inputs_string,
35+
outputs_string,
36+
transforms_string,
37+
buffer,
38+
status);
2739

28-
throw new NotImplementedException("");
40+
status.Check(false);
41+
var bytes = buffer.ToArray();
42+
return GraphDef.Parser.ParseFrom(bytes);
43+
}
2944
}
3045
}
3146
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*****************************************************************************
2+
Copyright 2018 The TensorFlow.NET Authors. All Rights Reserved.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
******************************************************************************/
16+
17+
using System;
18+
using System.Runtime.InteropServices;
19+
20+
namespace Tensorflow
21+
{
22+
public partial class c_api
23+
{
24+
[DllImport(TensorFlowLibName)]
25+
public static extern int TransformGraphWithStringInputs(byte[] graph_def_string,
26+
int graph_def_string_len,
27+
string inputs_string,
28+
string outputs_string,
29+
string transforms_string,
30+
IntPtr output_buffer,
31+
IntPtr status);
32+
}
33+
}

‎src/TensorFlowNET.Core/Operations/gen_io_ops.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public static Tensor[] restore_v2(Tensor prefix, string[] tensor_names, string[]
3434
return _op.outputs;
3535
}
3636

37-
public static Tensor read_file(string filename, string name = null)
37+
public static Tensor read_file<T>(T filename, string name = null)
3838
{
3939
var _op = _op_def_lib._apply_op_helper("ReadFile", name: name, args: new { filename });
4040

‎src/TensorFlowNET.Core/TensorFlow.Binding.csproj‎

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<AssemblyName>TensorFlow.NET</AssemblyName>
66
<RootNamespace>Tensorflow</RootNamespace>
77
<TargetTensorFlow>1.14.1</TargetTensorFlow>
8-
<Version>0.14.0</Version>
8+
<Version>0.15.0</Version>
99
<Authors>Haiping Chen, Meinrad Recheis, Eli Belash</Authors>
1010
<Company>SciSharp STACK</Company>
1111
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
@@ -18,15 +18,11 @@
1818
<Description>Google's TensorFlow full binding in .NET Standard.
1919
Building, training and infering deep learning models.
2020
https://tensorflownet.readthedocs.io</Description>
21-
<AssemblyVersion>0.14.0.0</AssemblyVersion>
22-
<PackageReleaseNotes>Changes since v0.13.0:
23-
1: Upgrade NumSharp to v0.20.5
24-
2: Return byte[] for TF_String
25-
3: Fix return_tensors for import_graph_def
26-
4: Add tf.nn.ctc_greedy_decoder
27-
5: Fix calling RegisterGradientFunction too early</PackageReleaseNotes>
21+
<AssemblyVersion>0.15.0.0</AssemblyVersion>
22+
<PackageReleaseNotes>Changes since v0.14.0:
23+
1: Add TransformGraphWithStringInputs.</PackageReleaseNotes>
2824
<LangVersion>7.3</LangVersion>
29-
<FileVersion>0.14.0.0</FileVersion>
25+
<FileVersion>0.15.0.0</FileVersion>
3026
<PackageLicenseFile>LICENSE</PackageLicenseFile>
3127
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
3228
<SignAssembly>true</SignAssembly>

0 commit comments

Comments
 (0)