caffe(1)基础数据结构-Blob

caffe代码层次:
  • Blob:是基础的数据结构,是用来保存学习到的参数以及网络传输过程中产生数据的类。
  • Layer:是网络的基本单元,由此派生出了各种层类。修改这部分的人主要是研究特征表达方向的。
  • Net:是网络的搭建,将Layer所派生出层类组合成网络。Solver:是Net的求解,修改这部分人主要会是研究DL求解方向的。


BLob只是一个基本的数据结构,以Protobuf方式存储,Protobuf是一种可以实现内存与外存交换的协议接口。
1、主要变量:
shared_ptr<SyncedMemory> data_; 
shared_ptr<SyncedMemory> diff_;
shared_ptr<SyncedMemory> shape_data_;
vector<int> shape_;
int count_; 
int capacity_;
Data: 主要存储前向传递的数据;
diff:主要存储的是反向传播中的梯度;
s hape_datashape_都是存储Blo b的形状,一个是老版本一个是新版本,对于Blob中的4个基本变 num,channel,height,width 可以直接通过 shape(0),shape(1),shape(2),shape(3) 来访问。
2、主要函数:
void Reshape(const int num, const int channels, const int height, const int width)
Reshape函数在Layer中的reshape或者forward操作中来adjust dimension。同时在改变Blob大小时,内存将会被重新分配如果内存大小不够了,并且额外的内存将不会被释放;

inline int count(int start_axis, int end_axis)
count:函数用于统计Blob的容量;

inline int offset(const int n, const int c = 0const int h = 0const int w = 0) inline int offset(const vector<int>& indices)
计算offset;

const Dtype* cpu_data() const
void set_cpu_data(Dtype* data);
const int* gpu_shape() const;
const Dtype* gpu_data() const
const Dtype* cpu_diff() const
const Dtype* gpu_diff() const
Dtype* mutable_cpu_data()
Dtype* mutable_gpu_data()
Dtype* mutable_cpu_diff()
Dtype* mutable_gpu_diff();
这一部分函数主要在通过cpu_data*指针获得地址,

inline Dtype data_at(const int n, const int c, const int h, const int w) 
inline Dtype diff_at(const int n, const int c, const int h, const int w) 
inline Dtype data_at(const vector<int>& index)
inline Dtype diff_at(const vector<int>& index) 
inline const shared_ptr<SyncedMemory>& data() 
inline const shared_ptr<SyncedMemory>& diff()
通过给定的位置访问数据,根据位置计算与数据起始的偏差offset,。

void  CopyFrom( const  Blob<Dtype>& source, bool copy_diff = false,bool reshape = false)
从一个Blob中copy数据,若copy_diff是False则copy data,否则copy diff,reshape控制是否需要reshape;

void  FromProto( const  BlobProto& proto, bool reshape = true)
void  ToProto(BlobProto* proto, bool write_diff = false)  const
这两个函数主要 是将数据序列化,对Protobuf 存储或读取 Protobuf是谷歌的一个数据序列化的存储格式,参见: http://blog.csdn.net/kkk584520/article/details/41046827
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值