为什么我会得到"You must feed a value for placeholder tensor 'output' with dtype int64"?
Why do I get "You must feed a value for placeholder tensor 'output' with dtype int64"?
我正在尝试构建一个C++程序,该程序读取预先训练的模型并使用它。我从这里获取了代码并对其进行了一点修改。我现在拥有的是:
int main(int argc, char* argv[]) {
// Initialize a tensorflow session
Session* session;
Status status = NewSession(SessionOptions(), &session);
if (!status.ok()) {
std::cout << status.ToString() << "n";
return 1;
}
// Read in the protobuf graph we exported
GraphDef graph_def;
status = ReadTextProto(Env::Default(), "models/train.pbtxt", &graph_def);
if (!status.ok()) {
std::cout << status.ToString() << "n";
return 1;
}
// Add the graph to the session
status = session->Create(graph_def);
if (!status.ok()) {
std::cout << status.ToString() << "n";
return 1;
}
tensorflow::Tensor inputs(DT_FLOAT, TensorShape({46}));
auto inputs_flat = inputs.flat<float>();
inputs_flat.setRandom();
// The session will initialize the outputs
std::vector<tensorflow::Tensor> outputs;
status = session->Run({{"input", inputs}}, {"output"}, {}, &outputs);
if (!status.ok()) {
std::cout << status.ToString() << "n"; // <--- error shows here
return 1;
}
// Grab the first output
// and convert the node to a scalar representation.
auto output_c = outputs[0].scalar<int>();
// Print the results
std::cout << outputs[0].DebugString() << "n";
std::cout << output_c() << "n";
// Free any resources used by the session
session->Close();
return 0;
}
但是当我运行它时,我得到
Invalid argument: You must feed a value for placeholder tensor 'output' with dtype int64
[[Node: output = Placeholder[_output_shapes=[[-1]], dtype=DT_INT64, shape=[], _device="/job:localhost/replica:0/task:0/cpu:0"]()]]
我在models/train.pbtxt
中阅读的图表有 14K 行,所以我不在这里复制它。我将把相关部分:
...................
node {
name: "input"
op: "Placeholder"
attr {
key: "_output_shapes"
value {
list {
shape {
dim {
size: -1
}
dim {
size: 46
}
}
}
}
}
attr {
key: "dtype"
value {
type: DT_FLOAT
}
}
attr {
key: "shape"
value {
shape {
}
}
}
}
node {
name: "output"
op: "Placeholder"
attr {
key: "_output_shapes"
value {
list {
shape {
dim {
size: -1
}
}
}
}
}
attr {
key: "dtype"
value {
type: DT_INT64
}
}
attr {
key: "shape"
value {
shape {
}
}
}
}
...................
所以阅读问题:此错误消息告诉我什么?
在原始图中,有一个名为 "output"
的节点是一个tf.placeholder()
,即当你运行任何依赖于它的操作时必须馈送的符号张量。
在以下调用 session->Run()
的行中,您告诉 TensorFlow 评估并获取名为 "output"
的节点的结果:
status = session->Run({{"input", inputs}}, {"output"}, {}, &outputs);
这似乎没有意义:为什么要获取必须在同一行上馈送的占位符的值?
我怀疑名为 "output"
的节点实际上并不对应于模型的输出(例如预测),而是用于馈送预期输出的占位符(例如,馈送到"input"
的相应值的已知标签)。图中可能还有其他一些节点可供您评估以获取预测,但其名称将取决于您最初构建图形的方式。
相关文章:
- 从不同线程使用int64的不同字节安全吗
- 你能把一个向量<int64>投射到一个向量<uint8>吗
- 从 std::向量值创建张量<Tensor>
- 如何使用 Eigen::Tensor::convolve with Multiple Kernel?
- Int64 和 time_t 之间的 C++ 重载歧义
- 无法在 Windows 10/Visual C++ 2017 上使用 tensorflow C++ API tensor
- 从 Eigen::Tensor 创建张量流::张量
- 如何将 Eigen::Tensor 广播到更高维度?
- 将 Eigen::TensorMap 转换为 Eigen::Tensor
- 在 c++ 中设置 int64 值的最高四位
- eigen :: Tensor,如何从张量访问矩阵
- tensorflow::Tensor to python Tensor or numpy.nd_array
- UINT8数组对INT64的质量化失败,但应该起作用
- 使用TensorFlow时"unsupported/Eigen/CXX11/Tensor: No such file or directory"
- 为什么我会得到"You must feed a value for placeholder tensor 'output' with dtype int64"?
- 如何使用SSE有效地执行INT8/INT64转换
- 从INT64到字节数组
- 如何将 int64 定点转换为双精度
- 如何在不改变顺序的情况下将int64值移位到无符号int64空间
- 在C++中将 Java long 转换为 int64