Skip to content

Commit de696fb

Browse files
committed
new operation alwasy in current graph.
1 parent 3d085c4 commit de696fb

3 files changed

Lines changed: 18 additions & 8 deletions

File tree

src/TensorFlowNET.Core/Graphs/Graph.Import.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,16 @@ public Status Import(byte[] bytes, string prefix = "")
5959
return status;
6060
}
6161

62+
static object locker = new object();
6263
public static Graph ImportFromPB(string file_path, string name = null)
6364
{
64-
var graph = tf.Graph().as_default();
65-
var graph_def = GraphDef.Parser.ParseFrom(File.ReadAllBytes(file_path));
66-
importer.import_graph_def(graph_def, name: name);
67-
return graph;
65+
lock (locker)
66+
{
67+
var graph = tf.Graph().as_default();
68+
var graph_def = GraphDef.Parser.ParseFrom(File.ReadAllBytes(file_path));
69+
importer.import_graph_def(graph_def, name: name);
70+
return graph;
71+
}
6872
}
6973
}
7074
}

src/TensorFlowNET.Core/Graphs/Graph.Operation.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,13 @@ public unsafe Operation[] ReturnOperations(IntPtr results)
5555

5656
public Operation OperationByName(string operName)
5757
{
58-
return c_api.TF_GraphOperationByName(_handle, operName);
58+
var handle = c_api.TF_GraphOperationByName(_handle, operName);
59+
if(graph_key != tf.get_default_graph().graph_key)
60+
{
61+
Console.WriteLine($"Current graph is not default graph.");
62+
// throw new ValueError($"Current graph is not default graph.");
63+
}
64+
return new Operation(handle, g: this);
5965
}
6066

6167
public ITensorOrOperation[] get_operations()

src/TensorFlowNET.Core/TensorFlowNET.Core.csproj

Lines changed: 3 additions & 3 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.0</TargetTensorFlow>
8-
<Version>0.10.8</Version>
8+
<Version>0.10.9</Version>
99
<Authors>Haiping Chen, Meinrad Recheis</Authors>
1010
<Company>SciSharp STACK</Company>
1111
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
@@ -17,7 +17,7 @@
1717
<PackageTags>TensorFlow, NumSharp, SciSharp, MachineLearning, TensorFlow.NET, C#</PackageTags>
1818
<Description>Google's TensorFlow full binding in .NET Standard.
1919
Docs: https://tensorflownet.readthedocs.io</Description>
20-
<AssemblyVersion>0.10.8.0</AssemblyVersion>
20+
<AssemblyVersion>0.10.9.0</AssemblyVersion>
2121
<PackageReleaseNotes>Changes since v0.9.0:
2222

2323
1. Added full connected Convolution Neural Network example.
@@ -37,7 +37,7 @@ Docs: https://tensorflownet.readthedocs.io</Description>
3737
15. Fix Tensor memory leak.
3838
16. Rename with to tf_with that is only used to build graph purpose.</PackageReleaseNotes>
3939
<LangVersion>7.2</LangVersion>
40-
<FileVersion>0.10.8.0</FileVersion>
40+
<FileVersion>0.10.9.0</FileVersion>
4141
<PackageLicenseFile>LICENSE</PackageLicenseFile>
4242
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
4343
<SignAssembly>true</SignAssembly>

0 commit comments

Comments
 (0)