c++ - 我想通过 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);
}
解决方案
我们可以使用张量的 data() 函数来解决这个问题。
例如p (std::__1::string *)(tensor->buf_->data())
,为什么我们可以在 lldb 中使用 data() 函数?
推荐阅读
- spring-boot - 不例外的百里香叶符号和不例外的值
- python - 如何使用 PyO3 构建混合 Python Rust 包
- javascript - 将电子邮件数据从一个 HTML 文件传输到另一个以“%40”而不是“@”显示的文件
- python - cudf 读取 csv 文件错误:字符串的总大小对于 cudf 列来说太大了
- c++ - CRTP 与模板专业化和标签调度
- rust - Serde 有条件地反序列化序列中的每个项目
- java - 使用选择排序对数组进行排序
- python - 操作 XML (Python) 后无法编辑 Docx 文档文本
- api - ExpressJS/Mocha:测试期间找不到模型文档
- android - 科尔多瓦有可用于 Wi-Fi Direct 的插件吗?