gpt4 book ai didi

python - 编译 new_op 教程时出错(Tensorflow)

转载 作者:行者123 更新时间:2023-11-28 05:27:31 24 4
gpt4 key购买 nike

我想学习如何install new op .因此,为此我正在按照给定的教程进行操作。我创建了一个名为 user_ops 的文件夹,创建了一个“zero_out.cc”文件并复制了教程中给出的代码。当我尝试将 Op 编译成动态库时出现 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(<

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

最佳答案

假设您唯一的问题是未定义的 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();
});

关于python - 编译 new_op 教程时出错(Tensorflow),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40242491/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com