Cfis Yoi Cfis Yoi - 2 months ago 23
C++ Question

Error compiling the new_op tutorial (Tensorflow)

I would like to learn how to install new op. So for doing that i' m following the given tutorial. I made a folder named user_ops, create a "" file and copy the code given in the tutorial. When i' m trying to compile the Op into a dynamic library with g++ errors appear: In lambda function: error: ‘Status’ has not been declared
return Status::OK();
^ At global scope: error: invalid user-defined conversion from ‘’ to ‘tensorflow::Status ()(tensorflow::shape_inference::InferenceContext)’ [-fpermissive]
^ note: candidate is: ::operator void ()(tensorflow::shape_inference::InferenceContext)() const
.SetShapeFn([](::tensorflow::shape_inference::InferenceContext* c) {
^ note: no known conversion from ‘void ()(tensorflow::shape_inference::InferenceContext)’ to ‘tensorflow::Status ()(tensorflow::shape_inference::InferenceContext)’
In file included from
/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(<

Why is that happening? How could i fix that?


Assuming your only problem is the undefined Status type -- and copying and pasting the tutorial code works just fine except for this -- you need to either move the using namespace tensorflow to before the first use of Status, or fully qualify it (as in return tensorflow::Status::OK())

For example, the REGISTER_OP section could read as follows, if you did the templated version:

    .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();