编译新教程时出错(Tensorflow)

2024-09-29 19:28:44 发布

您现在位置:Python中文网/ 问答频道 /正文

我想学习如何install new op。因此,为了做到这一点,我遵循给定的教程。我做了一个名为user_ops的文件夹,创建一个“0_输出.cc“归档并复制教程中给出的代码。当我试图将操作编译成动态库时,出现了g++错误:

zero_out.cc: In lambda function: zero_out.cc:10:14: error: ‘Status’ has not been declared return Status::OK(); ^ zero_out.cc: At global scope: zero_out.cc:11:6: error: invalid user-defined conversion from ‘’ to ‘tensorflow::Status ()(tensorflow::shape_inference::InferenceContext)’ [-fpermissive] }); ^ zero_out.cc:8:70: note: candidate is: ::operator void ()(tensorflow::shape_inference::InferenceContext)() const .SetShapeFn([](::tensorflow::shape_inference::InferenceContext* c) { ^ zero_out.cc:8:70: note: no known conversion from ‘void ()(tensorflow::shape_inference::InferenceContext)’ to ‘tensorflow::Status ()(tensorflow::shape_inference::InferenceContext)’ In file included from zero_out.cc:1:0: /usr/local/lib/python2.7/dist-packages/tensorflow/include/tensorflow/core/framework/op.h:252:30: note: initializing argument 1 of ‘tensorflow::register_op::OpDefBuilderWrapper& tensorflow::register_op::OpDefBuilderWrapper::SetShapeFn(tensorflow::Status ()(tensorflow::shape_inference::InferenceContext))’ OpDefBuilderWrapper& SetShapeFn(<

为什么会这样?我怎么能修好呢?在


Tags: fromtensorflowstatus教程outnoteccshape
2条回答

在我看来,Tensorflowtutorial没有正确的代码。 所以我遵循了这个tutorial的代码,它工作得非常完美! 我不知道它说什么!在

假设您唯一的问题是未定义的Status类型,复制和粘贴教程代码就可以了,除了这个之外,您需要在第一次使用Status之前将{}移动到,或者完全限定它(如return tensorflow::Status::OK()

例如,如果使用模板版本,REGISTER_OP部分可以如下所示:

REGISTER_OP("ZeroOut")
    .Attr("T: {float, int32}")
    .Input("to_zero: T")
    .Output("zeroed: T")
    .SetShapeFn([](::tensorflow::shape_inference::InferenceContext* c) {
      c->set_output(0, c->input(0));
      return tensorflow::Status::OK();
    });

相关问题 更多 >

    热门问题