最近在做re-di任务时,经常要用到parts信息,因此slice层是非常有用的,但是caffe中这一层的参数需要弄明白,这里将slice层的代码解读一下。
——————————————————————–caffe.proto———————————————————————–
message SliceParameter {
// The axis along which to slice -- may be negative to index from the end
// (e.g., -1 for the last axis).
// By default, SliceLayer concatenates blobs along the "channels" axis (1).
//默认是在channel维进行切分
optional int32 axis = 3 [default = 1];
//切分点,个数要比输出个数少1
repeated uint32 slice_point = 2;
// DEPRECATED: alias for "axis" -- does not support negative indexing.
optional uint32 slice_dim = 1 [default = 1];
}
—————————————————————SliceLayer::LayerSetUp————————————————————–
template <typename Dtype>
void SliceLayer<Dtype>::LayerSetUp(const vector<Blob<Dtype>*>& bottom,
const vector<Blob<Dtype>*>& top) {
//获取本层参数
const SliceParameter& slice_param = this->layer_param_.slice_param();
CHECK(!(slice_param.has_axis() && slice_param.has_slice_dim()))
<< "Either axis or slice_dim should be specified; not both.";
//vector清空,并从参数将切分点拷贝进来
slice_point_.clear();
std::copy(slice_param.slice_point().begin(),
slice_param.slice_point().end(),
std::back_inserter(slice_point_));
}
—————————————————————SliceLayer::Reshape————————————————————–