在Caffe中只编译一个层文件

3
当我们在caffe中开发一个新的层,例如new_layer.cppnew_layer.cunew.layer.hpp,我们需要重新编译caffe。是否有可能只编译这些新层文件,就像更新原始库一样,还是必须重新编译整个库?能否给我一些提示?
补充:实际上,我从Github上下载了某人的实现中的层文件:https://github.com/farmingyard/ShuffleNet。其中包括.cpp.cu.hpp文件。我将.cpp.cu放在caffe/src/caffe/layers目录下,并将.hpp放在caffe/include/caffe/layers/目录下,然后在caffe.proto中添加如下内容:
message LayerParameter {
...
optional ShuffleChannelParameter shuffle_channel_param = 164;
}

另外:

message ShuffleChannelParameter {
  optional uint32 group = 1[default = 1]; // The number of group
}

在proto文件的末尾,然后我在caffe根目录中调用make clean,接着调用make all,没有错误,并检查到有行数。
CXX src/caffe/layers/shuffle_channel_layer.cpp

and

NVCC src/caffe/layers/shuffle_channel_layer.cu

and(我不知道这是否意味着proto文件已重新编译)

CXX .build_release/src/caffe/proto/caffe.pb.cc

然后执行make proto,会得到以下结果:
make: Nothing to be done for proto 

然后我运行了make pycaffe命令,没有错误提示,编译成功。随后我使用了作者提供的一个示例网络的prototxt文件来使用新层,但接下来出现了以下错误提示:

Message type "caffe.LayerParameter" has no field named "shuffle_channel_param".

完整的LayerParameter

// NOTE
// Update the next available ID when you add a new LayerParameter field.
//
// LayerParameter next available layer-specific ID: 147 (last added: recurrent_param)
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 float loss_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 whether to backpropagate to each bottom. If unspecified,
  // Caffe will automatically infer whether each input needs backpropagation
  // to compute parameter gradients. If set to true for some inputs,
  // backpropagation to those inputs is forced; if set false for some inputs,
  // backpropagation to those inputs is skipped.
  //
  // The size must be either 0 or equal to the number of bottoms.
  repeated bool propagate_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 ParameterParameter parameter_param = 145;
  optional PoolingParameter pooling_param = 121;
  optional PowerParameter power_param = 122;
  optional PReLUParameter prelu_param = 131;
  optional PythonParameter python_param = 130;
  optional RecurrentParameter recurrent_param = 146;
  optional ReductionParameter reduction_param = 136;
  optional ReLUParameter relu_param = 123;
  optional ReshapeParameter reshape_param = 133;
  optional ROIPoolingParameter roi_pooling_param = 8266711;
  optional ScaleParameter scale_param = 142;
  optional SigmoidParameter sigmoid_param = 124;
  optional SmoothL1LossParameter smooth_l1_loss_param = 8266712;
  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 ShuffleChannelParameter shuffle_channel_param = 164;
}

@Shai,请查看我的新编辑。 - K.Wanter
1
@Shai,结果发现我使用的是另一个旧的之前编译过的caffe,而不是新编译的那个 :) - K.Wanter
我正在尝试将ROI池化层编译到我的Caffe中。我已经复制了所有内容,但它无法编译。 - raaj
1个回答

1
使用 make 进行编译时,make 知道已经编译过的源代码以及与上次构建相比发生了哪些变化。如果你只是进行了局部更改,make 只会编译/链接已更改的源代码以及受其影响的部分(对头文件的更改可能需要编译其他包含该头文件的源代码)。也就是说,你不需要做任何特殊的事情,只需继续使用 make 即可。
如果你运行 make clean,将会删除所有已编译的对象并强制 make 从头开始重新编译整个项目。

@K.Wanter,你是否也对caffe.proto进行了修改? - Shai
@K.Wanter 是的。如果您更改了 caffe.proto,则需要验证 make 命令是否也运行了 protoc 编译器。 - Shai
你的意思是运行 protoc 编译器吗? - K.Wanter
除了在caffe根目录下运行“make”之外,您是不是还需要编译“caffe.proto”文件? - K.Wanter
@K.Wanter 尝试运行 make protomake pycaffe - Shai
显示剩余9条评论

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接