How to fill a tensor in C++

前端 未结 2 819
死守一世寂寞
死守一世寂寞 2021-02-01 09:14

I\'m creating a tensor like this:

tensorflow::Tensor a(tensorflow::DT_FLOAT, tensorflow::TensorShape());

I know how to fill a scalar value:

2条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-01 09:55

    tensorflow::Input::Initializer a({{1, 2}, {3, 4}});
    

    Actually it works in compiling, but errors when running, which shows that a is a tensor with [0] tensorshape. I don't know where is wrong, but my successful way is:

    tensorflow::Input::Initializer a({1, 2, 3, 4}, tensorflow::TensorShape({2, 2}));
    

提交回复
热议问题