【问题标题】:caffe: how to access the data in BLOB using gdb?caffe:如何使用 gdb 访问 BLOB 中的数据?
【发布时间】:2016-07-01 02:32:41
【问题描述】:

我使用 DEBUG=1 标志构建我的 caffe。因此我可以使用 gdb 对其进行调试。

我的调试程序是 mnist 示例:

gdb --args .build_debug/tools/caffe train --solver=examples/mnist/lenet_solver.prototxt

我将断点设置在

./include/caffe/layer.hpp:451

对应的函数:

inline Dtype Layer<Dtype>::Forward(const vector<Blob<Dtype>*>& bottom,
const vector<Blob<Dtype>*>& top)

我试图打印出这个 BLOB 的 DATA 但找不到我的方式。

我能得到的是:

  • bottom 和 top 是 vvectors 的向量。
(gdb) p bottom
$30 = std::vector of length 2, capacity 2 = {0x4c24300, 0x4b12fd0}
(gdb) what bottom
type = const std::vector<caffe::Blob<float>*, std::allocator<caffe::Blob<float>*> > &
(gdb) what bottom[0]
type = std::vector<caffe::Blob<float>*, std::allocator<caffe::Blob<float>*> >::reference
(gdb) what bottom[0][0]
type = caffe::Blob<float>
  • 我可以找到这个 blob 的元数据
(gdb) p bottom[0][0]
$42 = {
  data_ = {
    px = 0x4c23710,
    pn = {
      pi_ = 0x4c23740
    }
  },
  diff_ = {
    px = 0x4c23fc0,
    pn = {
      pi_ = 0x4c23ff0
    }
  },
  shape_data_ = {
    px = 0x4c23f00,
    pn = {
      pi_ = 0x4c23f30
    }
  },
  shape_ = std::vector of length 2, capacity 2 = {100, 10},
  count_ = 1000,
  capacity_ = 1000
}

但我未能获取数据。我唯一能做的就是

(gdb) p bottom[0][0].data_
$43 = {
  px = 0x4c23710,
  pn = {
    pi_ = 0x4c23740
  }
}
(gdb) p bottom[0][0].data_.px[0]
$44 = {
  cpu_ptr_ = 0x474fef0,
  gpu_ptr_ = 0x0,
  size_ = 4000,
  head_ = caffe::SyncedMemory::HEAD_AT_CPU,
  own_cpu_data_ = true,
  cpu_malloc_use_cuda_ = false,
  own_gpu_data_ = false,
  gpu_device_ = -1
}

如何打印此 blob 的 data_ 和 diff_ 成员?

【问题讨论】:

    标签: caffe


    【解决方案1】:

    例如:

    (gdb) p *((float *)(bottom[1].data_.px)-&gt;cpu_ptr_+0)

    $15 = 0
    

    (gdb) p *((float *)(bottom[1].data_.px)-&gt;cpu_ptr_+1)

    $16 = 1
    

    还需要将(float *) 替换为您的实际blob 指针类型。

    【讨论】:

      猜你喜欢
      • 2017-07-08
      • 1970-01-01
      • 1970-01-01
      • 2015-03-21
      • 2018-03-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多