您必须使用dtype float和shape [?,3]输入占位符张量“ X_1”的值

时间:2018-10-16 11:11:41

标签: tensorflow model restore tensorflowsharp

我已经通过Jupyter Notebook编写了一个非常简单的模型

n_input = 3  
X = tf.placeholder(tf.float32, [None, n_input], name="X")
decoder = tf.matmul(X, [[2.0,3.0],[2.0,3.0],[2.0,3.0]], name='decoder')

init = tf.global_variables_initializer()
sess = tf.Session()
sess.run(init)

values = sess.run(decoder, feed_dict={X: df_norm[:10]})

graph = tf.get_default_graph()
tf.train.write_graph(graph, './model/','saved_model.pbtxt', as_text=False)

然后我用TensorflowSharp加载了它

using (var graph = new TFGraph())
            {
                var bytes = File.ReadAllBytes(@".\model\saved_model.pbtxt");
                graph.Import(bytes);
                var session = new TFSession(graph);


                var runner = session.GetRunner();
                runner.AddInput(graph["X"][0], new float[] { 176.75f, 7.95f, 40397.00f }); 

                runner.Fetch(graph["decoder"][0]);

                var output = runner.Run();

                // Fetch the results from output:
                TFTensor result = output[0];
            }

最后,我在下面遇到了异常:

  

TensorFlow.TFException HResult = 0x80131500메시지=您必须输入   dtype float和形状为[?,3]的占位符张量'X_1'的值
  [[{{node X_1}} = Placeholderdtype = DT_FLOAT,shape = [?, 3],   _device =“ / job:localhost / replica:0 / task:0 / device:CPU:0”]]소스= TensorFlowSharp StackTrace:at   TensorFlow.TFStatus.CheckMaybeRaise(TFStatus entryStatus,布尔值   最后)在TensorFlow.TFSession.Run(TFOutput []输入,TFTensor []   inputValues,TFOutput []输出,TFOperation [] targetOpers,TFBuffer   runMetadata,TFBuffer runOptions,TFStatus状态)   TensorFlow.TFSession.Runner.Run(TFStatus状态)位于   tensorflowsharp_model_restore.Program.Main(String [] args)在   G:\ tensorflow \ tensorflowsharp \ tensorflowsharp_model_restore \ tensorflowsharp_model_restore \ Program.cs:line   29

0 个答案:

没有答案