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

时间:2018-03-20 06:30:03

标签: 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, "");
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

模特遗失了什么?或者我需要添加一些代码?

0 个答案:

没有答案