2017-08-14 94 views
0

在github上,一个OpOutputList初始化像这样:如何使用Tensorflow的OpOutputList?

OpOutputList outputs; 
OP_REQUIRES_OK(context, context->output_list("output",&outputs)); 

和张量增加这样的:

Tensor* tensor0 = nullptr; 
Tensor* tensor1 = nullptr; 
long long int sz0 = 3; 
long long int sz1 = 4; 
... 
OP_REQUIRES_OK(context, outputs.allocate(0, TensorShape({sz0}), &tensor0)); 
OP_REQUIRES_OK(context, outputs.allocate(1, TensorShape({sz1}), &tensor1)); 

我假设OpOutputList就像OpInputList在交错数组是允许的。

我的问题是,OpOutputList如何工作?有时我会遇到段错误,因为我在使用Eigen::Tensor::flat()时无法访问第一个索引,但由于我不明白分配是如何工作的,所以无法查明错误。

非常感谢。

回答

0

OpOutputList对象本身是一个非常简单的值对象,它只包含两个整数 - 包含在此列表中的op输出的开始和结束索引。作为简单的值对象,你通常只是在堆栈上创建它们,不需要“分配”。

您可以像任何其他张量一样分配逻辑上属于OpOutputList的张量。一般使用allocate_output()。这里是OpOutputList::allocate实现:

Status OpOutputList::allocate(int i, const TensorShape& shape, 
           Tensor** output) { 
DCHECK_GE(i, 0); 
DCHECK_LT(i, stop_ - start_); 
return ctx_->allocate_output(start_ + i, shape, output); 
} 

正如你可以看到它只是检查该指数i确实是这个OpOutputList内,并呼吁allocate_output