博客:blog.shinelee.me | 博客园 | CSDN
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