博客:blog.shinelee.me | 博客园 | 优快云
Blob作用
据Caffe官方描述:
A Blob is a wrapper over the actual data being processed and passed along by Caffe, and also under the hood provides synchronization capability between the CPU and the GPU. Mathematically, a blob is an N-dimensional array stored in a C-contiguous fashion.
Caffe stores and communicates data using blobs. Blobs provide a unified memory interface holding data; e.g., batches of images, model parameters, and derivatives for optimization.
Blobs conceal the computational and mental overhead of mixed CPU/GPU operation by synchronizing from the CPU host to the GPU device as needed. Memory on the host and device is allocated on demand (lazily) for efficient memory usage.
Blob是Caffe中的基础数据结构,主要作用如下:
- 存储和传输数据,对外提供统一的内存接口。在Caffe中,输入图像、每层的权重和反向传播时的梯度、每层的输入和输出等都以
Blob形式管理 - 隐藏CPU和GPU之间数据同步的细节(通过
SyncedMemory实现),用户使用时不需要自己管理CPU和GPU间的数据同步
在逻辑上,Blob是个 N d N_d Nd维张量。当 N d = 4 N_d=4 Nd=4时,Blob的shape定义为 N ∗ C ∗ H ∗ W N * C * H * W N∗C∗H∗W,即 N u m ∗ C h a n n e l ∗ H e i g h t ∗ W i d t h Num * Channel * Height * Width Num∗Channel∗Height∗Width,可以表示输入图像Batch、卷积层的kernel参数、卷积层的输入输出map等;当 N d = 2 N_d=2 Nd=2时,可以表示全连接层的权重, N o u t ∗ N i n N_{out} * N_{in} Nout∗Nin;当 N d = 1 N_d=1 Nd=1时,可以表示卷积层和全连接层的bias参数。
具体地,
- N d = 4 N_d=4 Nd=4,
Blob表示输入图像时, N N N为当前批次的图片数量即MiniBatchNum, C C C为图像的通道数,RGB图 C = 3 C=3 C=3, H H H和 W W W为图像的高和宽。 - N d = 4 N_d=4 Nd

Blob作为Caffe的基础数据结构,用于存储和传输数据,提供统一内存接口。它隐藏了CPU与GPU之间的数据同步,根据需求自动同步。Blob支持Nd维数组,常用于表示图像批次、模型参数等。主要成员变量包括数据区,行优先存储。成员函数涉及构造、设置、数据更新、运算和辅助操作。在训练过程中,Blob通过Update函数更新参数。
最低0.47元/天 解锁文章
6247

被折叠的 条评论
为什么被折叠?



