-
Notifications
You must be signed in to change notification settings - Fork 5.7k
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
priorbox layer for Single Shot Multibox Detection Network #867
Conversation
@Noplz Please format the code. You should install pre-commit and clang-format.
Then run following command in the Git root of Paddle,
After the above has been done, the code will be automatically formatted when running |
std::back_inserter(aspectRatio_)); | ||
std::copy(config_.inputs(0).priorbox_conf().variance().begin(), | ||
config_.inputs(0).priorbox_conf().variance().end(), | ||
std::back_inserter(variance_)); |
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.
可以先用一个临时变量来记录config_.inputs(0).priorbox_conf(),38-49行不用重复写那么多了
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.
好的
缺少单测。缺少GPU实现(如果在下一个PR补充,请说明)。 |
@@ -0,0 +1,137 @@ | |||
/* Copyright (c) 2016 Baidu, Inc. All Rights Reserve. |
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.
Baidu, Inc需统一改成PaddlePaddle Authors
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.
好 这就去修改
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.
已修改
void PriorBoxLayer::forwardImp(const Argument& featureMap, | ||
const Argument& imageShape) { | ||
int layer_width = featureMap.getFrameWidth(); | ||
int layer_height = featureMap.getFrameHeight(); |
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.
有很多变量命名不符合Paddle规范。
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.
好的..之前没注意到..
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.
已修改,麻烦再review下。
self.config.inputs[0].priorbox_conf.variance.extend(variance) | ||
self.config.size = size | ||
input_layer0 = self.get_input_layer(0) | ||
input_layer1 = self.get_input_layer(1) |
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.
input_layer0和input_layer1没用的话可以删掉。
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.
已删除
|
||
MatrixPtr inV1 = imageShape.value; | ||
int image_width = inV1->getElement(0, 0); | ||
int image_height = inV1->getElement(0, 1); |
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.
第2个Input只存了height和width? 每个样本都一样吗? 可以从输入的data_layer的frameHeight 和 frameWidth获得吗?
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.
对的每个样本都一样的 印象中从data_layer没能get到frameHeight和frameWidth
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.
如果每个样本都一样,data_layer现在可以设置image的height和width了, 可以通过frameHeight和frameWidth获取到。
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.
那我再去试一下
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.
已修改为从data_layer的output获得image的height和width
|
||
namespace paddle { | ||
|
||
class PriorBoxLayer : public Layer { |
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.
添加注释。
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.
已添加
aspectRatio_.push_back(1.); | ||
numPriors_ = aspectRatio_.size(); | ||
if (maxSize_.size() > 0) numPriors_++; | ||
buffer_ = Matrix::create(1, 1, false, false); |
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.
下面有resizeOrCreate, 这行可以删掉了
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.
已删除
if (useGpu_) { | ||
for (size_t i = 0; i < inputLayers_.size(); i++) { | ||
tmpCpuInput_[i].resizeAndCopyFrom( | ||
getInput(i), false, HPPL_STREAM_DEFAULT); |
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.
下面计算只用到了input的value, 这里其实没有必要拷贝整个Argument。 只需要拷贝value就可以了。 因此 std::vector<Argument> tmpCpuInput_;
这个其实可以是两个Matrix。
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.
如果传Matrix的话, getFrameWidth和getFrameHeight就获取不到了吧?到是可以在外面把这几个值都get出来只传这几个int型的width和height的值进去。其实这一层需要的只是第一个input matrix的shape,第二个input的matrix也只有两个值,都通过getElement拿到的话也无所谓数据在CPU或GPU,output也是通过copyFrom拿到的。所以感觉这里加if(useGpu_)也有些多余。
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.
如果只获取shape的话, 无论数据是在CPU还是GPU, 通过Argument或者Matrix都可以获取到,所以input应该也不需要拷贝了。
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.
嗯。。我还是改回最开始那样吧 不需要任何copy
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.
已修改为不需要任何copy兼容cpu和gpu
现在还少一个单测,这个层感觉比较特殊还没想好怎么写单测好。 |
是否可以仿照 https://github.com/PaddlePaddle/Paddle/blob/develop/paddle/gserver/tests/test_ConvTrans.cpp 自定义result结果? |
好的 我去看看 仿照写一个 |
""" | ||
# plus one for ratio 1. | ||
num_filters = (len(aspect_ratio) * 2 + 1 + len(max_size)) * 4 | ||
size = (input.size / input.num_filters) * num_filters * 2 |
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.
可以对第二个input即Image进行check,check必须为data_layer? config_parse.py里面或许可以check必须设置了height和width。
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.
已添加check 都放在config_parser.py里面check了
仿照着https://github.com/PaddlePaddle/Paddle/blob/develop/paddle/gserver/tests/test_ConvTrans.cpp 写了一个单测,麻烦review下,谢谢 |
已添加gpu单测 |
|
||
// CPU case 1. | ||
MatrixPtr result; | ||
float resultData[] = {0.04, |
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.
额, 由 #967 注意到,这里得改成 real, 下同 :)
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 priorbox layer for Single Shot Multibox Detection Network. This layer doesn't need the backward propagation and the layer's result is independent of the value of the input image but the shape. The layer's result has been verified by the Caffe's implementation.