【发布时间】:2018-04-16 03:45:50
【问题描述】:
我有一个来自输入的 shape(2,2,3) 张量。我可以通过.shape() 得到这个张量的形状,它可以用来帮助迭代。但是我无法迭代它,这可能是由于错误转换为矩阵而导致的,而矩阵的维度总是 2 代码如下所示:
const Tensor& input = context->input(0); // get the input
DCHECK_EQ(input.dims(), 3); //check the dimission==3
const TensorShape& input_shape = input.shape(); //get the shape of the tensor
auto input_tensor = input.matrix<float>();//wrong conversion
for(int i=0; i<input_shape.dim_size(0); i++)
{
for(int j=0; j<input_shape.dim_size(1); j++)
{
for(int k=0; k<input_shape.dim_size(2); k++)
{
count<<input_tensor(i,j,k);//wrong code
}
}
}
所以,我想知道迭代这个张量的方法。非常感谢!
【问题讨论】:
标签: c++ tensorflow tensor