Skip to content

Commit

Permalink
[WebNN EP] Fix bug of padding in Op ConvTranspose
Browse files Browse the repository at this point in the history
Get the dimensions of H and W according to the layout.
  • Loading branch information
zesongw committed Nov 24, 2023
1 parent 62f00ad commit 4ec8086
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,14 @@ 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.
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) +
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

0 comments on commit 4ec8086

Please sign in to comment.