【问题标题】:What is the purpose of Tiling layer in CaffeCaffe中Tiling层的作用是什么
【发布时间】:2018-09-30 22:08:41
【问题描述】:

Caffe 中 Tiling 层的作用是什么?它似乎是一种重塑输入的形式,但我想知道它究竟是如何工作的以及它可以应用在哪里?

这是源代码:

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

【问题讨论】:

    标签: machine-learning neural-network computer-vision deep-learning caffe


    【解决方案1】:

    tiling layer 和 tile layer 不同,tiling layer 就像 reshape,而 tile layer 就像 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_;
      }
    

    顶部数据只是输入数据的tiles_次,NCHW和tile_dim = 8,你得到形状为NC*(H*8 )*(宽*8) 但是对于平铺层,它会使层变平,例如你有 NCHW blob,并且 tiling_dim=8,然后在平铺层之后,计数不会改变,但是你得到形状为 N(C/64)*(H*8)*(W*8) 的斑点。

    【讨论】:

    • 好点,虽然更详细的答案会更有帮助。
    【解决方案2】:

    caffe 中的"Tile" 层实现了与numpy 的tile 或Matlab 的repmat 函数类似的操作:它沿指定维度复制数组的内容。

    例如,假设您有一个 2D 的“注意力”(或“显着性”)图,并且您想根据这些权重对特征进行加权:对“盐碱”区域赋予更大的权重,而对非“显着”区域赋予更少的权重.实现这一点的一种方法是将 3D 特征图乘以 2D 显着图(逐元素)。为此,您需要 "Tile" 沿通道维度(从 2D 到 3D)的显着性映射,然后应用 "Eltwise" 层。

    【讨论】:

    • 平铺层和平铺层做同样的工作吗?
    • @cerebrou 你能链接到你发布的代码的来源吗?
    猜你喜欢
    • 2017-05-11
    • 1970-01-01
    • 1970-01-01
    • 2015-07-14
    • 1970-01-01
    • 1970-01-01
    • 2016-09-21
    • 2020-10-18
    相关资源
    最近更新 更多