public Generator(string outputFile = "Ops.g.cs") { OutputFile = new FileInfo(outputFile); if (OutputFile.Exists) { L.Warning("The output file {0} exists and will be overwritten.", OutputFile.FullName); } else { L.Information("Using output file {0}.", OutputFile.FullName); } var status = tf_status.TF_NewStatus(); TF_Buffer opsBuffer = c_api.TF_GetAllOpList(); if (tf_status.TF_GetCode(status) != TF_Code.TF_OK) { L.Error("Could not get op list: {0}.", tf_status.TF_Message(status)); Program.Exit(Program.ExitResult.TF_ERROR); } var ret = new byte[(int)opsBuffer.Length]; Marshal.Copy(opsBuffer.Data, ret, 0, (int)opsBuffer.Length); OpDefs = Serializer.Deserialize <List <OpDef> >(new MemoryStream(ret)); ApiDefMap = c_api.TF_NewApiDefMap(opsBuffer, status); if (tf_status.TF_GetCode(status) != TF_Code.TF_OK) { L.Error("Could not create new ApiDefMap: {0}.", tf_status.TF_Message(status)); Program.Exit(Program.ExitResult.TF_ERROR); } outputWriter = new StringWriter(OutputBuilder); L.Information("Created generator."); }
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); } return(new Session(sess, g: new Graph(graph)).as_default()); } }