-
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
Add up, down, left and right padding for im2col. #4887
Add up, down, left and right padding for im2col. #4887
Conversation
paddle/operators/math/im2col.cc
Outdated
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) { |
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 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[...] = ...
}
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.
Done
paddle/operators/math/im2col.cc
Outdated
(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; |
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.
同上,可以在line 127, line 128分别减padding_up, padding_left吧。
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.
Done
paddle/operators/math/im2col.cc
Outdated
@@ -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 ??? |
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.
What is the comment mean?
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.
Nothing.
has been removed.
paddle/operators/math/im2col_test.cc
Outdated
if (paddle::platform::is_cpu_place(*place)) { | ||
input = input_tmp; | ||
} else { | ||
input.CopyFrom<float>(input_tmp, *place, *context); |
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.
CopyFrom
remove the template T.
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.
Done
paddle/operators/math/im2col.cc
Outdated
@@ -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) / |
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_ENFORCE
-> PADDLE_ENFORCE_EQ
, 貌似PADDLE_ENFORCE_EQ
的报错信息较好一些。 下同。
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.
Done
… fix_im2col_kocf_for_sequence
b9d50e8
to
09662da
Compare
fix #4995