public static Session LoadFromSavedModel(string path) { var graph = c_api.TF_NewGraph(); var status = new Status(); var opt = c_api.TF_NewSessionOptions(); var tags = new string[] { "serve" }; var buffer = new TF_Buffer(); var sess = c_api.TF_LoadSessionFromSavedModel(opt, IntPtr.Zero, path, tags, tags.Length, graph, ref buffer, status); // load graph bytes // var data = new byte[buffer.length]; // Marshal.Copy(buffer.data, data, 0, (int)buffer.length); // var meta_graph = MetaGraphDef.Parser.ParseFrom(data);*/ status.Check(); return(new Session(sess, g: new Graph(graph).as_default())); }
public static Session LoadFromSavedModel(string path) { lock (Locks.ProcessWide) { var graph = c_api.TF_NewGraph(); var status = new Status(); var opt = new SessionOptions(); var tags = new string[] { "serve" }; var buffer = new TF_Buffer(); IntPtr sess; try { sess = c_api.TF_LoadSessionFromSavedModel(opt, IntPtr.Zero, path, tags, tags.Length, graph, ref buffer, status); status.Check(true); } catch (TensorflowException ex) when(ex.Message.Contains("Could not find SavedModel")) { status = new Status(); sess = c_api.TF_LoadSessionFromSavedModel(opt, IntPtr.Zero, Path.GetFullPath(path), tags, tags.Length, graph, ref buffer, status); status.Check(true); } // load graph bytes // var data = new byte[buffer.length]; // Marshal.Copy(buffer.data, data, 0, (int)buffer.length); // var meta_graph = MetaGraphDef.Parser.ParseFrom(data);*/ return(new Session(sess, g: new Graph(graph)).as_default()); } }
public static Session LoadFromSavedModel(string path) { var graph = c_api.TF_NewGraph(); var status = new Status(); var opt = c_api.TF_NewSessionOptions(); var buffer = new TF_Buffer(); var sess = c_api.TF_LoadSessionFromSavedModel(opt, IntPtr.Zero, path, new string[0], 0, graph, ref buffer, status); //var bytes = new Buffer(buffer.data).Data; //var meta_graph = MetaGraphDef.Parser.ParseFrom(bytes); status.Check(); new Graph(graph).as_default(); return(sess); }
public static extern IntPtr TF_LoadSessionFromSavedModel(IntPtr session_options, IntPtr run_options, string export_dir, string[] tags, int tags_len, IntPtr graph, ref TF_Buffer meta_graph_def, IntPtr status);
public static extern IntPtr TF_GetBuffer(TF_Buffer buffer);