首页 > 解决方案 > 我想通过 lldb 打印张量值

问题描述

在此处输入图像描述

我想打印 buf_ 中的 Buffer 成员变量,也就是说,我想p *(tensorflow::Buffer*)buf_打印 Buffer 类中的成员变量。

tensorflow 中的代码,1.10.1。

类关系:类TensorBuffer是tensor.h中的基类,Buffer是tensor.cc中的模板和派生类

以下是lldb的输出:</p>

frame #0: 0x0000000175abffc0 

libtensorflow_framework.so`tensorflow::Tensor::Tensor(this=0x000070000cadd308, a=0x00007fd91ea61500, type=DT_STRING, shape=0x000070000cadd2f0) at tensor.cc:726:3

     723  CHECK_NOTNULL(a);

     724  if (shape_.num_elements() > 0 || a->ShouldAllocateEmptyTensors()) {

     725    CASES(type, buf_ = new Buffer<T>(a, shape.num_elements()));

->   726  }


(lldb) p buf_

(tensorflow::TensorBuffer *) $17 = 0x00007fd91e927c40

(lldb) p *(Buffer<std::__1::string>*)buf_

error: use of undeclared identifier 'Buffer'

error: expected '(' for function-style cast or type construction

error: expected expression

(lldb) p *(tensorflow::Buffer<std::__1::string>*)buf_

error: no member named 'Buffer' in namespace 'tensorflow'

error: expected '(' for function-style cast or type construction

error: expected expression

第 725 行解码:

switch(type)

case DataTypeToEnum<string>::value :

{

    typedef string T;

    buf_ = new Buffer<T>(a, shape.num_elements(), allocation_attr);

}

标签: c++tensorflowlldb

解决方案


我们可以使用张量的 data() 函数来解决这个问题。

例如p (std::__1::string *)(tensor->buf_->data()) ,为什么我们可以在 lldb 中使用 data() 函数?


推荐阅读