如何转换eigen :: tensormap float*



我正在实现tensorflow :: op(https://www.tensorflow.org/versions/r0.12/how_tos/adding_an_op/#verify_it_torks(。

我想调用一个函数向前((,该函数将float指针作为参数。在第一个参数上,我无法将张量转换为浮点指针。

REGISTER_OP("ForwardMatching")
.Input("input0: float32")
.Input("input1: float32")
.Input("disparities: float32")
.Input("output: float32")
.Input("in: int32")
.Input("ic: int32")
.Input("ih: int32")
.Input("iw: int32")
.Input("lendisps: int32")
.Input("memorylayout: int32")
.Input("rectcorr: int32")
.Output("zeroed: int32")
.SetShapeFn([](::tensorflow::shape_inference::InferenceContext* c) {
    c->set_output(0, c->input(0));
    return Status::OK();
});
class ForwardMatchingOp : public OpKernel {
public:
    std::vector<cudnnTensorDescriptor_t> a;
    StereoCorrelation* sc = new StereoCorrelation(a);
    explicit ForwardMatchingOp(OpKernelConstruction* context) : OpKernel(context) {}
        void Compute(OpKernelContext* context) override {
            // Grab the input tensor
            const Tensor& input0_tensor = context->input(0);
            iu::TensorGpu_32f::MemoryLayout ml;
            float *i0, *i1, *disp;
            int in, ic, ih, iw, lendisps, rectcor;
            float *output;
            sc->forward(input0,i1,disp, output, in, ic, ih, iw, lendisps, ml, rectcor);
    } 
};

错误消息:

note:   no known conversion for argument 1 from ‘Eigen::TensorMap<Eigen::Tensor<const float, 1, 1, long int>, 16, Eigen::MakePointer>’ to ‘float*’

转换为

Tensor A;
float *a_data = A.flat<float>().data();
size_t a_len = A.NumElements()

这里 flat()返回一个特征::张tensor:

/// brief Return the tensor data as an `Eigen::Tensor` of the data type and a
/// specified shape.
template <typename T>
typename TTypes<T>::Flat flat() {
  return shaped<T, 1>({NumElements()});
}

data()是特定于特征的。NumElements()

/// Convenience accessor for the tensor shape.
int64 NumElements() const { return shape().num_elements(); }

最新更新