TensorFlow:如何将值包装为标量Tensor而不是1x1 Tensor

时间:2019-05-20 20:51:36

标签: python c++ tensorflow

我有以下代码,试图将bool值包装到tensorflow :: Tensor中。

tensorflow::Tensor vector_to_tensor_bool(const std::vector<bool> &input_vec) {
    tensorflow::Tensor tensor_1d(tensorflow::DT_BOOL, tensorflow::TensorShape({1}));
    auto tensor_1d_map = tensor_1d.tensor<bool, 1>();
    tensor_1d_map(0) = input_vec[0];
    return tensor_1d;
}

但是,我得到了错误:

 Caused by: Invalid argument: The second input must be a scalar, but it has shape [1]

我认为这是在说我应该将其设为标量张量,而不是1x1张量。如何将常规值转换为标量Tensor值?谢谢!

0 个答案:

没有答案