我使用 DEBUG=1
标志构建我的 caffe。因此我能够使用 gdb 对其进行调试。
my debug programs was the mnist example:
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 的数据,但找不到方法。
我能得到的是:
- bottom and top are vector of 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>
- I can find the meta-data of this 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
}
but i failed to get the data. the only thing i can do is
(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
}
How can i print the data_ and diff_ member of this blob?
最佳答案
例如:
(gdb) p *((float *)(bottom[1].data_.px)->cpu_ptr_+0)
$15 = 0
或
(gdb) p *((float *)(bottom[1].data_.px)->cpu_ptr_+1)
$16 = 1
而且它还需要将 (float *)
替换为您实际的 blob 指针类型。
关于caffe:如何使用gdb访问BLOB中的数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38136145/