在使用模型文件从C#运行时,试图使用未初始化的值变量

在使用模型文件从C#运行时,试图使用未初始化的值变量,c#,python,api,tensorflow,C#,Python,Api,Tensorflow,我有一个正在运行的Python代码来执行简单的逻辑回归。我使用Python中的以下语句创建了一个pb文件 tf.train.write_graph(sess.graph_def, '.','logistic-sigmoid-cpm-model.pb', False) 然后我使用Tensorflowsharp从C#加载它 var model = File.ReadAllBytes("logistic-sigmoid-cpm-model.pb"); graph.Import(model, "");

我有一个正在运行的Python代码来执行简单的逻辑回归。我使用Python中的以下语句创建了一个pb文件

tf.train.write_graph(sess.graph_def, '.','logistic-sigmoid-cpm-model.pb', False)
然后我使用Tensorflowsharp从C#加载它

var model = File.ReadAllBytes("logistic-sigmoid-cpm-model.pb");
graph.Import(model, "");
using (var session = new TFSession(graph))
{
    var x = LoadCsv("dataX.csv", 1);
    var y = LoadCsv("dataY1.csv", 0);

    var runner = session.GetRunner();                
    runner.AddInput(graph["x"][0], x).AddInput(graph["y"][0], y).Fetch(graph["pred"][0]);
    var output = runner.Run();
我收到了以下错误消息

TensorFlow.TFException
    HResult=0x80131500
    Message=Attempting to use uninitialized value Variable
       [[Node: Variable/read = Identity[T=DT_FLOAT, _class=["loc:@Variable"], _device="/job:localhost/replica:0/task:0/device:CPU:0"](Variable)]]
    Source=TensorFlowSharp
    StackTrace:
        at TensorFlow.TFStatus.CheckMaybeRaise(TFStatus incomingStatus, Boolean last)
        at TensorFlow.TFSession.Run(TFOutput[] inputs, TFTensor[] inputValues, TFOutput[] outputs, TFOperation[] targetOpers, TFBuffer runMetadata, TFBuffer runOptions, TFStatus status)
        at TensorFlow.TFSession.Runner.Run(TFStatus status)
        at ConsoleApp2.Program.Main(String[] args) in C:\Users\Shuo-jen\source\repos\ConsoleApp2\ConsoleApp2\Program.cs:line 35

模型缺少什么吗?或者我需要添加一些代码?

TF.global\u variables\u initializer(),操作需要事先执行。你是说在我在Python端创建模型之前?还是在我在TensorflowSharp侧运行predicition之前?我想我在Python端创建模型之前运行它。但我不知道如何从TensorflowSharp这一边运行它。