yuenshome / yuenshome.github.io

https://yuenshome.github.io
MIT License
81 stars 15 forks source link

quantized-cnn #51

Open ysh329 opened 5 years ago

ysh329 commented 5 years ago

jiaxiang-wu/quantized-cnn https://github.com/jiaxiang-wu/quantized-cnn

pmgysel/caffe: Ristretto: Caffe-based approximation of convolutional neural networks. https://github.com/pmgysel/caffe

ysh329 commented 5 years ago

1

https://github.com/jiaxiang-wu/quantized-cnn/blob/master/src/CaffeEva.cc#L987-L993

void CaffeEva::CalcFeatMap_FCntAprx(const Matrix<float>& featMapSrc,
    const int layerInd, Matrix<float>* pFeatMapDst) {
  // ...
  // ...
  // ...
  // ...
  // quantize the source feature map with pre-defined codebook
  swCompLkupTblFCnt.Resume();
  memcpy(featMapSrcRsp.GetDataPtr(),
      featMapSrc.GetDataPtr(), sizeof(float) * featMapSrc.GetEleCnt());
  GetInPdMat(featMapSrcRsp, ctrdBuf, &inPdMat);
  inPdMat.Resize(dataCnt, subSpaceCnt * ctrdCntPerSpace);
  swCompLkupTblFCnt.Pause();
  // ...
  // ...
}

2

https://github.com/jiaxiang-wu/quantized-cnn/blob/master/src/CaffeEva.cc#L800-L812

void CaffeEva::CalcFeatMap_ConvAprx(const Matrix<float>& featMapSrc,
    const int layerInd, Matrix<float>* pFeatMapDst) {
    // ....
    // ....
    // ....
    // ....
    // ....
    // quantize the source feature map with pre-defined codebook
    swCompLkupTblConv.Resume();
    featMapSrcPerGrp.Resize(dataCnt, imgHeiSrc, imgWidSrc, imgChnSrcPerGrp);
    if (layerInfo.grpCnt == 1) {
      memcpy(featMapSrcPerGrp.GetDataPtr(),
          featMapSrc.GetDataPtr(), sizeof(float) * featMapSrc.GetEleCnt());
    } else {
      featMapSrc.GetSubMat(0, 0, 0, chnIndSrcL, &featMapSrcPerGrp);
    }  // ENDIF: layerInfo
    featMapSrcPerGrp.Resize(dataCnt * imgHeiSrc * imgWidSrc, imgChnSrcPerGrp);
    GetInPdMat(featMapSrcPerGrp, ctrdBuf, &inPdMat);
    inPdMat.Resize(dataCnt, imgHeiSrc, imgWidSrc, ctrdCntExt);
    swCompLkupTblConv.Pause();
    // ....
    // ....
    // ....
}