DeepCompression-caffe icon indicating copy to clipboard operation
DeepCompression-caffe copied to clipboard

有几个Caffe层实现的疑问

Open ysh329 opened this issue 6 years ago • 1 comments

作者你好,我看到全连接和卷积分别有带前缀cmp的实现。

  1. 这里的mask_data是该层被剪枝的权重在原矩阵中的位置嘛?
  2. 实现了K均值聚类后读取类中心嘛?下面代码中这一行muweight[i] = cent_data[indice_data[i]];是否是对应的实现?
template <typename Dtype>
void CmpInnerProductLayer<Dtype>::Forward_cpu(const vector<Blob<Dtype>*>& bottom,
    const vector<Blob<Dtype>*>& top) {
  Dtype* muweight = this->blobs_[0]->mutable_cpu_data();
  const int *mask_data = this->masks_.cpu_data();
  int count = this->blobs_[0]->count();

  for (int i = 0; i < count; ++i)
    muweight[i] *= mask_data[i] ;

  if(this->quantize_term_)
  {
    const Dtype *cent_data = this->centroids_.cpu_data();
    const int *indice_data = this->indices_.cpu_data();

    for (int i = 0; i < count; ++i)
    {
       if (mask_data[i])
         muweight[i] = cent_data[indice_data[i]];
    }
  }

  const Dtype* bottom_data = bottom[0]->cpu_data();
  Dtype* top_data = top[0]->mutable_cpu_data();
  const Dtype* weight = this->blobs_[0]->cpu_data();
  caffe_cpu_gemm<Dtype>(CblasNoTrans, transpose_ ? CblasNoTrans : CblasTrans,
      M_, N_, K_, (Dtype)1.,
      bottom_data, weight, (Dtype)0., top_data);
  if (bias_term_) {
    caffe_cpu_gemm<Dtype>(CblasNoTrans, CblasNoTrans, M_, N_, 1, (Dtype)1.,
        bias_multiplier_.cpu_data(),
        this->blobs_[1]->cpu_data(), (Dtype)1., top_data);
  }
}

感谢~

ysh329 avatar Dec 24 '18 00:12 ysh329

mask_data 是模型稀疏化的0,1位置模板; 此外作者在训练过程中没有更新cent_data,应该是个bug

superchenyan avatar Oct 12 '19 02:10 superchenyan