TensorFlow C+中的通过选项+; C++,我现在在Python中创建了一个TyoSoFrand图,并将它(作为一个原型BUF)导出到C++中。我正在通过会话->运行(…)调用运行入/出队列操作(FIFOQueue),在一段时间内无法运行操作后,需要调用超时。我可以在Python中通过将RunOptions输入sess.run(…)来实现这一点。是否有类似的方法在C++中执行?
如果你查看当前版本的页眉(V1.3.0,尽管自从Vo.8. 0创建了TensorFlow C+中的通过选项+; C++,我现在在Python中创建了一个TyoSoFrand图,并将它(作为一个原型BUF)导出到C++中。我正在通过会话->运行(…)调用运行入/出队列操作(FIFOQueue),在一段时间内无法运行操作后,需要调用超时。我可以在Python中通过将RunOptions输入sess.run(…)来实现这一点。是否有类似的方法在C++中执行?,c++,tensorflow,C++,Tensorflow,如果你查看当前版本的页眉(V1.3.0,尽管自从Vo.8. 0创建了RunOpvests/Cuff>),并且有一些标记为“实验”的函数签名,允许你通过 RunOpvs>代码>对象。如果您以这种方式调用Run,并且查看它似乎无法传递nullptr,那么指针RunMetadata参数似乎也是必需的。所以你可以这样做: #include <vector> #include <tensorflow/core/public/session.h> int main(int argc
Run
,并且查看它似乎无法传递nullptr
,那么指针RunMetadata
参数似乎也是必需的。所以你可以这样做:
#include <vector>
#include <tensorflow/core/public/session.h>
int main(int argc, char *argv[])
{
const int64_t TIMEOUT_MS = ...; // Timeout in milliseconds
tensorflow::GraphDef graph = ...; // Load you graph definition
tensorflow::Session *newSession;
auto status = tensorflow::NewSession(tensorflow::SessionOptions(), &newSession);
if (!status.ok()) { /* Handle error. */ }
status = session->Create(graph);
if (!status.ok()) { /* Handle error. */ }
tensorflow::RunOptions run_options;
run_options.set_timeout_in_ms(TIMEOUT_MS);
tensorflow::RunMetadata run_metadata;
// Run parameters
std::vector<std::pair<string, Tensor> > inputs = ...;
std::vector<string> output_tensor_names = ...;
std::vector<string> target_node_names = ...;
std::vector<Tensor> outputs;
// Run
status = sess.Run(run_options, inputs, output_tensor_names,
target_node_names, &outputs, &run_metadata);
if (!status.ok()) { /* Handle error. */ }
// Use output
// ...
return 0;
}
#包括
#包括
int main(int argc,char*argv[])
{
const int64_t TIMEOUT_MS=…;//以毫秒为单位的超时
tensorflow::GraphDef graph=…;//加载图形定义
tensorflow::会话*新闻会话;
自动状态=tensorflow::NewSession(tensorflow::SessionOptions(),&NewSession);
如果(!status.ok()){/*句柄错误。*/}
状态=会话->创建(图形);
如果(!status.ok()){/*句柄错误。*/}
tensorflow::RunOptions运行选项;
运行\选项。设置\超时\单位为\毫秒(超时\毫秒);
tensorflow::RunMetadata run\u metadata;
//运行参数
向量输入=。。。;
向量输出_张量_名称=。。。;
向量目标节点名称=。。。;
向量输出;
//跑
状态=sess.Run(运行选项、输入、输出张量名称、,
目标节点名称、输出和运行元数据);
如果(!status.ok()){/*句柄错误。*/}
//使用输出
// ...
返回0;
}
看起来这个界面已经存在很长时间了,但是由于它被标记为实验性的,所以它可能会显示一些错误,或者只是在即将发布的版本中有所更改。谢谢!我问这个问题的原因是因为我需要一种方法在程序停止接收数据后关闭它。使用超时是一个“优雅”的选项吗?@ NCI我还没有真正使用这个选项,但至少对我来说是合理的,只要你的超时时间足够长,以确保你不停止在一个延迟或中间的评估。但您也可以研究使用该选项的可能注意事项。