参考:caffe官网 2016-01-23 10:08:22
1 blobs,layers,nets是caffe模型的骨架
2 blobs是作者写好的数据存储的“容器”,可以有效实现CPU和GPU之间的同步(隐藏了这些复杂的操作),搬移,传递等。它提供了统一的接口,可以存储数据,如batches of images, model parameters, and derivatives for optimization等。
3 blobs最后一层改变最快。若blobs为(n, k, h, w),即寻址时,地址加1是最后一维n加1.
5 Number / N is the batch size of the data和Channel / K is the feature dimension
6 使用blobs中通常存储data and diff ,前者是数据的值,后者是梯度值。进一步地,可以存在cpu中,也可以存在GPU中,访问有两种方式:
1 const Dtype* cpu_data() const; 2 Dtype* mutable_cpu_data();
(similarly for gpu and diff).
7 在GPU模式中,按照cpu模式将数据拷贝到blobs中,然后调用设备核去进行GPU计算,并将数据运到高层。只要所有层都配置了GPU模式,中间的计算过程的数据都保留在GPU中。判断Blobs是否拷贝了数据:
1 // Assuming that data are on the CPU initially, and we have a blob. 2 const Dtype* foo; 3 Dtype* bar; 4 foo = blob.gpu_data(); // data copied cpu->gpu. 5 foo = blob.cpu_data(); // no data copied since both have up-to-date contents. 6 bar = blob.mutable_gpu_data(); // no data copied. 7 // ... some operations ... 8 bar = blob.mutable_gpu_data(); // no data copied when we are still on GPU. 9 foo = blob.cpu_data(); // data copied gpu->cpu, since the gpu side has modified the data 10 foo = blob.gpu_data(); // no data copied since both have up-to-date contents 11 bar = blob.mutable_cpu_data(); // still no data copied. 12 bar = blob.mutable_gpu_data(); // data copied cpu->gpu. 13 bar = blob.mutable_cpu_data(); // data copied gpu->cpu.
时间: 2024-10-27 06:15:23