caffe中的Blob块
首先说明:Blob定义了一个类模板。
让我们看一下Blob的头文件里有什么哈:
定义了一个全局变量:
const int kMaxBlobAxes = 32;
看看它的构造函数:
Blob() : data_(), diff_(), count_(0), capacity_(0) {};
explicit Blob(const int num, const int channels, const int height,const int width);
explicit Blob(const vector<int>& shape);
Reshape函数:
void Reshape(const int num, const int channels, const int height, const int width);
void Reshape(const vector<int>& shape);
void Reshape(const BlobShape& shape);
void ReshapeLike(const Blob& other);
内联函数shape_string:作用就是把shape的数据变为字符输出,里面用到了ostringstream流;
inline string shape_string() const {
ostringstream stream;
for (int i = 0; i < shape_.size(); ++i) {
stream << shape_[i] << " ";
}
stream << "(" << count_ << ")";
return stream.str();
}
内联函数shape():
//作用:返回shape_的引用;
inline const vector<int>& shape() const { return shape_; }
//作用:输入第几维度,返回该维度的大小;
inline int shape(int index) const {
return shape_[CanonicalAxisIndex(index)];
//内联函数:num_axes(),作用:返回是多少维度的块;
inline int num_axes() const { return shape_.size(); }
//内联函数:count():
inline int count() const { return count_; } //返回一共多少数据啊,;
inline int count(int start_axis, int end_axis) const //返回输入的索引之间的大小;
inline int count(int start_axis) const //太麻烦了,不写了,自己看代码吧;
canonicalAxisIndex的作用就是:把正的索引不变,负的改为正的,另外,还是检查一下它们的范围啦;
CanonicalAxisIndex(int axis_index) const
offset函数就是计算一下索引的偏移值,因为吧,多维数组在内存里也是按一维 存放的:
inline int offset(const int n, const int c = 0, const int h = 0, const int w = 0) const {
……
return ((n * channels() + c) * height() + h) * width() + w;
}
// 用向量的方式把坐标值传入:
inline int offset(const vector<int>& indices) const
函数copyfrom,作用把数据从Blob块中复制到内存中
void CopyFrom(const Blob<Dtype>& source, bool copy_diff = false, bool reshape = false);
查看数据的函数:
inline Dtype data_at(const int n, const int c, const int h, const int w) const
inline Dtype diff_at(const int n, const int c, const int h, const int w) const
inline Dtype data_at(const vector<int>& index) const
inline Dtype diff_at(const vector<int>& index) const
获得data_与diff_的函数:
inline const shared_ptr<SyncedMemory>& data() const {
CHECK(data_);
return data_;
}
inline const shared_ptr<SyncedMemory>& diff() const {
CHECK(diff_);
return diff_;
}
另外还有好几个函数,尼玛,有点多哎
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();
void Update();
void FromProto(const BlobProto& proto, bool reshape = true);
void ToProto(BlobProto* proto, bool write_diff = false) const; /// @brief Compute the sum of absolute values (L1 norm) of the data.
Dtype asum_data() const;
/// @brief Compute the sum of absolute values (L1 norm) of the diff.
Dtype asum_diff() const;
/// @brief Compute the sum of squares (L2 norm squared) of the data.
Dtype sumsq_data() const;
/// @brief Compute the sum of squares (L2 norm squared) of the diff.
Dtype sumsq_diff() const;
/// @brief Scale the blob data by a constant factor.
void scale_data(Dtype scale_factor);
/// @brief Scale the blob diff by a constant factor.
void scale_diff(Dtype scale_factor);
还有:
/**
* @brief Set the data_ shared_ptr to point to the SyncedMemory holding the
* data_ of Blob other -- useful in Layer%s which simply perform a copy
* in their Forward pass.
*
* This deallocates the SyncedMemory holding this Blob's data_, as
* shared_ptr calls its destructor when reset with the "=" operator.
*/
void ShareData(const Blob& other);
/**
* @brief Set the diff_ shared_ptr to point to the SyncedMemory holding the
* diff_ of Blob other -- useful in Layer%s which simply perform a copy
* in their Forward pass.
*
* This deallocates the SyncedMemory holding this Blob's diff_, as
* shared_ptr calls its destructor when reset with the "=" operator.
*/
void ShareDiff(const Blob& other); bool ShapeEquals(const BlobProto& other);
下面是定义的变量:
shared_ptr<SyncedMemory> data_;
shared_ptr<SyncedMemory> diff_;
shared_ptr<SyncedMemory> shape_data_;
vector<int> shape_;
int count_;
int capacity_;
caffe中的Blob块的更多相关文章
- 【caffe Blob】caffe中与Blob相关的代码注释、使用举例
首先,Blob使用的小例子(通过运行结果即可知道相关功能): #include <vector> #include <caffe/blob.hpp> #include < ...
- (Caffe)基本类Blob,Layer,Net(一)
本文地址:http://blog.csdn.net/mounty_fsc/article/details/51085654 Caffe中,Blob.Layer,Net,Solver是最为核心的类,下面 ...
- caffe中python接口的使用
下面是基于我自己的接口,我是用来分类一维数据的,可能不具通用性: (前提,你已经编译了caffe的python的接口) 添加 caffe塻块的搜索路径,当我们import caffe时,可以找到. 对 ...
- caffe代码阅读10:Caffe中卷积的实现细节(涉及到BaseConvolutionLayer、ConvolutionLayer、im2col等)-2016.4.3
一. 卷积层的作用简单介绍 卷积层是深度神经网络中的一个重要的层,该层实现了局部感受野.通过这样的局部感受野,能够有效地减少參数的数目. 我们将结合caffe来解说详细是怎样实现卷积层的前传和反传的. ...
- 【撸码caffe 二】 blob.hpp
Blob类是caffe中对处理和传递的实际数据的封装,是caffe中基本的数据存储单元,包括前向传播中的图像数据,反向传播中的梯度数据以及网络层间的中间数据变量(包括权值,偏置等),训练模型的参数等等 ...
- caffe中权值初始化方法
首先说明:在caffe/include/caffe中的 filer.hpp文件中有它的源文件,如果想看,可以看看哦,反正我是不想看,代码细节吧,现在不想知道太多,有个宏观的idea就可以啦,如果想看代 ...
- caffe中各层的作用:
关于caffe中的solver: cafffe中的sover的方法都有: Stochastic Gradient Descent (type: "SGD"), AdaDelta ( ...
- caffe中的filler.hpp源码的作用:
filler.hpp文件:(它应该没有对应的.cpp文件,一切实现都是在头文件中定义的,可能是因为filler只分在网络初始化时用到那么一次吧) 1,首先定义了基类:Filler,它包括:一个纯虚函数 ...
- CAFFE中训练与使用阶段网络设计的不同
神经网络中,我们通过最小化神经网络来训练网络,所以在训练时最后一层是损失函数层(LOSS), 在测试时我们通过准确率来评价该网络的优劣,因此最后一层是准确率层(ACCURACY). 但是当我们真正要使 ...
随机推荐
- 每日一九度之 题目1039:Zero-complexity Transposition
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:3372 解决:1392 题目描述: You are given a sequence of integer numbers. Zero-co ...
- hbase 停止regionserver
每个regionserver节点可以自由启动或停止,可以不随hbase整体一起. 停止后regionserver上的数据会被移到其他regionserver上,不影响hbase的使用. 停止reg ...
- 测试-Unity修改权重
以下内容仅为猜想,只进行了初步验证 FBX骨骼中包含所绑定的顶点索引,导入Unity后,Unity会把层级树保存起来,然后实例化的时候映射过去 编辑器下权重信息本身不在fbx文件的meta里,不可修改 ...
- webform数据导出
把数据放到一个泛型集合里,再把泛型集合里面的数据放到一个table中,设置好文件路径,然后进行文件读取,最后供用户下载. 数据导出放在一个按钮中就可以了 using System; using Sys ...
- out 传值
public void Out(out int a, out int b) {//out相当于return返回值 //可以返回多个值 //拿过来变量名的时候,里面默认为空值 a=1; b=2; } s ...
- 软件密码和https协议
密码安全问题,一直是程序员最痛疼的问题,这一章主要的来说一下密码的安全,和怎么提高密码的安全,还有Tomcat的https协议. 密码对于一个程序的安全有多重要就不多说了,如果你做过银行系统的话,那么 ...
- thinkphp model层外挪,以便多个站点可以通用
/ThinkPHP/ThinkPHP.php 增加如下代码 //非原始代码defined('BASE_LOGIC') or define('BASE_LOGIC', THINK_PATH . '.. ...
- 高通平台msm8909 LK 实现LCD 兼容
前段时间小米出现红米note2 换屏门,现在我们公司也要上演了:有两个供应商提供不同IC 的LCD panel. 软件区分的办法是读取LCD IC 的ID 寄存器,下面解析高通平台LK中LCD兼容的过 ...
- C#语法基础用法Dictionary排序
Dictionary排序 1.先看效果图: 2.核心逻辑如下: Dictionary<int, string> list = new Dictionary<int, string&g ...
- CSS hack的写法
css hack简单的说就是由于不同的浏览器,比如Internet Explorer 6,Internet Explorer 7,Mozilla Firefox等,对CSS的解析认识不一样,因此会导致 ...