梳理caffe代码blob三Word文件下载.docx
《梳理caffe代码blob三Word文件下载.docx》由会员分享,可在线阅读,更多相关《梳理caffe代码blob三Word文件下载.docx(29页珍藏版)》请在冰豆网上搜索。
caffe/proto/caffe.pb.h"
caffe/syncedmem.hpp"
caffe/util/math_functions.hpp"
constintkMaxBlobAxes=INT_MAX;
namespacecaffe{
/**
*@briefAwrapperaroundSyncedMemoryholdersservingasthebasic
*computationalunitthroughwhichLayer%s,Net%s,andSolver%s
*interact.
*
*TODO(dox):
morethoroughdescription.
*/
template&
typenameDtype&
classBlob{
public:
Blob()
:
data_(),diff_(),count_(0),capacity_(0){}
///@briefDeprecated;
use&
code&
Blob(constvector&
int&
&
amp;
shape)&
/code&
.
//explicit关键字的作用是禁止单参数构造函数的隐式转换
explicitBlob(constintnum,constintchannels,constintheight,
constintwidth);
explicitBlob(constvector&
shape);
Reshape(constvector&
/*
Reshape函数将num,channels,height,width传递给vectorshape_
*/
voidReshape(constintnum,constintchannels,constintheight,
/**
*Blob作为一个最基础的类,其中构造函数开辟一个内存空间来存储数据,Reshape函数在Layer中的
*reshape或者forward操作中来adjustthedimensionsofatopblob。
同时在改变Blob大小时,
*内存将会被重新分配如果内存大小不够了,并且额外的内存将不会被释放。
对input的blob进行reshape,
*如果立马调用Net:
:
Backward是会出错的,因为reshape之后,要么Net:
forward或者Net:
Reshape就会
*被调用来将新的inputshape传播到高层
//根据shape来初始化shape_和shape_data_,以及为data_和diff_分配空间。
voidReshape(constvector&
voidReshape(constBlobShape&
voidReshapeLike(constBlob&
other);
//iniline主要是将代码进行复制,扩充,会使代码总量上升,好处就是可以节省调用的开销,以string形式获取shape_
inlinestringshape_string()const{
ostringstreamstream;
for(inti=0;
i&
shape_.size();
++i){
stream&
shape_[i]&
"
;
}
("
&
count_&
)"
returnstream.str();
//获取shape_
inlineconstvector&
shape()const{returnshape_;
*@briefReturnsthedimensionoftheindex-thaxis(orthenegativeindex-th
*axisfromtheend,ifindexisnegative).
*@paramindextheaxisindex,whichmaybenegativeasitwillbe
*"
canonicalized"
usingCanonicalAxisIndex.
*Diesonoutofrangeindex.
//获取index维的大小
inlineintshape(intindex)const{
returnshape_[CanonicalAxisIndex(index)];
//获取维的个数
inlineintnum_axes()const{returnshape_.size();
//获取当前data的大小
inlineintcount()const{returncount_;
*@briefComputethevolumeofaslice;
i.e.,theproductofdimensions
*amongarangeofaxes.
*@paramstart_axisThefirstaxistoincludeintheslice.
*@paramend_axisThefirstaxistoexcludefromtheslice.
/*多个count()函数,主要还是为了统计Blob的容量(volume),或者是某一片(slice),
从某个axis到具体某个axis的shape乘积。
//获取某几维数据的大小
inlineintcount(intstart_axis,intend_axis)const{
CHECK_LE(start_axis,end_axis);
CHECK_GE(start_axis,0);
CHECK_GE(end_axis,0);
CHECK_LE(start_axis,num_axes());
CHECK_LE(end_axis,num_axes());
intcount=1;
for(inti=start_axis;
end_axis;
count*=shape(i);
returncount;
*@briefComputethevolumeofaslicespanningfromaparticularfirst
*axistothefinalaxis.
//获取某一维到结束数据的大小
inlineintcount(intstart_axis)const{
returncount(start_axis,num_axes());
*@briefReturnsthe'
canonical'
versionofa(usually)user-specifiedaxis,
*allowingfornegativeindexing(e.g.,-1forthelastaxis).
*@paramindextheaxisindex.
*If0&
=index&
num_axes(),returnindex.
*If-num_axes&
=-1,return(num_axes()-(-index)),
*e.g.,thelastaxisindex(num_axes()-1)ifindex==-1,
*thesecondtolastifindex==-2,etc.
//Blob的Index是可以从负坐标开始读的,标准化索引,主要是对参数索引进行标准化,以满足要求
inlineintCanonicalAxisIndex(intaxis_index)const{
CHECK_GE(axis_index,-num_axes())
axis"
axis_index&
outofrangefor"
num_axes()
-DBlobwithshape"
shape_string();
CHECK_LT(axis_index,num_axes())
if(axis_index&
0){
returnaxis_index+num_axes();
returnaxis_index;
//Blob中的4个基本变量num,channel,height,width可以直接通过shape(0),shape
(1),shape
(2),shape(3)来访问
///@briefDeprecatedlegacyshapeaccessornum:
useshape(0)instead.
inlineintnum()const{returnLegacyShape(0);
///@briefDeprecated