Caffe中瓷砖层的目的是什么?它似乎是一种重塑输入的形式,但我想知道它究竟是如何工作的以及它可以应用于何处?
这是源代码:
template <typename Dtype>
void TilingLayer<Dtype>::LayerSetUp(const vector<Blob<Dtype>*>& bottom,
const vector<Blob<Dtype>*>& top) {
TilingParameter tiling_param = this->layer_param_.tiling_param();
tile_dim_ = tiling_param.tile_dim();
tile_dim_sq_ = tile_dim_ * tile_dim_;
CHECK(tile_dim_) << "tile_dim must be specified.";
CHECK_GT(tile_dim_, 0) << "tile_dim must be positive.";
}
template <typename Dtype> void TilingLayer<Dtype>::Reshape(const
vector<Blob<Dtype>*>& bottom,
const vector<Blob<Dtype>*>& top) {
CHECK_EQ(top.size(), 1);
input_channels_ = bottom[0]->channels();
input_height_ = bottom[0]->height();
input_width_ = bottom[0]->width();
output_channels_ = bottom[0]->channels() / tile_dim_sq_;
output_width_ = input_width_ * tile_dim_;
output_height_ = input_height_ * tile_dim_;
count_per_output_map_ = output_width_ * output_height_;
count_per_input_map_ = input_width_ * input_height_;
CHECK_EQ(0, input_channels_ % tile_dim_sq_)
<< "The number of input channels for tiling layer must be multiples "
<< "of the tile_dim."; top[0]->Reshape(bottom[0]->num(),
input_channels_ / tile_dim_sq_,
input_height_ * tile_dim_, input_width_ * tile_dim_); }
平铺层不同于平铺层,平铺层就像重塑一样,但平铺层就像重新设计。
===============编辑添加更多细节==========对于图块层,如源代码所示,https://github.com/BVLC/caffe/blob/master/src/caffe/layers/tile_layer.cpp
Dtype* top_data = top[0]->mutable_cpu_data();
for (int i = 0; i < outer_dim_; ++i) {
for (int t = 0; t < tiles_; ++t) {
caffe_copy(inner_dim_, bottom_data, top_data);
top_data += inner_dim_;
}
bottom_data += inner_dim_;
}
顶部数据只是输入数据的tiles_次,NCHW和tile_dim = 8,你得到形状为NC *(H * 8)*(W * 8)的blob,但是对于平铺层,它会使图层变平,例如你有NCHW blob和tiling_dim = 8,然后在平铺图层后,计数不会改变,但是你会得到形状为N(C / 64)*(H * 8)*(W * 8)的blob。