Caffe 增加自定义 Layer 及其 ProtoBuffer 参数
转载自:http://blog.csdn.net/kkk584520/article/details/52721838
http://blog.csdn.net/kkk584520
博客内容基于新书《深度学习:21 天实战 Caffe》,书中课后习题答案欢迎读者留言讨论。以下进入正文。
在使用 Caffe 过程中经常会有这样的需求:已有 Layer 不符合我的应用场景;我需要这样这样的功能,原版代码没有实现;或者已经实现但效率太低,我有更好的实现。
方案一:简单粗暴的解法——偷天换日
如果你对 ConvolutionLayer 的实现不满意,那就直接改这两个文件:$CAFFE_ROOT/include/caffe/layers/conv_layer.hpp 和 $CAFFE_ROOT/src/caffe/layers/conv_layer.cpp 或 conv_layer.cu ,将 im2col + gemm 替换为你自己的实现(比如基于 winograd 算法的实现)。
优点:快速迭代,不需要对 Caffe 框架有过多了解,糙快狠准。
缺点:代码难维护,不能 merge 到 caffe master branch,容易给使用代码的人带来困惑(效果和 #define TRUE false 差不多)。
方案二:稍微温柔的解法——千人千面
和方案一类似,只是通过预编译宏来确定使用哪种实现。例如可以保留 ConvolutionLayer 默认实现,同时在代码中增加如下段:
- #ifdef SWITCH_MY_IMPLEMENTATION
- // 你的实现代码
- #else
- // 默认代码
- #endif
这样可以在需要使用该 Layer 的代码中,增加宏定义:
- #define SWITCH_MY_IMPLEMENTATION
就可以使用你的实现。而未定义该宏的代码,仍然使用原版实现。
优点:可以在新旧实现代码之间灵活切换;
缺点:每次切换需要重新编译;
方案三:优雅转身——山路十八弯
同一个功能的 Layer 有不同实现,希望能灵活切换又不需要重新编译代码,该如何实现?
这时不得不使用 ProtoBuffer 工具了。
首先,要把你的实现,要像正常的 Layer 类一样,分解为声明部分和实现部分,分别放在 .hpp 与 .cpp、.cu 中。Layer 名称要起一个能区别于原版实现的新名称。.hpp 文件置于 $CAFFE_ROOT/include/caffe/layers/,而 .cpp 和 .cu 置于 $CAFFE_ROOT/src/caffe/layers/,这样你在 $CAFFE_ROOT 下执行 make 编译时,会自动将这些文件加入构建过程,省去了手动设置编译选项的繁琐流程。
其次,在 $CAFFE_ROOT/src/caffe/proto/caffe.proto 中,增加新 LayerParameter 选项,这样你在编写 train.prototxt 或者 test.prototxt 或者 deploy.prototxt 时就能把新 Layer 的描述写进去,便于修改网络结构和替换其他相同功能的 Layer 了。
最后也是最容易忽视的一点,在 Layer 工厂注册新 Layer 加工函数,不然在你运行过程中可能会报如下错误:
- F1002 01:51:22.656038 1954701312 layer_factory.hpp:81] Check failed: registry.count(type) == 1 (0 vs. 1) Unknown layer type: AllPass (known types: AbsVal, Accuracy, ArgMax, BNLL, BatchNorm, BatchReindex, Bias, Concat, ContrastiveLoss, Convolution, Crop, Data, Deconvolution, Dropout, DummyData, ELU, Eltwise, Embed, EuclideanLoss, Exp, Filter, Flatten, HDF5Data, HDF5Output, HingeLoss, Im2col, ImageData, InfogainLoss, InnerProduct, Input, LRN, Log, MVN, MemoryData, MultinomialLogisticLoss, PReLU, Pooling, Power, ReLU, Reduction, Reshape, SPP, Scale, Sigmoid, SigmoidCrossEntropyLoss, Silence, Slice, Softmax, SoftmaxWithLoss, Split, TanH, Threshold, Tile, WindowData)
- *** Check failure stack trace: ***
- @ 0x10243154e google::LogMessage::Fail()
- @ 0x102430c53 google::LogMessage::SendToLog()
- @ 0x1024311a9 google::LogMessage::Flush()
- @ 0x1024344d7 google::LogMessageFatal::~LogMessageFatal()
- @ 0x10243183b google::LogMessageFatal::~LogMessageFatal()
- @ 0x102215356 caffe::LayerRegistry<>::CreateLayer()
- @ 0x102233ccf caffe::Net<>::Init()
- @ 0x102235996 caffe::Net<>::Net()
- @ 0x102118d8b time()
- @ 0x102119c9a main
- @ 0x7fff851285ad start
- @ 0x4 (unknown)
- Abort trap: 6
下面给出一个实际案例,走一遍方案三的流程。
这里我们实现一个新 Layer,名称为 AllPassLayer,顾名思义就是全通 Layer,“全通”借鉴于信号处理中的全通滤波器,将信号无失真地从输入转到输出。
虽然这个 Layer 并没有什么卵用,但是在这个基础上增加你的处理是非常简单的事情。另外也是出于实验考虑,全通层的 Forward/Backward 函数非常简单不需要读者有任何高等数学和求导的背景知识。读者使用该层时可以插入到任何已有网络中,而不会影响训练、预测的准确性。
首先看头文件:
- #ifndef CAFFE_ALL_PASS_LAYER_HPP_
- #define CAFFE_ALL_PASS_LAYER_HPP_
- #include <vector>
- #include "caffe/blob.hpp"
- #include "caffe/layer.hpp"
- #include "caffe/proto/caffe.pb.h"
- #include "caffe/layers/neuron_layer.hpp"
- namespacecaffe {
- template<typenameDtype>
- classAllPassLayer :publicNeuronLayer<Dtype> {
- public:
- explicitAllPassLayer(constLayerParameter& param)
- : NeuronLayer<Dtype>(param) {}
- virtualinlineconstchar* type()const{return"AllPass"; }
- protected:
- virtualvoidForward_cpu(constvector<Blob<Dtype>*>& bottom,
- constvector<Blob<Dtype>*>& top);
- virtualvoidForward_gpu(constvector<Blob<Dtype>*>& bottom,
- constvector<Blob<Dtype>*>& top);
- virtualvoidBackward_cpu(constvector<Blob<Dtype>*>& top,
- constvector<bool>& propagate_down,constvector<Blob<Dtype>*>& bottom);
- virtualvoidBackward_gpu(constvector<Blob<Dtype>*>& top,
- constvector<bool>& propagate_down,constvector<Blob<Dtype>*>& bottom);
- };
- } // namespace caffe
- #endif // CAFFE_ALL_PASS_LAYER_HPP_
再看源文件:
- #include <algorithm>
- #include <vector>
- #include "caffe/layers/all_pass_layer.hpp"
- #include <iostream>
- usingnamespacestd;
- #define DEBUG_AP(str) cout<<str<<endl
- namespacecaffe {
- template<typenameDtype>
- voidAllPassLayer<Dtype>::Forward_cpu(constvector<Blob<Dtype>*>& bottom,
- constvector<Blob<Dtype>*>& top) {
- constDtype* bottom_data = bottom[0]->cpu_data();
- Dtype* top_data = top[0]->mutable_cpu_data();
- constintcount = bottom[0]->count();
- for(inti = 0; i < count; ++i) {
- top_data[i] = bottom_data[i];
- }
- DEBUG_AP("Here is All Pass Layer, forwarding.");
- DEBUG_AP(this->layer_param_.all_pass_param().key());
- }
- template<typenameDtype>
- voidAllPassLayer<Dtype>::Backward_cpu(constvector<Blob<Dtype>*>& top,
- constvector<bool>& propagate_down,
- constvector<Blob<Dtype>*>& bottom) {
- if(propagate_down[0]) {
- constDtype* bottom_data = bottom[0]->cpu_data();
- constDtype* top_diff = top[0]->cpu_diff();
- Dtype* bottom_diff = bottom[0]->mutable_cpu_diff();
- constintcount = bottom[0]->count();
- for(inti = 0; i < count; ++i) {
- bottom_diff[i] = top_diff[i];
- }
- }
- DEBUG_AP("Here is All Pass Layer, backwarding.");
- DEBUG_AP(this->layer_param_.all_pass_param().key());
- }
- #ifdef CPU_ONLY
- STUB_GPU(AllPassLayer);
- #endif
- INSTANTIATE_CLASS(AllPassLayer);
- REGISTER_LAYER_CLASS(AllPass);
- } // namespace caffe
时间考虑,我没有实现 GPU 模式的 forward、backward,故本文例程仅支持 CPU_ONLY 模式。
编辑 caffe.proto,找到 LayerParameter 描述,增加一项:
- message LayerParameter {
- optional string name = 1; // the layer name
- optional string type = 2; // the layer type
- repeated string bottom = 3; // the name of each bottom blob
- repeated string top = 4; // the name of each top blob
- // The train / test phase for computation.
- optional Phase phase = 10;
- // The amount of weight to assign each top blob in the objective.
- // Each layer assigns a default value, usually of either 0 or 1,
- // to each top blob.
- repeated floatloss_weight = 5;
- // Specifies training parameters (multipliers on global learning constants,
- // and the name and other settings used for weight sharing).
- repeated ParamSpec param = 6;
- // The blobs containing the numeric parameters of the layer.
- repeated BlobProto blobs = 7;
- // Specifies on which bottoms the backpropagation should be skipped.
- // The size must be either 0 or equal to the number of bottoms.
- repeated boolpropagate_down = 11;
- // Rules controlling whether and when a layer is included in the network,
- // based on the current NetState. You may specify a non-zero number of rules
- // to include OR exclude, but not both. If no include or exclude rules are
- // specified, the layer is always included. If the current NetState meets
- // ANY (i.e., one or more) of the specified rules, the layer is
- // included/excluded.
- repeated NetStateRule include = 8;
- repeated NetStateRule exclude = 9;
- // Parameters for data pre-processing.
- optional TransformationParameter transform_param = 100;
- // Parameters shared by loss layers.
- optional LossParameter loss_param = 101;
- // Layer type-specific parameters.
- //
- // Note: certain layers may have more than one computational engine
- // for their implementation. These layers include an Engine type and
- // engine parameter for selecting the implementation.
- // The default for the engine is set by the ENGINE switch at compile-time.
- optional AccuracyParameter accuracy_param = 102;
- optional ArgMaxParameter argmax_param = 103;
- optional BatchNormParameter batch_norm_param = 139;
- optional BiasParameter bias_param = 141;
- optional ConcatParameter concat_param = 104;
- optional ContrastiveLossParameter contrastive_loss_param = 105;
- optional ConvolutionParameter convolution_param = 106;
- optional CropParameter crop_param = 144;
- optional DataParameter data_param = 107;
- optional DropoutParameter dropout_param = 108;
- optional DummyDataParameter dummy_data_param = 109;
- optional EltwiseParameter eltwise_param = 110;
- optional ELUParameter elu_param = 140;
- optional EmbedParameter embed_param = 137;
- optional ExpParameter exp_param = 111;
- optional FlattenParameter flatten_param = 135;
- optional HDF5DataParameter hdf5_data_param = 112;
- optional HDF5OutputParameter hdf5_output_param = 113;
- optional HingeLossParameter hinge_loss_param = 114;
- optional ImageDataParameter image_data_param = 115;
- optional InfogainLossParameter infogain_loss_param = 116;
- optional InnerProductParameter inner_product_param = 117;
- optional InputParameter input_param = 143;
- optional LogParameter log_param = 134;
- optional LRNParameter lrn_param = 118;
- optional MemoryDataParameter memory_data_param = 119;
- optional MVNParameter mvn_param = 120;
- optional PoolingParameter pooling_param = 121;
- optional PowerParameter power_param = 122;
- optional PReLUParameter prelu_param = 131;
- optional PythonParameter python_param = 130;
- optional ReductionParameter reduction_param = 136;
- optional ReLUParameter relu_param = 123;
- optional ReshapeParameter reshape_param = 133;
- optional ScaleParameter scale_param = 142;
- optional SigmoidParameter sigmoid_param = 124;
- optional SoftmaxParameter softmax_param = 125;
- optional SPPParameter spp_param = 132;
- optional SliceParameter slice_param = 126;
- optional TanHParameter tanh_param = 127;
- optional ThresholdParameter threshold_param = 128;
- optional TileParameter tile_param = 138;
- optional WindowDataParameter window_data_param = 129;
- optional AllPassParameter all_pass_param = 155;
- }
注意新增数字不要和以前的 Layer 数字重复。
仍然在 caffe.proto 中,增加 AllPassParameter 声明,位置任意。我设定了一个参数,可以用于从 prototxt 中读取预设值。
- message AllPassParameter {
- optional floatkey = 1 [default= 0];
- }
在 cpp 代码中,通过
- this->layer_param_.all_pass_param().key()
这句来读取 prototxt 预设值。
在 $CAFFE_ROOT 下执行 make clean,然后重新 make all。要想一次编译成功,务必规范代码,对常见错误保持敏锐的嗅觉并加以避免。
万事具备,只欠 prototxt 了。
不难,我们写个最简单的 deploy.prototxt,不需要 data layer 和 softmax layer,just for fun。
- name:"AllPassTest"
- layer {
- name: "data"
- type: "Input"
- top: "data"
- input_param { shape: { dim: 10 dim: 3 dim: 227 dim: 227 } }
- }
- layer {
- name: "ap"
- type: "AllPass"
- bottom: "data"
- top: "conv1"
- all_pass_param {
- key: 12.88
- }
- }
注意,这里的 type :后面写的内容,应该是你在 .hpp 中声明的新类 class name 去掉 Layer 后的名称。
上面设定了 key 这个参数的预设值为 12.88,嗯,你想到了刘翔对不对。
为了检验该 Layer 是否能正常创建和执行 forward, backward,我们运行 caffe time 命令并指定刚刚实现的 prototxt :
- $ ./build/tools/caffe.bin time -model deploy.prototxt
- I1002 02:03:41.667682 1954701312 caffe.cpp:312] Use CPU.
- I1002 02:03:41.671360 1954701312 net.cpp:49] Initializing net from parameters:
- name: "AllPassTest"
- state {
- phase: TRAIN
- }
- layer {
- name: "data"
- type: "Input"
- top: "data"
- input_param {
- shape {
- dim: 10
- dim: 3
- dim: 227
- dim: 227
- }
- }
- }
- layer {
- name: "ap"
- type: "AllPass"
- bottom: "data"
- top: "conv1"
- all_pass_param {
- key: 12.88
- }
- }
- I1002 02:03:41.671463 1954701312 layer_factory.hpp:77] Creating layer data
- I1002 02:03:41.671484 1954701312 net.cpp:91] Creating Layer data
- I1002 02:03:41.671499 1954701312 net.cpp:399] data -> data
- I1002 02:03:41.671555 1954701312 net.cpp:141] Setting up data
- I1002 02:03:41.671566 1954701312 net.cpp:148] Top shape: 10 3 227 227 (1545870)
- I1002 02:03:41.671592 1954701312 net.cpp:156] Memory required for data: 6183480
- I1002 02:03:41.671605 1954701312 layer_factory.hpp:77] Creating layer ap
- I1002 02:03:41.671620 1954701312 net.cpp:91] Creating Layer ap
- I1002 02:03:41.671630 1954701312 net.cpp:425] ap <- data
- I1002 02:03:41.671644 1954701312 net.cpp:399] ap -> conv1
- I1002 02:03:41.671663 1954701312 net.cpp:141] Setting up ap
- I1002 02:03:41.671674 1954701312 net.cpp:148] Top shape: 10 3 227 227 (1545870)
- I1002 02:03:41.671685 1954701312 net.cpp:156] Memory required for data: 12366960
- I1002 02:03:41.671695 1954701312 net.cpp:219] ap does not need backward computation.
- I1002 02:03:41.671705 1954701312 net.cpp:219] data does not need backward computation.
- I1002 02:03:41.671710 1954701312 net.cpp:261] This network produces output conv1
- I1002 02:03:41.671720 1954701312 net.cpp:274] Network initialization done.
- I1002 02:03:41.671746 1954701312 caffe.cpp:320] Performing Forward
- Here is All Pass Layer, forwarding.
- 12.88
- I1002 02:03:41.679689 1954701312 caffe.cpp:325] Initial loss: 0
- I1002 02:03:41.679714 1954701312 caffe.cpp:326] Performing Backward
- I1002 02:03:41.679738 1954701312 caffe.cpp:334] *** Benchmark begins ***
- I1002 02:03:41.679746 1954701312 caffe.cpp:335] Testing for 50 iterations.
- Here is All Pass Layer, forwarding.
- 12.88
- Here is All Pass Layer, backwarding.
- 12.88
- I1002 02:03:41.681139 1954701312 caffe.cpp:363] Iteration: 1 forward-backward time: 1 ms.
- Here is All Pass Layer, forwarding.
- 12.88
- Here is All Pass Layer, backwarding.
- 12.88
- I1002 02:03:41.682394 1954701312 caffe.cpp:363] Iteration: 2 forward-backward time: 1 ms.
- Here is All Pass Layer, forwarding.
- 12.88
- Here is All Pass Layer, backwarding.
- 12.88
- I1002 02:03:41.683653 1954701312 caffe.cpp:363] Iteration: 3 forward-backward time: 1 ms.
- Here is All Pass Layer, forwarding.
- 12.88
- Here is All Pass Layer, backwarding.
- 12.88
- I1002 02:03:41.685096 1954701312 caffe.cpp:363] Iteration: 4 forward-backward time: 1 ms.
- Here is All Pass Layer, forwarding.
- 12.88
- Here is All Pass Layer, backwarding.
- 12.88
- I1002 02:03:41.686326 1954701312 caffe.cpp:363] Iteration: 5 forward-backward time: 1 ms.
- Here is All Pass Layer, forwarding.
- 12.88
- Here is All Pass Layer, backwarding.
- 12.88
- I1002 02:03:41.687713 1954701312 caffe.cpp:363] Iteration: 6 forward-backward time: 1 ms.
- Here is All Pass Layer, forwarding.
- 12.88
- Here is All Pass Layer, backwarding.
- 12.88
- I1002 02:03:41.689038 1954701312 caffe.cpp:363] Iteration: 7 forward-backward time: 1 ms.
- Here is All Pass Layer, forwarding.
- 12.88
- Here is All Pass Layer, backwarding.
- 12.88
- I1002 02:03:41.690251 1954701312 caffe.cpp:363] Iteration: 8 forward-backward time: 1 ms.
- Here is All Pass Layer, forwarding.
- 12.88
- Here is All Pass Layer, backwarding.
- 12.88
- I1002 02:03:41.691548 1954701312 caffe.cpp:363] Iteration: 9 forward-backward time: 1 ms.
- Here is All Pass Layer, forwarding.
- 12.88
- Here is All Pass Layer, backwarding.
- 12.88
- I1002 02:03:41.692805 1954701312 caffe.cpp:363] Iteration: 10 forward-backward time: 1 ms.
- Here is All Pass Layer, forwarding.
- 12.88
- Here is All Pass Layer, backwarding.
- 12.88
- I1002 02:03:41.694056 1954701312 caffe.cpp:363] Iteration: 11 forward-backward time: 1 ms.
- Here is All Pass Layer, forwarding.
- 12.88
- Here is All Pass Layer, backwarding.
- 12.88
- I1002 02:03:41.695264 1954701312 caffe.cpp:363] Iteration: 12 forward-backward time: 1 ms.
- Here is All Pass Layer, forwarding.
- 12.88
- Here is All Pass Layer, backwarding.
- 12.88
- I1002 02:03:41.696761 1954701312 caffe.cpp:363] Iteration: 13 forward-backward time: 1 ms.
- Here is All Pass Layer, forwarding.
- 12.88
- Here is All Pass Layer, backwarding.
- 12.88
- I1002 02:03:41.698225 1954701312 caffe.cpp:363] Iteration: 14 forward-backward time: 1 ms.
- Here is All Pass Layer, forwarding.
- 12.88
- Here is All Pass Layer, backwarding.
- 12.88
- I1002 02:03:41.699653 1954701312 caffe.cpp:363] Iteration: 15 forward-backward time: 1 ms.
- Here is All Pass Layer, forwarding.
- 12.88
- Here is All Pass Layer, backwarding.
- 12.88
- I1002 02:03:41.700945 1954701312 caffe.cpp:363] Iteration: 16 forward-backward time: 1 ms.
- Here is All Pass Layer, forwarding.
- 12.88
- Here is All Pass Layer, backwarding.
- 12.88
- I1002 02:03:41.702761 1954701312 caffe.cpp:363] Iteration: 17 forward-backward time: 1 ms.
- Here is All Pass Layer, forwarding.
- 12.88
- Here is All Pass Layer, backwarding.
- 12.88
- I1002 02:03:41.704056 1954701312 caffe.cpp:363] Iteration: 18 forward-backward time: 1 ms.
- Here is All Pass Layer, forwarding.
- 12.88
- Here is All Pass Layer, backwarding.
- 12.88
- I1002 02:03:41.706471 1954701312 caffe.cpp:363] Iteration: 19 forward-backward time: 2 ms.
- Here is All Pass Layer, forwarding.
- 12.88
- Here is All Pass Layer, backwarding.
- 12.88
- I1002 02:03:41.708784 1954701312 caffe.cpp:363] Iteration: 20 forward-backward time: 2 ms.
- Here is All Pass Layer, forwarding.
- 12.88
- Here is All Pass Layer, backwarding.
- 12.88
- I1002 02:03:41.710043 1954701312 caffe.cpp:363] Iteration: 21 forward-backward time: 1 ms.
- Here is All Pass Layer, forwarding.
- 12.88
- Here is All Pass Layer, backwarding.
- 12.88
- I1002 02:03:41.711272 1954701312 caffe.cpp:363] Iteration: 22 forward-backward time: 1 ms.
- Here is All Pass Layer, forwarding.
- 12.88
- Here is All Pass Layer, backwarding.
- 12.88
- I1002 02:03:41.712528 1954701312 caffe.cpp:363] Iteration: 23 forward-backward time: 1 ms.
- Here is All Pass Layer, forwarding.
- 12.88
- Here is All Pass Layer, backwarding.
- 12.88
- I1002 02:03:41.713964 1954701312 caffe.cpp:363] Iteration: 24 forward-backward time: 1 ms.
- Here is All Pass Layer, forwarding.
- 12.88
- Here is All Pass Layer, backwarding.
- 12.88
- I1002 02:03:41.715248 1954701312 caffe.cpp:363] Iteration: 25 forward-backward time: 1 ms.
- Here is All Pass Layer, forwarding.
- 12.88
- Here is All Pass Layer, backwarding.
- 12.88
- I1002 02:03:41.716487 1954701312 caffe.cpp:363] Iteration: 26 forward-backward time: 1 ms.
- Here is All Pass Layer, forwarding.
- 12.88
- Here is All Pass Layer, backwarding.
- 12.88
- I1002 02:03:41.717725 1954701312 caffe.cpp:363] Iteration: 27 forward-backward time: 1 ms.
- Here is All Pass Layer, forwarding.
- 12.88
- Here is All Pass Layer, backwarding.
- 12.88
- I1002 02:03:41.718962 1954701312 caffe.cpp:363] Iteration: 28 forward-backward time: 1 ms.
- Here is All Pass Layer, forwarding.
- 12.88
- Here is All Pass Layer, backwarding.
- 12.88
- I1002 02:03:41.720289 1954701312 caffe.cpp:363] Iteration: 29 forward-backward time: 1 ms.
- Here is All Pass Layer, forwarding.
- 12.88
- Here is All Pass Layer, backwarding.
- 12.88
- I1002 02:03:41.721837 1954701312 caffe.cpp:363] Iteration: 30 forward-backward time: 1 ms.
- Here is All Pass Layer, forwarding.
- 12.88
- Here is All Pass Layer, backwarding.
- 12.88
- I1002 02:03:41.723042 1954701312 caffe.cpp:363] Iteration: 31 forward-backward time: 1 ms.
- Here is All Pass Layer, forwarding.
- 12.88
- Here is All Pass Layer, backwarding.
- 12.88
- I1002 02:03:41.724261 1954701312 caffe.cpp:363] Iteration: 32 forward-backward time: 1 ms.
- Here is All Pass Layer, forwarding.
- 12.88
- Here is All Pass Layer, backwarding.
- 12.88
- I1002 02:03:41.725587 1954701312 caffe.cpp:363] Iteration: 33 forward-backward time: 1 ms.
- Here is All Pass Layer, forwarding.
- 12.88
- Here is All Pass Layer, backwarding.
- 12.88
- I1002 02:03:41.726771 1954701312 caffe.cpp:363] Iteration: 34 forward-backward time: 1 ms.
- Here is All Pass Layer, forwarding.
- 12.88
- Here is All Pass Layer, backwarding.
- 12.88
- I1002 02:03:41.728013 1954701312 caffe.cpp:363] Iteration: 35 forward-backward time: 1 ms.
- Here is All Pass Layer, forwarding.
- 12.88
- Here is All Pass Layer, backwarding.
- 12.88
- I1002 02:03:41.729249 1954701312 caffe.cpp:363] Iteration: 36 forward-backward time: 1 ms.
- Here is All Pass Layer, forwarding.
- 12.88
- Here is All Pass Layer, backwarding.
- 12.88
- I1002 02:03:41.730716 1954701312 caffe.cpp:363] Iteration: 37 forward-backward time: 1 ms.
- Here is All Pass Layer, forwarding.
- 12.88
- Here is All Pass Layer, backwarding.
- 12.88
- I1002 02:03:41.732275 1954701312 caffe.cpp:363] Iteration: 38 forward-backward time: 1 ms.
- Here is All Pass Layer, forwarding.
- 12.88
- Here is All Pass Layer, backwarding.
- 12.88
- I1002 02:03:41.733809 1954701312 caffe.cpp:363] Iteration: 39 forward-backward time: 1 ms.
- Here is All Pass Layer, forwarding.
- 12.88
- Here is All Pass Layer, backwarding.
- 12.88
- I1002 02:03:41.735049 1954701312 caffe.cpp:363] Iteration: 40 forward-backward time: 1 ms.
- Here is All Pass Layer, forwarding.
- 12.88
- Here is All Pass Layer, backwarding.
- 12.88
- I1002 02:03:41.737144 1954701312 caffe.cpp:363] Iteration: 41 forward-backward time: 2 ms.
- Here is All Pass Layer, forwarding.
- 12.88
- Here is All Pass Layer, backwarding.
- 12.88
- I1002 02:03:41.739090 1954701312 caffe.cpp:363] Iteration: 42 forward-backward time: 1 ms.
- Here is All Pass Layer, forwarding.
- 12.88
- Here is All Pass Layer, backwarding.
- 12.88
- I1002 02:03:41.741575 1954701312 caffe.cpp:363] Iteration: 43 forward-backward time: 2 ms.
- Here is All Pass Layer, forwarding.
- 12.88
- Here is All Pass Layer, backwarding.
- 12.88
- I1002 02:03:41.743450 1954701312 caffe.cpp:363] Iteration: 44 forward-backward time: 1 ms.
- Here is All Pass Layer, forwarding.
- 12.88
- Here is All Pass Layer, backwarding.
- 12.88
- I1002 02:03:41.744732 1954701312 caffe.cpp:363] Iteration: 45 forward-backward time: 1 ms.
- Here is All Pass Layer, forwarding.
- 12.88
- Here is All Pass Layer, backwarding.
- 12.88
- I1002 02:03:41.745970 1954701312 caffe.cpp:363] Iteration: 46 forward-backward time: 1 ms.
- Here is All Pass Layer, forwarding.
- 12.88
- Here is All Pass Layer, backwarding.
- 12.88
- I1002 02:03:41.747185 1954701312 caffe.cpp:363] Iteration: 47 forward-backward time: 1 ms.
- Here is All Pass Layer, forwarding.
- 12.88
- Here is All Pass Layer, backwarding.
- 12.88
- I1002 02:03:41.748430 1954701312 caffe.cpp:363] Iteration: 48 forward-backward time: 1 ms.
- Here is All Pass Layer, forwarding.
- 12.88
- Here is All Pass Layer, backwarding.
- 12.88
- I1002 02:03:41.749826 1954701312 caffe.cpp:363] Iteration: 49 forward-backward time: 1 ms.
- Here is All Pass Layer, forwarding.
- 12.88
- Here is All Pass Layer, backwarding.
- 12.88
- I1002 02:03:41.751124 1954701312 caffe.cpp:363] Iteration: 50 forward-backward time: 1 ms.
- I1002 02:03:41.751147 1954701312 caffe.cpp:366] Average time per layer:
- I1002 02:03:41.751157 1954701312 caffe.cpp:369] data forward: 0.00108 ms.
- I1002 02:03:41.751183 1954701312 caffe.cpp:372] data backward: 0.001 ms.
- I1002 02:03:41.751194 1954701312 caffe.cpp:369] ap forward: 1.37884 ms.
- I1002 02:03:41.751205 1954701312 caffe.cpp:372] ap backward: 0.01156 ms.
- I1002 02:03:41.751220 1954701312 caffe.cpp:377] Average Forward pass: 1.38646 ms.
- I1002 02:03:41.751231 1954701312 caffe.cpp:379] Average Backward pass: 0.0144 ms.
- I1002 02:03:41.751240 1954701312 caffe.cpp:381] Average Forward-Backward: 1.42 ms.
- I1002 02:03:41.751250 1954701312 caffe.cpp:383] Total Time: 71 ms.
- I1002 02:03:41.751260 1954701312 caffe.cpp:384] *** Benchmark ends ***
可见该 Layer 可以正常创建、加载预设参数、执行 forward、backward 函数。
Caffe 增加自定义 Layer 及其 ProtoBuffer 参数相关推荐
- 在js函数有默认参数情况下如何增加自定义参数而不覆盖原本的默认参数
在用一些ui写项目的时候会遇到:函数有默认参数并且需要增加自定义参数而不覆盖原本的默认参数的情况(代码放在评论区了) 在vant Uploader 文件上传,自定义参数 list是传入进来的,方便赋值 ...
- Caffe编写Python layer
Caffe编写Python layer 在使用caffe做训练的时候,通常的做法是把数据转为lmdb格式,然后在train.prototxt中指定,最后在开始训练,转为lmdb格式的优点是读取数据更高 ...
- caffe源码 layer分析
Layer 分析 1 layer 总体介绍 2 data 层 3 neuron 层 4 vision 层 5 common层 6 loss层 7 添加自己layer 一.layer总体介绍 1. la ...
- wordpress给后台文章列表增加自定义排序栏
为什么80%的码农都做不了架构师?>>> 受到Joost de Valk文章custom post type snippets 的启发,Joost的这篇文章简单地提供了一段怎么 ...
- [Caffe]:关于Eltwise layer
[Caffe]:关于Eltwise layer Eltwise : element-wise eltwise layer是caffe提供的按元素操作层.它支持3种基本操作: 1. PROD:按元素乘积 ...
- 给Fedora 15的gnome3增加自定义程序快捷方式
2019独角兽企业重金招聘Python工程师标准>>> 用了一段时间的Fedora 15 + gnom3之后发现一个很蛋疼的地方:程序列表里面列出的程序都是那些用过yum安装的程序, ...
- linux添加自己的库,Linux学习笔记——例叙makefile 增加自定义共享库
Linux学习笔记--例说makefile 增加自定义共享库 0.前言 从学习C语言开始就慢慢开始接触makefile,查阅了很多的makefile的资料但总感觉没有真正掌握makefile,如果自己 ...
- TensorFlow 2.0 - Keras Pipeline、自定义Layer、Loss、Metric
文章目录 1. Keras Sequential / Functional API 2. 自定义 layer 3. 自定义 loss 4. 自定义 评估方法 学习于:简单粗暴 TensorFlow 2 ...
- Linphone android去电增加自定义SIP消息头的流程分析
一.首先看一下如何在发起去电的sip请求中添加自定义的消息头 增加自定义头消息发方法,so已经提供了native方法, 发起呼叫的示例如下: LinphoneCallParams params = l ...
最新文章
- poj1730Pollard分解
- javascript学习(三) 内置对象
- python参数的可变参数与关键词参数
- BZOJ.4180.字符串计数(后缀自动机 二分 矩阵快速幂/倍增Floyd)
- Oracle入门(十三B)之高级查询(上)
- hive币涨幅空间大吗_自动消防水炮只能安装在大空间场所吗
- 搭建本地Ubuntu14.04源
- oem是代工还是贴牌_oem是什么意思,oem代工是什么意思?oem和odm区别有哪些?
- 命令行启动mssqlserver服务
- Java中List转换为数组,数组转List
- double精度丢失问题
- configure: error: C compiler cannot create executables
- 12000 颗卫星为地球织网!马斯克昨夜踏上改变世界的第6个征程
- 【转载】SAP物料基本计量单位的更改
- java基础-并发理论
- cuda-gdb 调试 Program terminated with signal SIGKILL, Killed. The program no longer exists.
- 尚医通 (三十一) --------- 手机登录
- 降龙十八掌搞定rt3070 USB WIFI模块在android2.3平台上上网[基于x210开发板]
- Cjson 库的使用
- 在Word中让公式在中间,公式编号右对齐
热门文章
- python3 最简单的实现 模版设计模式
- Qt 第一步 HelloWorld 的第一个程序
- 比__autoload 更灵活的 spl_autoload_register 用法
- java的概率的程序_java实现一个抽奖概率类
- 计算机网络的网络层功能在内完成,计算机网络习题及答案
- 今年不容易,要懂得爱护自己
- Linux资料分享,强势来袭!
- python eval函数_Python eval 函数妙用
- php获取qzonetoken,QQ一键登录实现
- vb6 由于超出容量限制 不能创建新事务_分布式限流?你也能轻松玩转(没啥新技术)...