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

Add up, down, left and right padding for im2col. #4887

Merged

Conversation

chengduoZH
Copy link
Contributor

@chengduoZH chengduoZH commented Oct 18, 2017

fix #4995

@chengduoZH chengduoZH changed the title fix im2col kocf for sequence projection Add up, down, left and right padding for im2col. Oct 21, 2017
if ((im_row_idx - padding_up) < 0 ||
(im_row_idx - padding_up) >= input_height ||
(im_col_idx - padding_left) < 0 ||
(im_col_idx - padding_left) >= input_width) {
Copy link
Contributor

Choose a reason for hiding this comment

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

int im_row_idx = h * stride_height + h_offset - padding_up;
int im_col_idx = w * stride_width + w_offset - padding_left;
if (im_row_idx < 0 || im_row_idx >= input_height ||  im_col_idx < 0 || ...) {
} else {
  im_row_idx += c_im * input_height;
  col_data[...] = ...
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

(im_col_idx - padding_left) >= 0 &&
(im_col_idx - padding_left) < input_width) {
im_row_idx += c_im * input_height - padding_up;
im_col_idx -= padding_left;
Copy link
Contributor

Choose a reason for hiding this comment

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

同上,可以在line 127, line 128分别减padding_up, padding_left吧。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@@ -222,10 +262,10 @@ class Col2ImFunctor<paddle::operators::math::ColFormat::kOCF,
++filter_row_idx) {
for (int filter_col_idx = 0; filter_col_idx < filter_width;
++filter_col_idx) {
int im_row_offset =
col_row_idx * stride_height + filter_row_idx - padding_height;
int im_row_offset = // change or not ???
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the comment mean?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nothing.
has been removed.

if (paddle::platform::is_cpu_place(*place)) {
input = input_tmp;
} else {
input.CopyFrom<float>(input_tmp, *place, *context);
Copy link
Contributor

Choose a reason for hiding this comment

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

CopyFrom remove the template T.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@@ -41,6 +41,16 @@ class Im2ColFunctor<paddle::operators::math::ColFormat::kCFO,
int filter_width = col.dims()[2];
int output_height = col.dims()[3];
int output_width = col.dims()[4];

PADDLE_ENFORCE((input_height + padding_up + padding_down - filter_height) /
Copy link
Contributor

Choose a reason for hiding this comment

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

PADDLE_ENFORCE -> PADDLE_ENFORCE_EQ, 貌似PADDLE_ENFORCE_EQ的报错信息较好一些。 下同。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@qingqing01 qingqing01 merged commit 23bf6b2 into PaddlePaddle:develop Oct 24, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add up, down, left and right padding for im2col.
2 participants