Skip to content

Conversation

@guoshengCS
Copy link
Contributor

Add RCNNLossLayer, RCNNDetectionLayer for Faster(er) R-CNN.

Copy link
Contributor

@qingqing01 qingqing01 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pkuyym Please help to review.

size_t topK,
real confThreshold,
real nmsThreshold,
vector<size_t>* indices) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see applyNMSFast is similar with SSD:

void applyNMSFast(const vector<NormalizedBBox>& bboxes,
                  const real* confScoreData,
                  size_t classIdx,
                  size_t topK,
                  real confThreshold,
                  real nmsThreshold,
                  size_t numPriorBBoxes,
                  size_t numClasses,
                  vector<size_t>* indices) {
  vector<pair<real, size_t>> scores;
  for (size_t i = 0; i < numPriorBBoxes; ++i) {
    size_t confOffset = i * numClasses + classIdx;
    if (confScoreData[confOffset] > confThreshold)
      scores.push_back(std::make_pair(confScoreData[confOffset], i));
  }
  // ...
}

觉得可以写成下面,依据confScoreData来判断:

void applyNMSFast(const vector<NormalizedBBox>& bboxes,
                  size_t topK,
                  real confThreshold,
                  real nmsThreshold,
                  size_t numClasses,
                  vector<size_t>* indices,
                   const real* confScoreData,
                  size_t classIdx,
                  size_t numPriorBBoxes) {
  vector<pair<real, size_t>> scores;
  if (confScoreData) {
    for (size_t i = 0; i < numPriorBBoxes; ++i) {
      size_t confOffset = i * numClasses + classIdx;
      if (confScoreData[confOffset] > confThreshold)
        scores.push_back(std::make_pair(confScoreData[confOffset], i));
    }
  } else {
    for (size_t i = 0; i < bboxes.size(); ++i) {
      scores.push_back(std::make_pair(bboxes[i].first, i));
    }
  }
 // ...
}

}
}

size_t getDetectionIndices(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

目测和applyNMSFast类似,和SSD里的代码可复用~

decodedBBox.yMax = decodedBBoxCenterY + decodedBBoxHeight / 2;

return decodedBBox;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

上面代码也类似,不过为了方便调试收敛效果,代码优化也行。

std::vector<real> roiLocData(4); // RoI location
for (size_t j = 0; j < 4; ++j) {
roiLocData[j] = *(roisData + n * roiDim + 1 + j);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

int batchIdx = *(roisData + n * roiDim);
std::vector<real> roiLocData(4);  // RoI location
for (size_t j = 0; j < 4; ++j) {
  roiLocData[j] = *(roisData + n * roiDim + 1 + j);
}

==>

roisData += roiDim;
int batchIdx = *roisData;
std::vector<real> roiLocData(roisData+ 1, roisData+ 5);

std::vector的初始化:http://www.cplusplus.com/reference/vector/vector/vector/

for (size_t j = 0; j < 4; ++j) {
predLocData[j] = *(locPredData + n * numClasses_ * 4 + c * 4 + j);
}
real predConfData = *(confPredData + n * numClasses_ + c);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

同样代码可以短一些:

locPredData += numClasses_ * 4;
for (size_t c = 0; c < numClasses_; ++c) {
  if (c == backgroundId_) continue;
  std::vector<real> predLocData(locPredData + c * 4, locPredData + c * 4 + 4);
  real predConfData = *(confPredData + c);
  // ...

* contains the prior-box data. The rest two input layers are
* layers for generating bounding-box location offset and the
* classification confidence.
* - Output: The predict bounding boxes.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The predicted bounding boxes.


@config_layer('rcnn_loss')
class RCNNLossLayer(LayerBase):
def __init__(self, name, inputs, loss_ratio, num_classes, background_id=0):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

, **xargs):

loss_ratio,
num_classes,
background_id=0,
name=None):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's better to add some comments for the difference between rnn_loss and multibox_loss, if you understand.

@luotao1
Copy link
Contributor

luotao1 commented Feb 1, 2019

感谢您给PaddlePaddle贡献代码。由于Paddle V1/V2版本已不再维护,相关代码也已从develop分支上删除,因此关闭您的PR,欢迎您向Paddle最新版-Fluid贡献代码。
Thanks for contributing to PaddlePaddle! Since V1/V2 will not be maintained anymore, and related codes have been deleted from develop branch as well, we close this PR. Welcome to contribute to Fluid——the latest version of PaddlePaddle.

@luotao1 luotao1 closed this Feb 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants