From 1088e1fe19c0cd3a94862449c41003394beba32d Mon Sep 17 00:00:00 2001 From: Oceania2018 Date: Thu, 14 Feb 2019 08:55:20 -0600 Subject: [PATCH] ImportGraphDefFromPbFile --- src/TensorFlowNET.Core/Graphs/Graph.Import.cs | 10 ++++++++++ test/TensorFlowNET.Examples/MetaGraph.cs | 2 ++ test/TensorFlowNET.UnitTest/TrainSaverTest.cs | 8 ++++++++ 3 files changed, 20 insertions(+) diff --git a/src/TensorFlowNET.Core/Graphs/Graph.Import.cs b/src/TensorFlowNET.Core/Graphs/Graph.Import.cs index a8c6563a..8511cc01 100644 --- a/src/TensorFlowNET.Core/Graphs/Graph.Import.cs +++ b/src/TensorFlowNET.Core/Graphs/Graph.Import.cs @@ -1,6 +1,7 @@ using Google.Protobuf; using System; using System.Collections.Generic; +using System.IO; using System.Runtime.InteropServices; using System.Text; @@ -24,5 +25,14 @@ namespace Tensorflow return return_outputs; } + + public Status Import(string file_path) + { + var bytes = File.ReadAllBytes(file_path); + var graph_def = new Tensorflow.Buffer(bytes); + var opts = c_api.TF_NewImportGraphDefOptions(); + c_api.TF_GraphImportGraphDef(_handle, graph_def, opts, Status); + return Status; + } } } diff --git a/test/TensorFlowNET.Examples/MetaGraph.cs b/test/TensorFlowNET.Examples/MetaGraph.cs index bf6cebda..bb272a2c 100644 --- a/test/TensorFlowNET.Examples/MetaGraph.cs +++ b/test/TensorFlowNET.Examples/MetaGraph.cs @@ -1,5 +1,7 @@ using System; using System.Collections.Generic; +using System.IO; +using System.Runtime.InteropServices; using System.Text; using Tensorflow; diff --git a/test/TensorFlowNET.UnitTest/TrainSaverTest.cs b/test/TensorFlowNET.UnitTest/TrainSaverTest.cs index e0b4a9db..28c8a242 100644 --- a/test/TensorFlowNET.UnitTest/TrainSaverTest.cs +++ b/test/TensorFlowNET.UnitTest/TrainSaverTest.cs @@ -1,6 +1,7 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using System; using System.Collections.Generic; +using System.IO; using System.Text; using Tensorflow; @@ -35,6 +36,13 @@ namespace TensorFlowNET.UnitTest }); } + [TestMethod] + public void ImportGraphDefFromPbFile() + { + var g = new Graph(); + var status = g.Import("mobilenet/saved_model.pb"); + } + [TestMethod] public void Save1() {