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

[WebNN EP] Fix bug of padding in Op ConvTranspose #18577

Merged
merged 3 commits into from
Nov 30, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions onnxruntime/core/providers/webnn/builders/impl/conv_op_builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,16 @@ Status ConvOpBuilder::AddToModelBuilderImpl(ModelBuilder& model_builder, const N
std::vector<int64_t> input_shape;
ORT_RETURN_IF_NOT(GetShape(*input_defs[0], input_shape, logger), "Cannot get shape");
for (size_t i = 0; i < 2; i++) {
total_padding[i] = strides[i] * (narrow<size_t>(input_shape[i + 1]) - 1) +
output_padding[i] + ((kernel_shape[i] - 1) * dilations[i] + 1) - output_shape[i];
// Get the dimensions of H and W.
// For NHWC layout, the dimensions of H and W correspond to index 1 and 2.
// For NCHW layout, the dimensions of H and W correspond to index 2 and 3.
if (model_builder.GetPreferredLayout() == DataLayout::NHWC) {
total_padding[i] = strides[i] * (narrow<size_t>(input_shape[i + 1]) - 1) +
output_padding[i] + ((kernel_shape[i] - 1) * dilations[i] + 1) - output_shape[i];
} else {
total_padding[i] = strides[i] * (narrow<size_t>(input_shape[i + 2]) - 1) +
fdwr marked this conversation as resolved.
Show resolved Hide resolved
output_padding[i] + ((kernel_shape[i] - 1) * dilations[i] + 1) - output_shape[i];
}
}
pads[0] = total_padding[0] - (total_padding[0] / 2);
pads[1] = total_padding[0] / 2;
Expand Down
Loading