【问题标题】:Error compiling the new_op tutorial (Tensorflow)编译 new_op 教程时出错 (Tensorflow)
【发布时间】:2016-10-25 14:18:31
【问题描述】:

我想学习如何install new op。所以为了做到这一点,我正在遵循给定的教程。我创建了一个名为 user_ops 的文件夹,创建了一个“zero_out.cc”文件并复制了教程中给出的代码。当我试图将 Op 编译成带有 g++ 的动态库时出现错误:

zero_out.cc:在 lambda 函数中: zero_out.cc:10:14:错误:“状态”尚未声明 返回状态::OK(); ^ zero_out.cc:在全球范围内: zero_out.cc:11:6:错误:从“”到“tensorflow::Status ()(tensorflow::shape_inference::InferenceContext)”的用户定义转换无效[-fpermissive] }); ^ zero_out.cc:8:70:注意:候选是:::operator void ()(tensorflow::shape_inference::InferenceContext)() const .SetShapeFn([](::tensorflow::shape_inference::InferenceContext* c) { ^ zero_out.cc:8:70:注意:没有已知的从 'void ()(tensorflow::shape_inference::InferenceContext)' 到 'tensorflow::Status ()(tensorflow:: shape_inference::InferenceContext)' 在 zero_out.cc:1:0 包含的文件中: /usr/local/lib/python2.7/dist-packages/tensorflow/include/tensorflow/core/framework/op.h:252:30:注意:初始化 'tensorflow::register_op::OpDefBuilderWrapper& tensorflow:: 的参数 1 register_op::OpDefBuilderWrapper::SetShapeFn(tensorflow::Status ()(tensorflow::shape_inference::InferenceContext))' OpDefBuilderWrapper&SetShapeFn(

为什么会这样?我该如何解决?

【问题讨论】:

    标签: python c++ compiler-errors tensorflow new-operator


    【解决方案1】:

    假设您唯一的问题是未定义的Status 类型——除此之外,复制和粘贴教程代码都可以正常工作——您需要将using namespace tensorflow 移动到第一次使用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();
        });
    

    【讨论】:

      【解决方案2】:

      在我看来,Tensorflow tutorial 没有正确的代码。 所以我遵循了tutorial 的代码,它运行良好! 我不知道它在说什么!

      【讨论】:

        猜你喜欢
        • 2018-05-21
        • 1970-01-01
        • 2017-04-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-04-08
        相关资源
        最近更新 更多