尝试使用未初始化的值-无法使用tensorflowsharp进行预测

时间:2018-10-12 09:51:32

标签: tensorflow tensorflowsharp

上下文:我创建并训练了一个可以检测产品缺陷的模型。使用Keras训练模型,并将其保存为.h5文件到磁盘。当前的缺陷检测系统是使用.NET编写的,因此我将.h5模型转换为.pb格式,并使用tensorflowsharp(TFS)进行加载。

代码:

var resourceFolder = "Dataset/Robot";
var tfGraph = new TFGraph();
using (var tmpSess = new TFSession(tfGraph))
using (var tfSessionOptions = new TFSessionOptions())
using (var metaGraphUnused = new TFBuffer())
{
    tmpSess.FromSavedModel(tfSessionOptions, null, resourceFolder, new[] {"serve"}, tfGraph, metaGraphUnused);
    var runner = tmpSess.GetRunner();
    var tfTensor = CreateTensor(dataset);
    runner.AddInput(tfGraph["input_1"][0], tfTensor).Fetch(tfGraph["conv2d_23/BiasAdd"][0]);
    var output = runner.Run();
}

问题:我进行预测(var output = runner.Run();时,TFS引发以下异常: Attempting to use uninitialized value {X}. 每当我重新运行程序时,X都会更改。 X的一些值包括:

  • conv2d_21 / kernel [[节点:conv2d_21 / kernel / read = IdentityT = DT_FLOAT,_device =“ / job:localhost /副本:0 / task:0 / device:CPU:0”]]
  • batch_normalization_22 / moving_variance [[节点:batch_normalization_22 / moving_variance / read =身份[T = DT_FLOAT,_class = [“ loc:@ batch_normalization_22 / cond / FusedBatchNorm / Switch_4”],)
  • conv2d_23 / bias [[节点:conv2d_23 / bias / read = IdentityT = DT_FLOAT,_device =“ / job:localhost /副本:0 / task:0 / device:CPU:0”]]

期望的行为:没有例外

到目前为止已完成的操作:

0 个答案:

没有答案