tensorflow에 사용자 정의 된 op를 추가하려고했지만 파이썬에서로드 할 수 없습니다. 질문은 github의 닫힌 issue과 비슷하지만 문제가 해결되지 않았습니다.tensorflow에서 사용자 정의 된 op 공유 라이브러리를로드 할 수 없습니다.
운영 체제 : CUDA와 cuDNN의 맥 OS 10.12
설치된 버전 : 없음 소스에서 설치
TensorFlow 0.11.0.
#include "tensorflow/core/framework/op.h"
REGISTER_OP("ZeroOut")
.Input("to_zero: int32")
.Output("zeroed: int32");
#include "tensorflow/core/framework/op_kernel.h"
using namespace tensorflow;
class ZeroOutOp : public OpKernel {
public:
explicit ZeroOutOp(OpKernelConstruction* context) : OpKernel(context) {}
void Compute(OpKernelContext* context) override {
// Grab the input tensor
const Tensor& input_tensor = context->input(0);
auto input = input_tensor.flat<int32>();
// Create an output tensor
Tensor* output_tensor = NULL;
OP_REQUIRES_OK(context, context->allocate_output(0, input_tensor.shape(),
&output_tensor));
auto output = output_tensor->flat<int32>();
// Set all but the first element of the output tensor to 0.
const int N = input.size();
for (int i = 1; i < N; i++) {
output(i) = 0;
}
// Preserve the first input value if possible.
if (N > 0) output(0) = input(0);
}
};
REGISTER_KERNEL_BUILDER(Name("ZeroOut").Device(DEVICE_CPU), ZeroOutOp);
및 bazel 빌드 파일 :
load("//tensorflow:tensorflow.bzl", "tf_custom_op_library")
tf_custom_op_library(
name = "zero_out.so",
srcs = ["zero_out.cc"]
)
그때 내가 실행
은 내가 add new op 튜토리얼 추가 zero_out.cc 파일을 다음bazel build -c opt //tensorflow/core/user_ops:zero_out.so
출력 :
INFO: Waiting for response from Bazel server (pid 28589)...
INFO: Found 1 target...
Target //tensorflow/core/user_ops:zero_out.so up-to-date:
bazel-bin/tensorflow/core/user_ops/zero_out.so
INFO: Elapsed time: 5.115s, Critical Path: 0.00s
생성 된 공유 라이브러리는 bazel-bin에 있습니다.
tf.load_op_library('/Users/dtong/code/data/tensorflow/bazel-bin/tensorflow/core/user_ops/zero_out.so')
결과 : 나는이 같은로드하려고 할 때
python(41716,0x7fffb7e123c0) malloc: *** error for object 0x7f9e9cd2de18: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug