我有以下代码,试图将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值?谢谢!