-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add RCNNLossLayer, RCNNDetectionLayer for Faster(er) R-CNN #3496
Add RCNNLossLayer, RCNNDetectionLayer for Faster(er) R-CNN #3496
Conversation
There was a problem hiding this 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) { |
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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; | ||
} |
There was a problem hiding this comment.
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); | ||
} |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The predicted bounding boxes.
@@ -1781,6 +1781,39 @@ def __init__(self, name, inputs, size, input_num, num_classes, | |||
self.config.size = size | |||
|
|||
|
|||
@config_layer('rcnn_loss') | |||
class RCNNLossLayer(LayerBase): | |||
def __init__(self, name, inputs, loss_ratio, num_classes, background_id=0): |
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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.
感谢您给PaddlePaddle贡献代码。由于Paddle V1/V2版本已不再维护,相关代码也已从develop分支上删除,因此关闭您的PR,欢迎您向Paddle最新版-Fluid贡献代码。 |
Add RCNNLossLayer, RCNNDetectionLayer for Faster(er) R-CNN.