Caffe的Net初始化

Caffe的Net初始化

基本情况

源文件:
src/caffe/net.cpp
include/caffe/net.hpp
python/caffe/_caffe.cpp

定义Net对象:可以同时指定prototoxt和caffemodel,也可以先Prototxt再从caffemodel复制blobs取值;Python/C++均可。e.g.

net = caffe.Net(prototxt, caffemodel, caffe.TEST)

定义Net对象,C++:

shared_ptr< Net<float> > net(new caffe::Net<float>(prototxt, TEST));
net->CopyTrainedLayersFrom(caffemodel);

Net对象初始化

构造函数把任务转移给了Init()函数:

template <typename Dtype>
Net<Dtype>::Net(const NetParameter& param) {
  Init(param);
}
template <typename Dtype>
void Net<Dtype>::Init(const NetParameter& in_param) {
    ... //超长的一大串内容
}

Init()函数主要内容包括:

  • 找到并插入各种split层:FilterNet()和InsertSplits()
  • 各layer的建立:
    layers_.push_back(LayerRegistry<Dtype>::CreateLayer(layer_param));
  • 设置各layer的blobs,保证连接性
  • 真正的建立起各个layer:
    layers_[layer_id]->SetUp(bottom_vecs_[layer_id], top_vecs_[layer_id]);

建立各个layer的时候,调用了LayerSetUp()Reshape()函数。

// include/caffe/layer.hpp

void SetUp(const vector<Blob<Dtype>*>& bottom,
    const vector<Blob<Dtype>*>& top) {
  CheckBlobCounts(bottom, top);
  LayerSetUp(bottom, top); //
  Reshape(bottom, top);    //
  SetLossWeights(top);
}
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值