Cfis Yoi Cfis Yoi - 1 month ago 12
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 "zero_out.cc" 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:


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(<


Why is that happening? How could i fix that?

Answer

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:

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