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_); }

最佳答案

平铺层与平铺层不同,平铺层像重塑,但平铺层像repmat。

==============编辑以添加更多详细信息===========
对于图块层,如源代码中所示,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_;
  }


最上面的数据只是输入数据的tile_倍,在NCHW和tile_dim = 8的情况下,将得到形状为NC *(H * 8)*(W * 8)的Blob
但是对于平铺层,它会使该层变平,例如您有NCHW blob,并且tiling_dim = 8,然后在平铺层之后,计数不变,但是您得到的形状为N(C / 64)*(H * 8)*(W * 8)。

10-06 06:30