Skip to content
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

Merged
merged 15 commits into from
Dec 22, 2016
Merged

Conversation

Noplz
Copy link
Contributor

@Noplz Noplz commented Dec 13, 2016

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.

@qingqing01 qingqing01 self-assigned this Dec 14, 2016
@qingqing01
Copy link
Contributor

@Noplz Please format the code.

You should install pre-commit and clang-format.

pip install pre-commit.

Then run following command in the Git root of Paddle,

pre-commit install

After the above has been done, the code will be automatically formatted when running git commit .

std::back_inserter(aspectRatio_));
std::copy(config_.inputs(0).priorbox_conf().variance().begin(),
config_.inputs(0).priorbox_conf().variance().end(),
std::back_inserter(variance_));
Copy link
Contributor

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行不用重复写那么多了

Copy link
Contributor Author

Choose a reason for hiding this comment

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

好的

@luotao1
Copy link
Contributor

luotao1 commented Dec 14, 2016

缺少单测。缺少GPU实现(如果在下一个PR补充,请说明)。

@@ -0,0 +1,137 @@
/* Copyright (c) 2016 Baidu, Inc. All Rights Reserve.
Copy link
Contributor

Choose a reason for hiding this comment

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

Baidu, Inc需统一改成PaddlePaddle Authors

Copy link
Contributor Author

Choose a reason for hiding this comment

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

好 这就去修改

Copy link
Contributor Author

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();
Copy link
Contributor

Choose a reason for hiding this comment

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

有很多变量命名不符合Paddle规范。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

好的..之前没注意到..

Copy link
Contributor Author

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)
Copy link
Contributor

Choose a reason for hiding this comment

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

input_layer0和input_layer1没用的话可以删掉。

Copy link
Contributor Author

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);
Copy link
Contributor

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获得吗?

Copy link
Contributor Author

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

Copy link
Contributor

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获取到。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

那我再去试一下

Copy link
Contributor Author

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 {
Copy link
Contributor

Choose a reason for hiding this comment

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

添加注释。

Copy link
Contributor Author

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);
Copy link
Contributor

Choose a reason for hiding this comment

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

下面有resizeOrCreate, 这行可以删掉了

Copy link
Contributor Author

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);
Copy link
Contributor

@qingqing01 qingqing01 Dec 14, 2016

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。

Copy link
Contributor Author

@Noplz Noplz Dec 14, 2016

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_)也有些多余。

Copy link
Contributor

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应该也不需要拷贝了。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

嗯。。我还是改回最开始那样吧 不需要任何copy

Copy link
Contributor Author

Choose a reason for hiding this comment

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

已修改为不需要任何copy兼容cpu和gpu

@Noplz
Copy link
Contributor Author

Noplz commented Dec 15, 2016

现在还少一个单测,这个层感觉比较特殊还没想好怎么写单测好。

@luotao1
Copy link
Contributor

luotao1 commented Dec 15, 2016

现在还少一个单测,这个层感觉比较特殊还没想好怎么写单测好。

是否可以仿照 https://github.com/PaddlePaddle/Paddle/blob/develop/paddle/gserver/tests/test_ConvTrans.cpp 自定义result结果?

@Noplz
Copy link
Contributor Author

Noplz commented Dec 15, 2016

好的 我去看看 仿照写一个

"""
# 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
Copy link
Contributor

@qingqing01 qingqing01 Dec 15, 2016

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。

Copy link
Contributor Author

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了

@Noplz
Copy link
Contributor Author

Noplz commented Dec 19, 2016

仿照着https://github.com/PaddlePaddle/Paddle/blob/develop/paddle/gserver/tests/test_ConvTrans.cpp 写了一个单测,麻烦review下,谢谢

@Noplz
Copy link
Contributor Author

Noplz commented Dec 20, 2016

已添加gpu单测


// CPU case 1.
MatrixPtr result;
float resultData[] = {0.04,
Copy link
Contributor

Choose a reason for hiding this comment

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

额, 由 #967 注意到,这里得改成 real, 下同 :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

已修改

@wangkuiyi wangkuiyi changed the title priorbox layer for ssd priorbox layer for Single Shot Multibox Detection Network Dec 20, 2016
@qingqing01 qingqing01 merged commit b53bdcd into PaddlePaddle:develop Dec 22, 2016
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.

None yet

4 participants